diff frontends/src/primitivus/xmlui.py @ 1478:90130847a0a8

frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
author Goffi <goffi@goffi.org>
date Thu, 20 Aug 2015 18:36:53 +0200
parents 675e0e9f1653
children a77217511afd
line wrap: on
line diff
--- a/frontends/src/primitivus/xmlui.py	Thu Aug 20 18:35:27 2015 +0200
+++ b/frontends/src/primitivus/xmlui.py	Thu Aug 20 18:36:53 2015 +0200
@@ -217,6 +217,27 @@
                     selected.append(value)
             self._xmluiSelectValues(selected)
 
+class PrimitivusJidsListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents):
+
+    def __init__(self, _xmlui_parent, jids, styles):
+        sat_widgets.List.__init__(self, options=jids+[''], # the empty field is here to add new jids if needed
+                                  option_type=lambda txt, align: sat_widgets.AdvancedEdit(edit_text=txt, align=align),
+                                  on_change=self._onChange)
+        self.delete=0
+
+    def _onChange(self, list_widget, jid_widget=None, text=None):
+        if jid_widget is not None:
+            if jid_widget != list_widget.contents[-1] and not text:
+                # if a field is empty, we delete the line (except for the last line)
+                list_widget.contents.remove(jid_widget)
+            elif jid_widget == list_widget.contents[-1] and text:
+                # we always want an empty field as last value to be able to add jids
+                list_widget.contents.append(sat_widgets.AdvancedEdit())
+
+    def _xmluiGetSelectedValues(self):
+        # XXX: there is not selection in this list, so we return all non empty values
+        return [jid_ for jid_ in self.getAllValues() if jid_]
+
 
 class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents):
 
@@ -386,7 +407,7 @@
                 self.main_cont.body.append(grid_wid)
             elif self.type == 'param':
                 tabs_cont = self.main_cont.body[0].base_widget
-                assert(isinstance(tabs_cont,sat_widgets.TabsContainer))
+                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()))
@@ -422,7 +443,7 @@
         elif show_type == 'window':
             self.host.newWidget(self)
         else:
-            assert(False)
+           assert False
         self.host.redraw()
 
     def _xmluiClose(self):