diff frontends/primitivus/xmlui.py @ 183:9ee4a1d0d7fb

Added auto(dis)connect params + misc - parameters,xmlui: "bool" type is now managed - parameters,xmlui: categories now use label in addition of name - QuickFrontend: auto(dis)connection management - plugin XEP-0045: an error dialog is now show in frontend if room cannot be joined - Wix: fixed unproper close event management
author Goffi <goffi@goffi.org>
date Wed, 18 Aug 2010 15:57:26 +0800
parents 2ea8dab08160
children 879beacb8e16
line wrap: on
line diff
--- a/frontends/primitivus/xmlui.py	Wed Aug 18 12:45:48 2010 +0800
+++ b/frontends/primitivus/xmlui.py	Wed Aug 18 15:57:26 2010 +0800
@@ -90,6 +90,9 @@
             elif type=="textbox":
                 ctrl = custom_widgets.AdvancedEdit(edit_text = value, multiline=True)
                 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
+            elif type=="bool":
+                ctrl = urwid.CheckBox('', state = value=="true")
+                self.ctrl_list[name] = ({'type':type, 'control':ctrl})
             elif type=="list":
                 style=[] if elem.getAttribute("multi")=='yes' else ['single']
                 ctrl = custom_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style)
@@ -102,7 +105,7 @@
                 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type)  #FIXME !
                 raise NotImplementedError
             if self.type == 'param':
-                if isinstance(ctrl,urwid.Edit):
+                if isinstance(ctrl,urwid.Edit) or isinstance(ctrl,urwid.CheckBox):
                     urwid.connect_signal(ctrl,'change',self.onParamChange)
                 ctrl._param_category = self._current_category
                 ctrl._param_name = name
@@ -133,12 +136,13 @@
                     self.__parseElems(node, current)
             elif node.nodeName == "category":
                 name = node.getAttribute('name') 
+                label = node.getAttribute('label') 
                 if not name or not isinstance(data,custom_widgets.TabsContainer):
                     raise InvalidXMLUI 
                 if self.type == 'param':
                     self._current_category = name #XXX: awful hack because params need category and we don't keep parent
                 tab_cont = data
-                listbox = tab_cont.addTab(name)
+                listbox = tab_cont.addTab(label or name)
                 self.__parseChilds(listbox.body, node, ['layout'])
             else:
                 message=_("Unknown tag")
@@ -217,7 +221,7 @@
         id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile)
         self.host.current_action_ids.add(id)
 
-    def onParamChange(self, widget, text):
+    def onParamChange(self, widget, extra=None):
         """Called when type is param and a widget to save is modified"""
         assert(self.type == "param")
         self.param_changed.add(widget)
@@ -228,6 +232,8 @@
             ctrl = self.ctrl_list[ctrl_name]
             if isinstance(ctrl['control'], custom_widgets.List):
                 data.append((ctrl_name, ctrl['control'].getSelectedValue()))
+            if isinstance(ctrl['control'], urwid.CheckBox):
+                data.append((ctrl_name, "true" if ctrl['control'].get_state() else "false"))
             else:
                 data.append((ctrl_name, ctrl['control'].get_edit_text()))
         if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
@@ -247,5 +253,9 @@
 
     def onSaveParams(self, button):
         for ctrl in self.param_changed:
-            self.host.bridge.setParam(ctrl._param_name, ctrl.get_edit_text(), ctrl._param_category, profile_key = self.host.profile)
+            if isinstance(ctrl, urwid.CheckBox):
+                value = "true" if ctrl.get_state() else "false"
+            else:
+                value = ctrl.get_edit_text()
+            self.host.bridge.setParam(ctrl._param_name, value, ctrl._param_category, profile_key = self.host.profile)
         self.host.removeWindow()