From c34a6e5795c3e36377f2da23bf2b6f6c92e54fee Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 9 Aug 2010 21:58:28 +0800 Subject: [PATCH] Primitivus: misc improvments on TabsContainer/FocusFrame - FocusFrame: better management of keypress - TabsContainer: new addFooter method, to add a widget on the bottom of the container --- frontends/primitivus/custom_widgets.py | 22 ++++++++++++++++------ frontends/primitivus/xmlui.py | 8 +++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/frontends/primitivus/custom_widgets.py b/frontends/primitivus/custom_widgets.py index bcde7046..d6b8a691 100644 --- a/frontends/primitivus/custom_widgets.py +++ b/frontends/primitivus/custom_widgets.py @@ -816,6 +816,10 @@ class FocusFrame(urwid.Frame): """Frame which manage 'tab' key""" def keypress(self, size, key): + ret = urwid.Frame.keypress(self, size, key) + if not ret: + return + if key == 'tab': focus_list = ('header','body','footer') focus_idx = focus_list.index(self.focus_part) @@ -826,7 +830,7 @@ class FocusFrame(urwid.Frame): if widget!=None and widget.selectable(): self.set_focus(focus_name) - return urwid.Frame.keypress(self, size, key) + return ret class TabsContainer(urwid.WidgetWrap): signals = ['click'] @@ -835,14 +839,14 @@ class TabsContainer(urwid.WidgetWrap): #self._current_tab = 0 self._buttons_cont = ColumnsRoller() self.tabs = [] - self.__frame = urwid.Frame(urwid.Filler(urwid.Text('')),urwid.Pile([self._buttons_cont,urwid.Divider(u"─")])) + self.__frame = FocusFrame(urwid.Filler(urwid.Text('')),urwid.Pile([self._buttons_cont,urwid.Divider(u"─")])) urwid.WidgetWrap.__init__(self, self.__frame) - """def selectable(self): - return True - def keypress(self, size, key): - return key""" + if key=='tab': + self._w.keypress(size,key) + return + return self._w.keypress(size,key) def __buttonClicked(self, button, invisible=False): """Called when a button on the tab is changed, @@ -880,6 +884,12 @@ class TabsContainer(urwid.WidgetWrap): self.__appendButton(name) return listbox + def addFooter(self, widget): + """Add a widget on the bottom of the tab (will be displayed on all pages) + @param widget: FlowWidget""" + self._w.footer = widget + + ## DECORATORS ## class LabelLine(urwid.LineBox): """Like LineBox, but with a Label centered in the top line""" diff --git a/frontends/primitivus/xmlui.py b/frontends/primitivus/xmlui.py index 0830e607..c3838fff 100644 --- a/frontends/primitivus/xmlui.py +++ b/frontends/primitivus/xmlui.py @@ -164,7 +164,7 @@ class XMLUI(urwid.WidgetWrap): assert ret_wid.body if isinstance(ret_wid.body[0],custom_widgets.TabsContainer): - ret_wid = urwid.Pile([ret_wid.body[0]]) #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox + ret_wid = ret_wid.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox if self.type == 'form': @@ -176,15 +176,13 @@ class XMLUI(urwid.WidgetWrap): grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center') ret_wid.body.append(grid_wid) elif self.type == 'param': - assert(isinstance(ret_wid,urwid.Pile)) + assert(isinstance(ret_wid,custom_widgets.TabsContainer)) buttons = [] buttons.append(custom_widgets.CustomButton(_('Save'),self.onSaveParams)) buttons.append(custom_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow())) max_len = max([button.getSize() for button in buttons]) grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center') - ret_wid.widget_list.append(urwid.Filler(grid_wid)) - ret_wid.item_types.append(('weight',1)) - + ret_wid.addFooter(grid_wid) return ret_wid def show(self):