From 421c108f0485e023243218ed49e5f724a3ba44ac Mon Sep 17 00:00:00 2001 From: Andrew Psaltis Date: Fri, 6 Mar 2009 12:49:27 -0500 Subject: [PATCH] curses/prefs_curses.py: Adapted widgets for integration into the main UI curses/curses_misc.py: Removed the "bottom_part" from the TabColumns curses/wicd-curses.py: Added support for editing preferences directly in the main UI w/o a dialog 'left' now only quits with saving for the NetworkSettingsDialogs (suggestions as for what to do here would be appreciated) --- curses/curses_misc.py | 13 ++++----- curses/prefs_curses.py | 60 ++---------------------------------------- curses/wicd-curses.py | 20 +++++++------- setup.py | 2 +- 4 files changed, 19 insertions(+), 76 deletions(-) diff --git a/curses/curses_misc.py b/curses/curses_misc.py index 01b7f3a..eb42efc 100644 --- a/curses/curses_misc.py +++ b/curses/curses_misc.py @@ -171,9 +171,10 @@ class TabColumns(urwid.WidgetWrap): attr = normal attributes attrsel = attribute when active """ - def __init__(self,tab_str,tab_wid,title,bottom_part,attr=('body','focus'), + # FIXME Make the bottom_part optional + def __init__(self,tab_str,tab_wid,title,bottom_part=None,attr=('body','focus'), attrsel='tab active', attrtitle='header'): - self.bottom_part = bottom_part + #self.bottom_part = bottom_part #title_wid = urwid.Text((attrtitle,title),align='right') column_list = [] for w in tab_str: @@ -195,7 +196,7 @@ class TabColumns(urwid.WidgetWrap): self.pile = urwid.Pile([ ('fixed',1,urwid.Filler(self.columns,'top')), urwid.Filler(lbox,'top',height=('relative',99)), - ('fixed',1,urwid.Filler(self.bottom_part,'bottom')) + #('fixed',1,urwid.Filler(self.bottom_part,'bottom')) ]) if not firstrun: self.frame.set_body(self.pile) @@ -205,7 +206,7 @@ class TabColumns(urwid.WidgetWrap): return True def keypress(self,size,key): - self._w.keypress(size,key) + key = self._w.keypress(size,key) if key == "meta [" or key == "meta ]": self._w.get_body().set_focus(0) newK = 'left' if key[-1] == '[' else 'right' @@ -220,7 +221,8 @@ class TabColumns(urwid.WidgetWrap): self.columns.get_focus().set_attr('tab active') self.active_tab = self.columns.get_focus() self.gen_pile(self.tab_map[self.active_tab]) - return key + + return key # self.listbox.body = lw @@ -347,7 +349,6 @@ class ComboBox(urwid.WidgetWrap): def build_combobox(self,parent,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 != '': diff --git a/curses/prefs_curses.py b/curses/prefs_curses.py index 86b60c2..532b2e5 100755 --- a/curses/prefs_curses.py +++ b/curses/prefs_curses.py @@ -237,27 +237,10 @@ class PrefsDialog(urwid.WidgetWrap): self.header2 : advancedLB} #self.load_settings() - # Now for the buttons: - ok_t = 'OK' - cancel_t = 'Cancel' - - ok_button = urwid.AttrWrap(urwid.Button('OK',self.ok_callback),'body','focus') - cancel_button = urwid.AttrWrap(urwid.Button('Cancel',self.cancel_callback),'body','focus') - # Variables set by the buttons' callback functions - self.CANCEL_PRESSED = False - self.OK_PRESSED = False - - - self.button_cols = urwid.Columns([ok_button,cancel_button], - dividechars=1) - - self.tabs = TabColumns(headerList,lbList,language['preferences'],self.button_cols) + self.tabs = TabColumns(headerList,lbList,language['preferences']) self.__super.__init__(self.tabs) def load_settings(self): - # Reset the buttons - self.CANCEL_PRESSED = False - self.OK_PRESSED = False ### General Settings # ComboBox does not like dbus.Strings as text markups. My fault. :/ @@ -378,45 +361,6 @@ class PrefsDialog(urwid.WidgetWrap): for w in self.dns1,self.dns2,self.dns3,self.dns_dom,self.search_dom: w.set_sensitive(new_state) - # Button callbacks - def ok_callback(self,button_object,user_data=None): - self.OK_PRESSED = True - def cancel_callback(self,button_object,user_data=None): - self.CANCEL_PRESSED = True - - def ready_comboboxes(self,ui,body): + def ready_widgets(self,ui,body): self.wpa_cbox.build_combobox(body,ui,4) self.backend_cbox.build_combobox(body,ui,8) - - # Put the widget into an overlay, and run! - def run(self,ui, dim, display): - width,height = ui.get_cols_rows() - self.load_settings() - - overlay = urwid.Overlay(self.tabs, display, ('fixed left', 0),width - , ('fixed top',1), height-3) - self.ready_comboboxes(ui,overlay) - - keys = True - while True: - if keys: - ui.draw_screen(dim, overlay.render(dim, True)) - keys = ui.get_input() - - 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) - if urwid.is_mouse_event(k): - event, button, col, row = k - overlay.mouse_event( dim, - event, button, col, row, - focus=True) - # Check if buttons are pressed. - if self.CANCEL_PRESSED: - return False - if self.OK_PRESSED or 'meta enter' in keys: - return True diff --git a/curses/wicd-curses.py b/curses/wicd-curses.py index 94c91e6..c5355ad 100755 --- a/curses/wicd-curses.py +++ b/curses/wicd-curses.py @@ -564,9 +564,6 @@ class appGUI(): ('I' ,'Hidden',None), ('Q' ,'Quit',loop.quit) ] - #(' ' ,' ',None), - #(' ' ,' ',None), - #(' ' ,' ',None), self.primaryCols = OptCols(keys,debug=True) #self.time_label = urwid.Text(strftime('%H:%M:%S')) @@ -608,7 +605,6 @@ class appGUI(): ('ESC','Cancel') ],debug=True ) - # Does what it says it does def lock_screen(self): self.frame.set_body(self.screen_locker) @@ -650,7 +646,6 @@ class appGUI(): # Be clunky until I get to a later stage of development. # Update the list of networks. Usually called by DBus. - # TODO: Preserve current focus when updating the list. @wrap_exceptions() def update_netlist(self,state=None, x=None, force_check=False,firstrun=False): # Don't even try to do this if we are running a dialog @@ -755,7 +750,6 @@ class appGUI(): self.update_ui() return True - # Cheap little indicator stating that we are actually connecting twirl = ['|','/','-','\\'] tcount = 0 # Counter for said indicator @@ -873,11 +867,14 @@ class appGUI(): if not self.pref: self.pref = PrefsDialog(self.frame,(0,1),ui, dbusmanager.get_dbus_ifaces()) - if self.pref.run(ui,self.size,self.frame): - self.pref.save_settings() - self.update_ui() + self.pref.load_settings() + self.pref.ready_widgets(ui,self.frame) + self.frame.set_footer(urwid.Pile([self.prefCols,self.footer2])) + self.diag = self.pref + self.frame.set_body(self.diag) + # Halt here, keypress gets passed to the dialog otherwise + return True if "A" in keys: - self.footer1 = self.confCols about_dialog(self.frame) if "C" in keys: # Same as "enter" for now @@ -925,7 +922,8 @@ class appGUI(): if self.diag: if k == 'esc': self.restore_primary() - if k == 'left' or k == 'meta enter': + if (k == 'left' and self.diag.__class__.__mro__[0] == \ + type(urwid.WidgetWrap)) or k == 'meta enter': self.diag.save_settings() self.restore_primary() return True diff --git a/setup.py b/setup.py index 728aa53..c232c4b 100755 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ import subprocess VERSION_NUM = '1.6.0a1' # REVISION_NUM is automatically updated REVISION_NUM = 'unknown' -CURSES_REVNO = 'uimod-r287' +CURSES_REVNO = 'uimod-r288' try: if not os.path.exists('vcsinfo.py'):