diff frontends/src/primitivus/xmlui.py @ 802:9007bb133009

core, frontends: XMLUI refactoring: - XMLUI now use objects with 2 main classes: widgets (button, label, etc), and container which contain widgets according to a layout - widgets and containers classes are found through introspection, thereby it's really easy to add a new one - there is still the AddWidgetName helper, for example AddText('jid', 'test@example.net') will add a StringWidget with name "jid" and default value "test@example.net" - container can be inside other containers. changeContainer change the first parent container
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:19:00 +0100
parents 46aa5ada61bf
children f100fd8d279f
line wrap: on
line diff
--- a/frontends/src/primitivus/xmlui.py	Tue Feb 04 18:06:12 2014 +0100
+++ b/frontends/src/primitivus/xmlui.py	Tue Feb 04 18:19:00 2014 +0100
@@ -103,12 +103,6 @@
         return [option.value for option in self.getSelectedValues()]
 
 
-class PrimitivusAdvancedListWidget(PrimitivusListWidget, PrimitivusEvents):
-
-    def __init__(self, parent, options, flags):
-        sat_widgets.List.__init__(self, options=options, style=flags, max_height=20)
-
-
 class PrimitivusPairsContainer(xmlui.PairsContainer, urwid.WidgetWrap):
 
     def __init__(self, parent, weight_0='1', weight_1='1'):
@@ -148,7 +142,6 @@
 
 class PrimitivusVerticalContainer(xmlui.VerticalContainer, urwid.ListBox):
 
-
     def __init__(self, parent):
         urwid.ListBox.__init__(self, urwid.SimpleListWalker([]))
 
@@ -169,13 +162,14 @@
     def __init__(self, host, xml_data, title = None, flags = None):
         self._dest = "window"
         xmlui.XMLUI.__init__(self, host, xml_data, title, flags)
+        urwid.WidgetWrap.__init__(self, self.main_cont)
 
     def constructUI(self, xml_data):
-        def postTreat(ret_wid):
-            assert ret_wid.body
+        def postTreat():
+            assert self.main_cont.body
 
-            if isinstance(ret_wid.body[0],sat_widgets.TabsContainer):
-                ret_wid = ret_wid.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox
+            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 = []
@@ -184,19 +178,18 @@
                     buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled))
                 max_len = max([len(button.get_label()) for button in buttons])
                 grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center')
-                ret_wid.body.append(grid_wid)
+                self.main_cont.body.append(grid_wid)
             elif self.type == 'param':
-                assert(isinstance(ret_wid,sat_widgets.TabsContainer))
+                assert(isinstance(self.main_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')
-                ret_wid.addFooter(grid_wid)
-            return ret_wid
+                self.main_cont.addFooter(grid_wid)
 
-        widget = super(XMLUI, self).constructUI(xml_data, postTreat)
-        urwid.WidgetWrap.__init__(self, widget)
+        super(XMLUI, self).constructUI(xml_data, postTreat)
+        urwid.WidgetWrap.__init__(self, self.main_cont)
 
     def show(self, show_type='popup', valign='middle'):
         """Show the constructed UI