diff browser_side/xmlui.py @ 337:ea1be522ba88

browser side: XMLUI fixes: - wholeText is now managed in nativedom.Node - fixed Button label - fixed AdvancedListContainer row index - fixed JidWidget - added _xmluiLaunchAction and _xmluiSetParam
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 16:49:20 +0100
parents e8c26e24a6c7
children 2067d6241927
line wrap: on
line diff
--- a/browser_side/xmlui.py	Tue Feb 04 16:49:20 2014 +0100
+++ b/browser_side/xmlui.py	Tue Feb 04 16:49:20 2014 +0100
@@ -35,6 +35,7 @@
 from pyjamas.ui.HTML import HTML
 from nativedom import NativeDOM
 from sat_frontends.tools import xmlui
+from sat.core.i18n import _
 
 
 class EmptyWidget(xmlui.EmptyWidget, Label):
@@ -56,7 +57,9 @@
 
 
 class JidWidget(xmlui.JidWidget, TextWidget):
-    pass
+
+    def __init__(self, parent, value):
+        TextWidget.__init__(self, parent, value)
 
 
 class DividerWidget(xmlui.DividerWidget, HTML):
@@ -120,7 +123,7 @@
 class ButtonWidget(xmlui.ButtonWidget, Button):
 
     def __init__(self, parent, value, click_callback):
-        Button.__init__(self)
+        Button.__init__(self, value)
 
     def _xmluiOnClick(self, event):
         self.addClickListener(callback)
@@ -132,7 +135,7 @@
         ListBox.__init__(self)
         self.setMultipleSelect('single' not in flags)
         for option in options:
-            self.addItem(option[0])
+            self.addItem(option[1])
         self._xmlui_attr_map = {label: value for value, label in options}
 
     def _xmluiSelectValue(self, value):
@@ -162,9 +165,9 @@
 class AdvancedListContainer(xmlui.AdvancedListContainer, Grid):
 
     def __init__(self, parent, columns, selectable='no'):
-        Grid.__init_(self, 0, columns)
+        Grid.__init__(self, 0, columns)
         self.columns = columns
-        self.row = 0
+        self.row = -1
         self.col = 0
         self._xmlui_rows_idx = []
         self._xmlui_selectable = selectable != 'no'
@@ -186,10 +189,10 @@
         self.col += 1
 
     def _xmluiAddRow(self, idx):
-        self._xmlui_rows_idx.insert(self.row, idx)
         self.row += 1
         self.col = 0
-        self.resizeRows(self.row)
+        self._xmlui_rows_idx.insert(self.row, idx)
+        self.resizeRows(self.row+1)
 
     def _xmluiGetSelectedWidgets(self):
         return [self.getWidget(self._xmlui_selected_row, col) for col in range(self.columns)]
@@ -261,6 +264,11 @@
         instance._xmlui_main = self._xmlui_main
         return instance
 
+    def createAdvancedListContainer(self, *args, **kwargs):
+        instance = AdvancedListContainer(*args, **kwargs)
+        instance._xmlui_main = self._xmlui_main
+        return instance
+
     def createEmptyWidget(self, *args, **kwargs):
         instance = EmptyWidget(*args, **kwargs)
         instance._xmlui_main = self._xmlui_main
@@ -331,7 +339,6 @@
         self.widget_factory._xmlui_main = self
         self.dom = NativeDOM()
         dom_parse = lambda xml_data: self.dom.parseString(xml_data)
-        self._dest = "window"
         VerticalPanel.__init__(self)
         self.setSize('100%', '100%')
         xmlui.XMLUI.__init__(self, host, xml_data, title, flags, dom_parse)
@@ -345,6 +352,12 @@
         else:
             print "WARNING: no close method defined"
 
+    def _xmluiLaunchAction(self, action_id, data):
+        self.host.launchAction(action_id, data)
+
+    def _xmluiSetParam(self, name, value, category):
+        self.host.bridge.call('setParam', None, name, value, category)
+
     def constructUI(self, xml_data):
         super(XMLUI, self).constructUI(xml_data)
         self.add(self.main_cont)
@@ -361,10 +374,3 @@
             hpanel.add(Button('Cancel', lambda ignore: self._xmluiClose()))
             hpanel.add(Button('Save', self.onSaveParams))
             self.add(hpanel)
-
-    ##EVENTS##
-
-    def onSaveParams(self, ignore=None):
-        def postTreat(name, value, category):
-            self.host.bridge.call('setParam', None, name, value, category)
-        xmlui.XMLUI.onSaveParams(self, ignore, postTreat)