changeset 912:b70fb2ac5997

primitivus: PrimitivusVerticalContainer box widgets management: /!\ Urwid SàText need to be updated /!\ - updated PrimitivusTabsContainer._xmluiAddTab to manage Urwid SàText changes - if a box widget is added to PrimitivusVerticalContainer, if will use the full available space if it is alone, else it we have a height of 5 rows
author Goffi <goffi@goffi.org>
date Fri, 21 Mar 2014 15:04:13 +0100
parents b12706d164d7
children d08cbdd566e2
files frontends/src/primitivus/xmlui.py
diffstat 1 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/xmlui.py	Fri Mar 21 15:04:03 2014 +0100
+++ b/frontends/src/primitivus/xmlui.py	Fri Mar 21 15:04:13 2014 +0100
@@ -180,21 +180,33 @@
         self.body.append(widget)
 
     def _xmluiAddTab(self, label):
-        list_box = super(PrimitivusTabsContainer, self).addTab(label)
-        if hasattr(PrimitivusVerticalContainer, "_PrimitivusVerticalContainer__super"): # workaround for Urwid's metaclass baviour
-                del PrimitivusVerticalContainer._PrimitivusVerticalContainer__super
-        PrimitivusVerticalContainer._xmluiAdapt(list_box)
-        return list_box
+        tab = PrimitivusVerticalContainer(None)
+        self.addTab(label, tab)
+        return tab
 
 
 class PrimitivusVerticalContainer(xmlui.VerticalContainer, urwid.ListBox):
+    BOX_HEIGHT = 5
 
     def __init__(self, parent):
         urwid.ListBox.__init__(self, urwid.SimpleListWalker([]))
+        self._last_size = None
 
     def _xmluiAppend(self, widget):
+        if 'flow' not in widget.sizing():
+            widget = urwid.BoxAdapter(widget, self.BOX_HEIGHT)
         self.body.append(widget)
 
+    def render(self, size, focus=False):
+        if size != self._last_size:
+            (maxcol, maxrow) = size
+            if self.body:
+                widget = self.body[0]
+                if isinstance(widget, urwid.BoxAdapter):
+                    widget.height = maxrow
+            self._last_size = size
+        return super(PrimitivusVerticalContainer, self).render(size, focus)
+
 
 class WidgetFactory(object):
 
@@ -217,9 +229,6 @@
         def postTreat():
             assert self.main_cont.body
 
-            if isinstance(self.main_cont.body[0],sat_widgets.TabsContainer):
-                self._main_cont = self.main_cont.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox
-
             if self.type == 'form':
                 buttons = []
                 buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted))
@@ -229,13 +238,14 @@
                 grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center')
                 self.main_cont.body.append(grid_wid)
             elif self.type == 'param':
-                assert(isinstance(self.main_cont,sat_widgets.TabsContainer))
+                tabs_cont = self.main_cont.body[0].base_widget
+                assert(isinstance(tabs_cont,sat_widgets.TabsContainer))
                 buttons = []
                 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams))
                 buttons.append(sat_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')
-                self.main_cont.addFooter(grid_wid)
+                tabs_cont.addFooter(grid_wid)
 
         super(XMLUI, self).constructUI(xml_data, postTreat)
         urwid.WidgetWrap.__init__(self, self.main_cont)