diff --git a/wicd/guiutil.py b/wicd/guiutil.py index e84c753..8eea489 100644 --- a/wicd/guiutil.py +++ b/wicd/guiutil.py @@ -46,6 +46,45 @@ def alert(parent, message, block=True): dialog.run() dialog.destroy() +def string_input(prompt, secondary, textbox_label): + # based on a version of a PyGTK text entry from + # http://ardoris.wordpress.com/2008/07/05/pygtk-text-entry-dialog/ + + def dialog_response(entry, dialog, response): + dialog.response(response) + + dialog = gtk.MessageDialog( + None, + gtk.DIALOG_MODAL, + gtk.MESSAGE_QUESTION, + gtk.BUTTONS_OK_CANCEL, + None) + + # set the text + dialog.set_markup("" + prompt + "") + # add the secondary text + dialog.format_secondary_markup(secondary) + + entry = gtk.Entry() + # allow the user to press enter instead of clicking OK + entry.connect("activate", dialog_response, dialog, gtk.RESPONSE_OK) + + # create an hbox and pack the label and entry in + hbox = gtk.HBox() + hbox.pack_start(gtk.Label(textbox_label), False, 4, 4) + hbox.pack_start(entry) + + # pack the boxes and show the dialog + dialog.vbox.pack_end(hbox, True, True, 0) + dialog.show_all() + + if dialog.run() == gtk.RESPONSE_OK: + text = entry.get_text() + dialog.destroy() + return text + else: + dialog.destroy() + return None class SmallLabel(gtk.Label): def __init__(self, text=''): diff --git a/wicd/netentry.py b/wicd/netentry.py index 4474b99..302b04d 100644 --- a/wicd/netentry.py +++ b/wicd/netentry.py @@ -21,7 +21,7 @@ import os import misc import wpath from misc import noneToString, stringToNone, noneToBlankString, to_bool -from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel +from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel, string_input language = misc.get_language_list_gui() @@ -553,7 +553,7 @@ class WiredNetworkEntry(NetworkEntry): self.chkbox_default_profile = gtk.CheckButton(language['default_wired']) # Build the profile list. - self.combo_profile_names = gtk.combo_box_entry_new_text() + self.combo_profile_names = gtk.combo_box_new_text() self.profile_list = wired.GetWiredProfileList() if self.profile_list: for x in self.profile_list: @@ -642,21 +642,32 @@ class WiredNetworkEntry(NetworkEntry): def add_profile(self, widget): """ Add a profile to the profile list. """ print "adding profile" - profile_name = self.combo_profile_names.get_active_text() + + response = string_input("Enter a profile name", "The profile name " + + "will not be used by the computer. It " + + "allows you to " + + "easily distinguish between different network " + + "profiles.", "Profile name:") + + # if response is "" or None + if not response: + return + + profile_name = response profile_list = wired.GetWiredProfileList() if profile_list: if profile_name in profile_list: return False - if profile_name != "": - self.profile_help.hide() - wired.CreateWiredNetworkProfile(profile_name, False) - self.combo_profile_names.prepend_text(profile_name) - self.combo_profile_names.set_active(0) - self.advanced_dialog.prof_name = profile_name - if self.is_full_gui: - self.button_delete.set_sensitive(True) - self.connect_button.set_sensitive(True) - self.advanced_button.set_sensitive(True) + + self.profile_help.hide() + wired.CreateWiredNetworkProfile(profile_name, False) + self.combo_profile_names.prepend_text(profile_name) + self.combo_profile_names.set_active(0) + self.advanced_dialog.prof_name = profile_name + if self.is_full_gui: + self.button_delete.set_sensitive(True) + self.connect_button.set_sensitive(True) + self.advanced_button.set_sensitive(True) def remove_profile(self, widget): """ Remove a profile from the profile list. """