diff --git a/curses/curses_misc.py b/curses/curses_misc.py index 64de914..898cd89 100644 --- a/curses/curses_misc.py +++ b/curses/curses_misc.py @@ -63,8 +63,11 @@ class ToggleEdit(urwid.WidgetWrap): self._w.set_attr('editbx') else: self._w.set_attr('body') + + def set_edit_text(self,text): + self._w.set_edit_text(text) - # If we aren't sensitive, don't be selectab;e + # If we aren't sensitive, don't be selectable def selectable(self): return self.sensitive @@ -125,10 +128,16 @@ class TabColumns(urwid.WidgetWrap): return key # self.listbox.body = lw + +### Combo box code begins here + +class ComboBoxException(Exception): + pass + # A "combo box" of SelTexts # I based this off of the code found here: # http://excess.org/urwid/browser/contrib/trunk/rbreu_menus.py -class ComboText(urwid.WidgetWrap): +class ComboBox(urwid.WidgetWrap): """A ComboBox of text objects""" class ComboSpace(urwid.WidgetWrap): """The actual menu-like space that comes down from the ComboText""" @@ -183,8 +192,7 @@ class ComboText(urwid.WidgetWrap): #def get_size(self): - def __init__(self,label,list,body,ui,row = 0,show_first=0,attr=('body','focus'), - use_enter=True): + def __init__(self,label='',list=[],attr=('body','focus'),use_enter=True,show_first=0): """ label : bit of text that preceeds the combobox. If it is "", then ignore it @@ -194,31 +202,60 @@ class ComboText(urwid.WidgetWrap): row : where this object is to be found onscreen show_first: index of the element in the list to pick first """ - + self.label = urwid.Text(label) + self.attr = attr + self.list = list str,trash = self.label.get_text() - self.cbox = urwid.AttrWrap(SelText([list[show_first]+' vvv']), - attr[0],attr[1]) + self.overlay = None + + self.cbox = urwid.AttrWrap(SelText(' vvv'),attr[0],attr[1]) # Unicode will kill me sooner or later. ^_^ if label != '': w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1) - self.overlay = self.ComboSpace(list,body,ui,show_first,pos=(len(str)+1,row)) else: w = urwid.Columns([self.cbox]) - self.overlay = self.ComboSpace(list,body,ui,show_first,pos=(0,row)) self.__super.__init__(w) - # We need this to control the keypress + # We need this to pick our keypresses + self.use_enter = use_enter + + # Set the focus at the beginning to 0 + self.show_first = show_first + + def set_list(self,list): + self.list = list + + def set_show_first(self,show_first): + self.show_first = show_first + + def build_combobox(self,body,ui,row,show_first=0): + str,trash = self.label.get_text() + self.cbox = urwid.AttrWrap(SelText([self.list[show_first]+' vvv']), + self.attr[0],self.attr[1]) + if str != '': + w = urwid.Columns([('fixed',len(str),self.label),self.cbox],dividechars=1) + self.overlay = self.ComboSpace(self.list,body,ui,self.show_first, + pos=(len(str)+1,row)) + else: + w = urwid.Columns([self.cbox]) + self.overlay = self.ComboSpace(self.list,body,ui,self.show_first, + pos=(0,row)) + + self.set_w(w) self.body = body self.ui = ui - self.use_enter = use_enter + # If we press space or enter, be a combo box! def keypress(self,size,key): activate = key == ' ' if self.use_enter: activate = activate or key == 'enter' if activate: + # Die if the user didn't prepare the combobox overlay + if self.overlay == None: + 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')) diff --git a/curses/prefs_curses.py b/curses/prefs_curses.py index 67ae0bd..3d1eee9 100644 --- a/curses/prefs_curses.py +++ b/curses/prefs_curses.py @@ -22,7 +22,7 @@ import urwid.curses_display from wicd import misc from wicd import dbusmanager -from curses_misc import SelText,ToggleEdit,ComboText,TabColumns +from curses_misc import SelText,ToggleEdit,ComboBox,TabColumns daemon = None wireless = None @@ -33,7 +33,6 @@ language = misc.get_language_list_gui() class PrefsDialog(urwid.WidgetWrap): def __init__(self,body,pos,ui,dbus=None): global daemon, wireless, wired - self.ui = ui daemon = dbus['daemon'] wireless = dbus['wireless'] @@ -91,9 +90,9 @@ class PrefsDialog(urwid.WidgetWrap): wired1_t = 'ethtool' wired2_t = 'mii-tool' - route_table_header_t = ('header',language["route_flush"]) - route1_t = 'ip' - route2_t = 'route' + flush_header_t = ('header',language["route_flush"]) + flush1_t = 'ip' + flush2_t = 'route' #### Advanced Settings #wpa_t=('editcp',language['wpa_supplicant_driver']+':') @@ -122,10 +121,12 @@ class PrefsDialog(urwid.WidgetWrap): # General Settings self.net_cat = urwid.Text(net_cat_t) - self.wired_iface = urwid.AttrWrap(urwid.Edit(wired_t),'editbx','editfc') - self.wless_iface = urwid.AttrWrap(urwid.Edit(wless_t),'editbx','editfc') + self.wired_edit = urwid.AttrWrap(urwid.Edit(wired_t),'editbx','editfc') + self.wless_edit = urwid.AttrWrap(urwid.Edit(wless_t),'editbx','editfc') self.global_dns_cat = urwid.Text(global_dns_cat_t) + # Default the global DNS settings to off. They will be reenabled later + # if so required. global_dns_state = False self.global_dns_checkb = urwid.CheckBox(global_dns_t,global_dns_state, on_state_change=self.global_dns_trigger) @@ -142,8 +143,8 @@ class PrefsDialog(urwid.WidgetWrap): self.wired_auto_2 = urwid.RadioButton(wired_auto_l,wired_auto_2_t) self.wired_auto_3 = urwid.RadioButton(wired_auto_l,wired_auto_3_t) generalLB = urwid.ListBox([self.net_cat, - self.wless_iface,#self._blank, - self.wired_iface, + self.wless_edit,#self._blank, + self.wired_edit, self.always_show_wired_checkb,self._blank, self.global_dns_cat, self.global_dns_checkb,#self._blank, @@ -159,24 +160,24 @@ class PrefsDialog(urwid.WidgetWrap): automatic_t = language['wicd_auto_config'] self.dhcp_header = urwid.Text(dhcp_header_t) - dhcp_l = [] + self.dhcp_l = [] # Automatic - self.dhcp0 = urwid.RadioButton(dhcp_l,automatic_t) - self.dhcp1 = urwid.RadioButton(dhcp_l,dhcp1_t) - self.dhcp2 = urwid.RadioButton(dhcp_l,dhcp2_t) - self.dhcp3 = urwid.RadioButton(dhcp_l,dhcp3_t) + self.dhcp0 = urwid.RadioButton(self.dhcp_l,automatic_t) + self.dhcp1 = urwid.RadioButton(self.dhcp_l,dhcp1_t) + self.dhcp2 = urwid.RadioButton(self.dhcp_l,dhcp2_t) + self.dhcp3 = urwid.RadioButton(self.dhcp_l,dhcp3_t) - wired_l = [] + self.wired_l = [] self.wired_detect_header = urwid.Text(wired_detect_header_t) - self.wired0 = urwid.RadioButton(wired_l,automatic_t) - self.wired1 = urwid.RadioButton(wired_l,wired1_t) - self.wired2 = urwid.RadioButton(wired_l,wired2_t) + self.wired0 = urwid.RadioButton(self.wired_l,automatic_t) + self.wired1 = urwid.RadioButton(self.wired_l,wired1_t) + self.wired2 = urwid.RadioButton(self.wired_l,wired2_t) - route_l = [] - self.route_table_header = urwid.Text(route_table_header_t) - self.route0 = urwid.RadioButton(route_l,automatic_t) - self.route1 = urwid.RadioButton(route_l,route1_t) - self.route2 = urwid.RadioButton(route_l,route2_t) + self.flush_l = [] + self.flush_header = urwid.Text(flush_header_t) + self.flush0 = urwid.RadioButton(self.flush_l,automatic_t) + self.flush1 = urwid.RadioButton(self.flush_l,flush1_t) + self.flush2 = urwid.RadioButton(self.flush_l,flush2_t) externalLB = urwid.ListBox([self.dhcp_header, self.dhcp0,self.dhcp1,self.dhcp2,self.dhcp3, @@ -184,18 +185,18 @@ class PrefsDialog(urwid.WidgetWrap): self.wired_detect_header, self.wired0,self.wired1,self.wired2, self._blank, - self.route_table_header, - self.route0,self.route1,self.route2 + self.flush_header, + self.flush0,self.flush1,self.flush2 ]) #### Advanced settings self.wpa_cat = urwid.Text(wpa_cat_t) - self.wpa_cbox = ComboText(wpa_t,wpa_list,self,ui,4) + self.wpa_cbox = ComboBox(wpa_t) self.wpa_warn = urwid.Text(wpa_warn_t) self.backend_cat = urwid.Text(backend_cat_t) - self.backend_cbox = ComboText(backend_t,backend_list,self,ui,8) + self.backend_cbox = ComboBox(backend_t) self.debug_cat = urwid.Text(debug_cat_t) self.debug_mode_checkb = urwid.CheckBox(debug_mode_t) @@ -223,7 +224,7 @@ class PrefsDialog(urwid.WidgetWrap): self.tab_map = {self.header0 : generalLB, self.header1 : externalLB, self.header2 : advancedLB} - self.load_settings() + #self.load_settings() # Now for the buttons: @@ -266,6 +267,11 @@ class PrefsDialog(urwid.WidgetWrap): def global_dns_trigger(self,check_box,new_state,user_data=None): for w in self.search_dom,self.dns1,self.dns2,self.dns3: w.set_sensitive(new_state) + + def ready_comboboxes(self,ui,body): + self.wpa_cbox.build_combobox(body,ui,4) + self.backend_cbox.build_combobox(body,ui,8) + # Normal keypress, but if we are at the top, then be "tabbish" instead #def keypress(self,size,ui): # self._w.keypress(size,ui) @@ -283,16 +289,16 @@ class PrefsDialog(urwid.WidgetWrap): # Put the widget into an overlay, and run! def run(self,ui, dim, display): width,height = ui.get_cols_rows() + self.load_settings() + # TODO: The below, if things go 'well' # If we are small, "tabbify" the interface - # Else, pile it together + overlay = urwid.Overlay(self.tabs, display, ('fixed left', 0),width , ('fixed top',1), height-3) + # Will need once we actually get the comboboxes filled with stuff + #self.ready_comboboxes(ui,overlay) - #dialog = TabbedOverlay(["Foo", "Bar", "Quit"], - # ('body', 'focus'), (1, 1), display) - - #dialog = PrefOverlay(display,(0,1)) keys = True while True: if keys: @@ -308,10 +314,13 @@ class PrefsDialog(urwid.WidgetWrap): #Send key to underlying widget: overlay.keypress(dim, k) -def run(): +def run_it(): dialog = PrefsDialog(None,(0,0),ui,dbusmanager.get_dbus_ifaces()) keys = True dim = ui.get_cols_rows() + dialog.load_settings() + # Will need once we actually get the comboboxes filled with stuff + #self.ready_comboboxes(ui,overlay) while True: if keys: ui.draw_screen(dim, dialog.render(dim, True)) @@ -347,4 +356,4 @@ if __name__=='__main__': ('editbx', 'light gray', 'dark blue'), ('editfc', 'white','dark blue', 'bold'), ('tab active','dark green','light gray')]) - ui.run_wrapper(run) + ui.run_wrapper(run_it) diff --git a/curses/wicd-curses.py b/curses/wicd-curses.py index 06f5d04..dd19dde 100644 --- a/curses/wicd-curses.py +++ b/curses/wicd-curses.py @@ -56,7 +56,7 @@ import sys from time import sleep # Curses UIs for other stuff -from curses_misc import SelText,ComboText +from curses_misc import SelText,ComboBox import prefs_curses from prefs_curses import PrefsDialog @@ -230,21 +230,8 @@ class appGUI(): self.wiredH=urwid.Filler(urwid.Text("Wired Network(s)")) self.wlessH=urwid.Filler(urwid.Text("Wireless Network(s)")) - self.footer1 = urwid.AttrWrap(urwid.Text("Something important will eventually go here."),'body') - self.footer2 = urwid.AttrWrap(urwid.Text("If you are seeing this, then something has gone wrong!"),'important') - self.footerList = urwid.ListBox([self.footer1,self.footer2]) - # Pop takes a number! - #walker.pop(1) - nothingness = urwid.Filler(urwid.Text('Hello, world!')) - self.frame = urwid.Frame(nothingness, - header=header, - footer=urwid.BoxAdapter(self.footerList,2)) - self.frame.set_focus('body') - - # Miiiiiiiiiiight be changing this back to something like how it was - # originally wiredL,wlessL = gen_network_list() - self.wiredCB = urwid.Filler(ComboText('',wiredL,self.frame,ui,3,use_enter=False)) + self.wiredCB = urwid.Filler(ComboBox(list=wiredL,use_enter=False)) self.wlessLB = urwid.ListBox(wlessL) # Stuff I used to simulate large lists #spam = SelText('spam') @@ -259,6 +246,17 @@ class appGUI(): ('fixed',1,self.wlessH), self.wlessLB] ) + self.footer1 = urwid.AttrWrap(urwid.Text("Something important will eventually go here."),'body') + self.footer2 = urwid.AttrWrap(urwid.Text("If you are seeing this, then something has gone wrong!"),'important') + self.footerList = urwid.ListBox([self.footer1,self.footer2]) + # Pop takes a number! + #walker.pop(1) + nothingness = urwid.Filler(urwid.Text('Hello, world!')) + self.frame = urwid.Frame(self.thePile, + header=header, + footer=urwid.BoxAdapter(self.footerList,2)) + self.wiredCB.get_body().build_combobox(self.frame,ui,3) + self.frame.set_body(self.thePile) # Booleans gallore! self.prev_state = False @@ -270,7 +268,6 @@ class appGUI(): #self.dialog = PrefOverlay(self.frame,self.size) - # Does what it says it does def lock_screen(self): self.frame.set_body(self.screen_locker) @@ -294,8 +291,10 @@ class appGUI(): state, x = daemon.GetConnectionStatus() if self.prev_state != state or force_check: wiredL,wlessL = gen_network_list() - self.wiredCB = urwid.Filler(ComboText('',wiredL,self.frame,ui,3, - use_enter=False)) + #self.wiredCB = urwid.Filler(ComboBox(wiredL,self.frame,ui,3, + # use_enter=False)) + self.wiredCB.get_body().set_list(wiredL) + self.wiredCB.get_body().build_combobox(self.frame,ui,3) self.wlessLB.body = urwid.SimpleListWalker(wlessL) self.prev_state = state @@ -440,7 +439,7 @@ class appGUI(): self.frame.keypress( self.size, k ) if " " in keys: - self.set_status('space pressed on wiredCB!') + #self.set_status('space pressed on wiredCB!') wid,pos = self.wiredCB.get_body().get_selected() text,attr = wid.get_text() wired.ReadWiredNetworkProfile(text)