Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
182:556c2bd7c344 | 183:9ee4a1d0d7fb |
---|---|
88 ctrl = custom_widgets.Password(edit_text = value) | 88 ctrl = custom_widgets.Password(edit_text = value) |
89 self.ctrl_list[name] = ({'type':type, 'control':ctrl}) | 89 self.ctrl_list[name] = ({'type':type, 'control':ctrl}) |
90 elif type=="textbox": | 90 elif type=="textbox": |
91 ctrl = custom_widgets.AdvancedEdit(edit_text = value, multiline=True) | 91 ctrl = custom_widgets.AdvancedEdit(edit_text = value, multiline=True) |
92 self.ctrl_list[name] = ({'type':type, 'control':ctrl}) | 92 self.ctrl_list[name] = ({'type':type, 'control':ctrl}) |
93 elif type=="bool": | |
94 ctrl = urwid.CheckBox('', state = value=="true") | |
95 self.ctrl_list[name] = ({'type':type, 'control':ctrl}) | |
93 elif type=="list": | 96 elif type=="list": |
94 style=[] if elem.getAttribute("multi")=='yes' else ['single'] | 97 style=[] if elem.getAttribute("multi")=='yes' else ['single'] |
95 ctrl = custom_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style) | 98 ctrl = custom_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style) |
96 self.ctrl_list[name] = ({'type':type, 'control':ctrl}) | 99 self.ctrl_list[name] = ({'type':type, 'control':ctrl}) |
97 elif type=="button": | 100 elif type=="button": |
100 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")]) | 103 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")]) |
101 else: | 104 else: |
102 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME ! | 105 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME ! |
103 raise NotImplementedError | 106 raise NotImplementedError |
104 if self.type == 'param': | 107 if self.type == 'param': |
105 if isinstance(ctrl,urwid.Edit): | 108 if isinstance(ctrl,urwid.Edit) or isinstance(ctrl,urwid.CheckBox): |
106 urwid.connect_signal(ctrl,'change',self.onParamChange) | 109 urwid.connect_signal(ctrl,'change',self.onParamChange) |
107 ctrl._param_category = self._current_category | 110 ctrl._param_category = self._current_category |
108 ctrl._param_name = name | 111 ctrl._param_name = name |
109 parent.append(ctrl) | 112 parent.append(ctrl) |
110 | 113 |
131 else: | 134 else: |
132 warning(_("Unknown layout, using default one")) | 135 warning(_("Unknown layout, using default one")) |
133 self.__parseElems(node, current) | 136 self.__parseElems(node, current) |
134 elif node.nodeName == "category": | 137 elif node.nodeName == "category": |
135 name = node.getAttribute('name') | 138 name = node.getAttribute('name') |
139 label = node.getAttribute('label') | |
136 if not name or not isinstance(data,custom_widgets.TabsContainer): | 140 if not name or not isinstance(data,custom_widgets.TabsContainer): |
137 raise InvalidXMLUI | 141 raise InvalidXMLUI |
138 if self.type == 'param': | 142 if self.type == 'param': |
139 self._current_category = name #XXX: awful hack because params need category and we don't keep parent | 143 self._current_category = name #XXX: awful hack because params need category and we don't keep parent |
140 tab_cont = data | 144 tab_cont = data |
141 listbox = tab_cont.addTab(name) | 145 listbox = tab_cont.addTab(label or name) |
142 self.__parseChilds(listbox.body, node, ['layout']) | 146 self.__parseChilds(listbox.body, node, ['layout']) |
143 else: | 147 else: |
144 message=_("Unknown tag") | 148 message=_("Unknown tag") |
145 error(message) | 149 error(message) |
146 raise NotImplementedError | 150 raise NotImplementedError |
215 data[field] = ctrl['control'].getValue() | 219 data[field] = ctrl['control'].getValue() |
216 | 220 |
217 id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile) | 221 id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile) |
218 self.host.current_action_ids.add(id) | 222 self.host.current_action_ids.add(id) |
219 | 223 |
220 def onParamChange(self, widget, text): | 224 def onParamChange(self, widget, extra=None): |
221 """Called when type is param and a widget to save is modified""" | 225 """Called when type is param and a widget to save is modified""" |
222 assert(self.type == "param") | 226 assert(self.type == "param") |
223 self.param_changed.add(widget) | 227 self.param_changed.add(widget) |
224 | 228 |
225 def onFormSubmitted(self, button): | 229 def onFormSubmitted(self, button): |
226 data = [] | 230 data = [] |
227 for ctrl_name in self.ctrl_list: | 231 for ctrl_name in self.ctrl_list: |
228 ctrl = self.ctrl_list[ctrl_name] | 232 ctrl = self.ctrl_list[ctrl_name] |
229 if isinstance(ctrl['control'], custom_widgets.List): | 233 if isinstance(ctrl['control'], custom_widgets.List): |
230 data.append((ctrl_name, ctrl['control'].getSelectedValue())) | 234 data.append((ctrl_name, ctrl['control'].getSelectedValue())) |
235 if isinstance(ctrl['control'], urwid.CheckBox): | |
236 data.append((ctrl_name, "true" if ctrl['control'].get_state() else "false")) | |
231 else: | 237 else: |
232 data.append((ctrl_name, ctrl['control'].get_edit_text())) | 238 data.append((ctrl_name, ctrl['control'].get_edit_text())) |
233 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned | 239 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned |
234 raise NotImplementedError | 240 raise NotImplementedError |
235 self.host.debug() | 241 self.host.debug() |
245 else: | 251 else: |
246 self.host.removePopUp() | 252 self.host.removePopUp() |
247 | 253 |
248 def onSaveParams(self, button): | 254 def onSaveParams(self, button): |
249 for ctrl in self.param_changed: | 255 for ctrl in self.param_changed: |
250 self.host.bridge.setParam(ctrl._param_name, ctrl.get_edit_text(), ctrl._param_category, profile_key = self.host.profile) | 256 if isinstance(ctrl, urwid.CheckBox): |
257 value = "true" if ctrl.get_state() else "false" | |
258 else: | |
259 value = ctrl.get_edit_text() | |
260 self.host.bridge.setParam(ctrl._param_name, value, ctrl._param_category, profile_key = self.host.profile) | |
251 self.host.removeWindow() | 261 self.host.removeWindow() |