diff --git a/curses/README b/curses/README index 01cec1f..cfda201 100644 --- a/curses/README +++ b/curses/README @@ -22,11 +22,11 @@ D : disconnect from all active networks ESC : if connecting to a network, stop doing so ENTER : Attempt connection to selected network P : Display preferences dialog -C : Display network configuration for selected network (only works for - wireless at the moment) +C : Display network configuration for selected network A : Display "About" dialog I : Raise the "Scan for hidden networks" dialog H : Raise help dialog +delete : Delete selected wired network profile (from the wired ComboBox) IN DIALOGS (Meta usually is "Alt"): ESC or Q: Quit dialog without saving information (if present) diff --git a/curses/TODO b/curses/TODO index 22a63c9..129fe2f 100644 --- a/curses/TODO +++ b/curses/TODO @@ -1,6 +1,5 @@ Things to do (in no particular order): -* Make a network config dialog for wired interfaces * Implement a keyhandler function for the overall frame * Make keystrokes customizable * Make color schemes customizable diff --git a/curses/curses_misc.py b/curses/curses_misc.py index e79a74c..9cd0346 100644 --- a/curses/curses_misc.py +++ b/curses/curses_misc.py @@ -295,17 +295,28 @@ class ComboBox(urwid.WidgetWrap): self.use_enter = use_enter # The Focus self.focus = focus + # The callback and friends self.callback = callback self.user_args = user_args + + # Widget references to simplify some things + self.body = None + self.ui = None + self.row = None def set_list(self,list): self.list = list def set_focus(self,index): self.focus = index + self.cbox.set_w(SelText(self.list[index]+' vvv')) + def rebuild_combobox(self): + self.build_combobox(self.body,self.ui,self.row) def build_combobox(self,body,ui,row): str,trash = self.label.get_text() + + self.cbox = DynWrap(SelText([self.list[self.focus]+' vvv']),attrs=self.attrs,focus_attr=self.focus_attr) if str != '': w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1) @@ -319,6 +330,7 @@ class ComboBox(urwid.WidgetWrap): self.set_w(w) self.body = body self.ui = ui + self.row = row # If we press space or enter, be a combo box! def keypress(self,size,key): @@ -331,7 +343,8 @@ class ComboBox(urwid.WidgetWrap): raise ComboBoxException('ComboBox must be built before use!') retval = self.overlay.show(self.ui,self.body) if retval != None: - self.cbox.set_w(SelText(retval+' vvv')) + self.set_focus(self.list.index(retval)) + #self.cbox.set_w(SelText(retval+' vvv')) if self.callback != None: self.callback(self,self.overlay._listbox.get_focus()[1],self.user_args) return self._w.keypress(size,key) diff --git a/curses/netentry_curses.py b/curses/netentry_curses.py index 09fa7f8..4274625 100644 --- a/curses/netentry_curses.py +++ b/curses/netentry_curses.py @@ -136,7 +136,7 @@ class AdvancedSettingsDialog(urwid.WidgetWrap): self.global_dns_cb.set_sensitive(new_state) # use_global_dns_cb is DynWrapped if checkb == self.global_dns_cb.get_w(): - for w in [ self.dns_dom_edit,self.search_dom_edit, + for w in [self.dns_dom_edit,self.search_dom_edit, self.dns1,self.dns2,self.dns3 ]: w.set_sensitive(not new_state) @@ -174,31 +174,93 @@ class AdvancedSettingsDialog(urwid.WidgetWrap): self.set_net_prop("dns2", '') self.set_net_prop("dns3", '') + def prerun(self,ui,dim,display): + pass def run(self,ui,dim,display): + self.ui = ui + self.parent = display width,height = ui.get_cols_rows() - overlay = urwid.Overlay(self, display, ('fixed left', 0),width + self.overlay = urwid.Overlay(self, display, ('fixed left', 0),width , ('fixed top',1), height-3) + self.prerun(ui,dim,display) #self.ready_comboboxes(ui,overlay) keys = True while True: if keys: - ui.draw_screen(dim, overlay.render(dim, True)) + ui.draw_screen(dim, self.overlay.render(dim, True)) keys = ui.get_input() + for k in keys: + #Send key to underlying widget: + if urwid.is_mouse_event(k): + event, button, col, row = k + self.overlay.mouse_event( dim, + event, button, col, row, + focus=True) + self.overlay.keypress(dim, k) if "window resize" in keys: dim = ui.get_cols_rows() if "esc" in keys or 'Q' in keys: return False - for k in keys: - #Send key to underlying widget: - overlay.keypress(dim, k) - # Check if buttons are pressed. - #if self.CANCEL_PRESSED: - # return False - #if self.OK_PRESSED or 'meta enter' in keys: - # return True + if "meta enter" in keys or self.OK_PRESSED: + self.OK_PRESSED = False + if self.save_settings(): + return True + if self.CANCEL_PRESSED: + return False + +class WiredSettingsDialog(AdvancedSettingsDialog): + def __init__(self,name): + global wired, daemon + AdvancedSettingsDialog.__init__(self) + self.set_default = urwid.CheckBox(language['default_wired']) + #self.cur_default = + # Add widgets to listbox + self._w.body.body.append(self.set_default) + self._w.body.body.append(self.button_cols) + + self.prof_name = name + self._w.header = urwid.Text( ('header',">Configuring preferences for wired profile \"%s\"" % self.prof_name),align='right' ) + + self.set_values() + def set_net_prop(self,option,value): + wired.SetWiredProperty(option,value) + def set_values(self): + self.ip_edit.set_edit_text(self.format_entry("ip")) + self.netmask_edit.set_edit_text(self.format_entry("netmask")) + self.gateway_edit.set_edit_text(self.format_entry("gateway")) + + self.global_dns_cb.set_state(bool(wired.GetWiredProperty('use_global_dns'))) + self.static_dns_cb.set_state(bool(wired.GetWiredProperty('use_static_dns'))) + + self.dns1.set_edit_text(self.format_entry( "dns1")) + self.dns2.set_edit_text(self.format_entry( "dns2")) + self.dns3.set_edit_text(self.format_entry( "dns3")) + self.dns_dom_edit.set_edit_text(self.format_entry("dns_domain")) + self.search_dom_edit.set_edit_text(self.format_entry("search_domain")) + + self.set_default.set_state(to_bool(wired.GetWiredProperty("default"))) + + def save_settings(self): + AdvancedSettingsDialog.save_settings(self) + if self.set_default.get_state(): + wired.UnsetWiredDefault() + print self.set_default.get_state() + if self.set_default.get_state(): + bool = True + else: + bool = False + wired.SetWiredProperty("default",bool) + wired.SaveWiredNetworkProfile(self.prof_name) + return True + + def format_entry(self, label): + """ Helper method to fetch and format wired properties. """ + return noneToBlankString(wired.GetWiredProperty(label)) + def prerun(self,ui,dim,display): + pass ######################################## @@ -257,6 +319,13 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): self.global_settings_chkbox.set_state(bool(wireless.GetWirelessProperty(networkID ,'use_settings_globally'))) + # Throw the encryption stuff into a list + list = [] + for x, enc_type in enumerate(self.encrypt_types): + list.append(enc_type[0]) + self.encryption_combo.set_list(list) + + self.change_encrypt_method() activeID = -1 # Set the menu to this item when we are done user_enctype = wireless.GetWirelessProperty(networkID, "enctype") for x, enc_type in enumerate(self.encrypt_types): @@ -270,12 +339,6 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): #self.lbox_encrypt_info.set_sensitive(True) else: self.encryption_combo.set_focus(0) - # Throw the encryption stuff into a list - list = [] - for x, enc_type in enumerate(self.encrypt_types): - list.append(enc_type[0]) - self.encryption_combo.set_list(list) - self.change_encrypt_method() def set_net_prop(self, option, value): """ Sets the given option to the given value for this network. """ @@ -363,7 +426,7 @@ class WirelessSettingsDialog(AdvancedSettingsDialog): self.overlay = urwid.Overlay(self, display, ('fixed left', 0),width , ('fixed top',1), height-3) self.encryption_combo.build_combobox(self.overlay,ui,14) - #self.change_encrypt_method() + self.change_encrypt_method() #self._w.body.body.append(self.pile_encrypt) keys = True diff --git a/curses/wicd-curses.py b/curses/wicd-curses.py index 212a178..279aa32 100644 --- a/curses/wicd-curses.py +++ b/curses/wicd-curses.py @@ -56,7 +56,7 @@ from time import sleep from curses_misc import SelText,ComboBox,TextDialog,InputDialog from prefs_curses import PrefsDialog import netentry_curses -from netentry_curses import WirelessSettingsDialog, error +from netentry_curses import WirelessSettingsDialog, WiredSettingsDialog,error language = misc.get_language_list_gui() @@ -181,10 +181,10 @@ def gen_network_list(): id = 0 wiredL = [] - is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None + #is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None # This one makes a list of strings to put in a combo box. - for profile in wired.GetWiredProfileList(): - theString = '%4s %25s' % (id, profile) + #for profile in wired.GetWiredProfileList(): + #theString = '%4s %25s' % (id, profile) #### THIS IS wired.blah() in experimental #print config.GetLastUsedWiredNetwork() # Tag if no wireless IP present, and wired one is @@ -195,9 +195,9 @@ def gen_network_list(): # 'connected focus')) #else: #wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus')) - wiredL.append(theString) - id+=1 - + #wiredL.append(theString) + #id+=1 + wiredL = wired.GetWiredProfileList() wlessL = [] # This one makes a list of NetLabels for network_id in range(0, wireless.GetNumberOfNetworks()): @@ -298,10 +298,16 @@ class WiredComboBox(ComboBox): """ list : the list of wired network profiles. The rest is self-explanitory. """ - def init(self,list): + def __init__(self,list): + self.ADD_PROFILE = '---Add a new profile---' + self.__super.__init__(use_enter=False) + self.set_list(list) + #self.set_focus(self.theList.index(wired.GetDefaultProfile())) + + def set_list(self,list): self.theList = list - id = 0 - wiredL = [] + id=0 + wiredL=[] is_active = wireless.GetWirelessIP('') == None and wired.GetWiredIP('') != None for profile in list: theString = '%4s %25s' % (id, profile) @@ -317,11 +323,37 @@ class WiredComboBox(ComboBox): # wiredL.append(urwid.AttrWrap(SelText(theString),'body','focus')) wiredL.append(theString) id+=1 - self.__super.__init__(list=wiredL,use_enter=False) - self.set_focus(theList.index(wired.GetDefaultWiredProfile())) + wiredL.append(self.ADD_PROFILE) + if is_active: + self.attrs = ('connected','editnfc') + self.focus_attr = 'connected focus' + else : + self.attrs = ('body','editnfc') + self.focus_attr = 'focus' + self.list = wiredL + if self.theList != []: + wired.ReadWiredNetworkProfile(self.get_selected_profile()) def keypress(self,size,key): - self.__super.keypress(size,key) + prev_focus = self.get_focus()[1] + key = self.__super.keypress(size,key) + if self.get_focus()[1] == len(self.list)-1: + dialog = InputDialog(('header',"Add new wired profile"),7,30) + + exitcode,name = dialog.run(ui,self.body) + if exitcode == 0: + wired.CreateWiredNetworkProfile(name,False) + self.set_list(wired.GetWiredProfileList()) + self.rebuild_combobox() + self.set_focus(prev_focus) + self.overlay._listbox.set_focus(prev_focus) + else: + wired.ReadWiredNetworkProfile(self.get_selected_profile()) + if key == 'delete': + wired.DeleteWiredNetworkProfile(self.get_selected_profile()) + self.set_list(wired.GetWiredProfileList()) + self.rebuild_combobox() + return key #if key == 'C': # Configure the network # pass @@ -332,11 +364,9 @@ class WiredComboBox(ComboBox): # self.connect() #return key - def connect(self): - wired.ConnectWired() def get_selected_profile(self): """Get the selected wired profile""" - return self.theList[self._w.get_selected()[1]] + return self.theList[self.get_focus()[1]] ######################################## ##### APPLICATION INTERFACE CLASS @@ -370,7 +400,7 @@ class appGUI(): wiredL,wlessL = [],[]# = gen_network_list() self.frame = None - self.wiredCB = urwid.Filler(ComboBox(list=wiredL,use_enter=False)) + self.wiredCB = urwid.Filler(WiredComboBox(wiredL)) self.wlessLB = urwid.ListBox(wlessL) self.update_netlist(force_check=True,firstrun=True) @@ -411,11 +441,12 @@ class appGUI(): def lock_screen(self): self.frame.set_body(self.screen_locker) self.screen_locked = True + self.update_ui() def unlock_screen(self): + self.update_netlist(force_check=True) self.frame.set_body(self.thePile) self.screen_locked = False - self.update_netlist(force_check=True) self.update_ui() def raise_hidden_network_dialog(self): @@ -436,12 +467,12 @@ class appGUI(): if self.thePile.get_focus() == self.wiredCB: wlessorwired = self.WIRED_IDX where = self.thePile.get_focus().get_body().get_focus()[1] - else:#self.thePile.get_focus() == self.wlessLB : + else: #self.thePile.get_focus() == self.wlessLB : wlessorwired = self.WLESS_IDX if self.wlessLB == self.no_wlan: where = None else: - where = self.frame.get_body().get_focus().get_focus()[1] + where = self.thePile.get_focus().get_focus()[1] #where = self.wlessLB.get_focus()[1] self.focusloc = (wlessorwired,where) # Be clunky until I get to a later stage of development. @@ -498,6 +529,9 @@ class appGUI(): self.prev_state = state if not firstrun: self.update_ui() + if firstrun: + if wired.GetDefaultWiredNetwork() != None: + self.wiredCB.get_body().set_focus(wired.GetWiredProfileList().index(wired.GetDefaultWiredNetwork())) # Update the footer/status bar @wrap_exceptions() @@ -591,16 +625,11 @@ class appGUI(): #if not self.connecting: # gobject.idle_add(self.refresh_networks, None, False, None) self.unlock_screen() - # I'm hoping that this will resolve Adam's problem with the screen lock - # remaining onscreen until a key is pressed. It goes away perfectly well - # here. - self.update_ui() # Same, same, same, same, same, same #@wrap_exceptions() def dbus_scan_started(self): self.lock_screen() - self.update_ui() # Redraw the screen @wrap_exceptions() @@ -621,6 +650,7 @@ class appGUI(): loop.quit() return False if "f5" in keys: + self.lock_screen() wireless.Scan() if "D" in keys: # Disconnect from all networks. @@ -656,7 +686,8 @@ class appGUI(): if "C" in keys: focus = self.thePile.get_focus() if focus == self.wiredCB: - pass + WiredSettingsDialog(self.wiredCB.get_body(). + get_selected_profile()).run(ui,self.size,self.frame) else: # wireless list only other option wid,pos = self.thePile.get_focus().get_focus() @@ -677,18 +708,6 @@ class appGUI(): self.size = ui.get_cols_rows() continue self.frame.keypress( self.size, k ) - - if " " in keys: - focus = self.thePile.get_focus() - if focus == self.wiredCB: - #self.set_status('space pressed on wiredCB!') - wid,pos = self.wiredCB.get_body().get_focus() - text,attr = wid.get_text() - wired.ReadWiredNetworkProfile(text) - # Make sure our internal reference to the combobox matches the - # one found in the pile. - #self.wiredCB = self.thePile.get_focus() - return True # TODO: Update this to use the networkentry stuff def connect(self, nettype, networkid, networkentry=None): diff --git a/in/man=wicd-curses.8.in b/in/man=wicd-curses.8.in index 090b042..2d6a921 100644 --- a/in/man=wicd-curses.8.in +++ b/in/man=wicd-curses.8.in @@ -1,4 +1,5 @@ -.TH WICD-CURSES "8" "January 2009" "wicd-curses" +.\" First revision was r203 +.TH WICD-CURSES "8" "January 2009" "wicd-curses-r247" .SH NAME .B wicd-curses \- curses-based wicd(8) controller @@ -39,11 +40,14 @@ Bring up hidden network scanning dialog .TP .BR H Bring up a rather simplistic help dialog. Of course, it mentions this man page first. :-) -.PP -The following is a work in progress and might not be fully functional as of yet. +.\".PP +.\"The following is a work in progress and might not be fully functional as of yet. .TP .BR C Bring up network configuration controller for the selected network +.TP +.BR delete +Delete the selected wired network profile (from the wired combo box at the top) .PP The following are not implemented yet: .TP diff --git a/in/other=WHEREAREMYFILES.in b/in/other=WHEREAREMYFILES.in index 61363e9..cec81a3 100644 --- a/in/other=WHEREAREMYFILES.in +++ b/in/other=WHEREAREMYFILES.in @@ -1,8 +1,10 @@ -If you are reading this, you are probably wondering why your Wicd configuration -files are not here. What follows is a summary of the folders that wicd uses. +WHERE ARE MY FILES?! -For a more detailed (and complete) description what is in each directory, consult the -man pages for wicd(8) and wicd-curses(8). +If you are reading this, you are probably wondering why your Wicd configuration +files are not here. What follows is a summary of the folders that Wicd uses. + +For a more detailed (and complete) description what is in each directory, +consult the man pages for wicd(8) and wicd-curses(8). ~/.wicd User-dependent configuration files, only used by wicd-curses