Mercurial > libervia-backend
comparison frontends/src/primitivus/xmlui.py @ 655:56f8a9c99194
core, primitivus: better support for parameter of type list
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 02 Oct 2013 17:38:29 +0200 |
parents | 49587e170f53 |
children | af0d08a84cc6 |
comparison
equal
deleted
inserted
replaced
654:5c5cf5bca240 | 655:56f8a9c99194 |
---|---|
103 elif type_=="bool": | 103 elif type_=="bool": |
104 ctrl = urwid.CheckBox('', state = value=="true") | 104 ctrl = urwid.CheckBox('', state = value=="true") |
105 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) | 105 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) |
106 elif type_=="list": | 106 elif type_=="list": |
107 style=[] if elem.getAttribute("multi")=='yes' else ['single'] | 107 style=[] if elem.getAttribute("multi")=='yes' else ['single'] |
108 ctrl = sat_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style) | 108 ctrl = sat_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style, on_change=self.onParamChange) |
109 ctrl.selectValue(elem.getAttribute("value")) | |
109 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) | 110 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) |
110 elif type_=="button": | 111 elif type_=="button": |
111 callback_id = elem.getAttribute("callback_id") | 112 callback_id = elem.getAttribute("callback_id") |
112 ctrl = sat_widgets.CustomButton(value, on_press=self.onButtonPress) | 113 ctrl = sat_widgets.CustomButton(value, on_press=self.onButtonPress) |
113 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")]) | 114 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")]) |
114 elif type_=="advanced_list": | 115 elif type_=="advanced_list": |
115 ctrl = sat_widgets.List(options=[getText(txt_elt) for txt_elt in elem.getElementsByTagName("text")], style=['can_select_none'], max_height=20) | 116 ctrl = sat_widgets.List(options=[getText(txt_elt) for txt_elt in elem.getElementsByTagName("text")], style=['can_select_none'], max_height=20, on_change=self.onParamChange) |
116 | 117 ctrl.selectValue(elem.getAttribute("value")) |
117 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) | 118 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) |
118 else: | 119 else: |
119 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type_) #FIXME ! | 120 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type_) #FIXME ! |
120 raise NotImplementedError | 121 raise NotImplementedError |
121 if self.type == 'param': | 122 if self.type == 'param': |
122 if isinstance(ctrl,urwid.Edit) or isinstance(ctrl,urwid.CheckBox): | 123 if isinstance(ctrl, urwid.Edit) or isinstance(ctrl, urwid.CheckBox): |
123 urwid.connect_signal(ctrl,'change',self.onParamChange) | 124 urwid.connect_signal(ctrl,'change',self.onParamChange) |
125 elif isinstance(ctrl, sat_widgets.List): | |
126 # the GenericList member triggers the events, not List itself | |
127 # TODO: create a method GenericList.setParamData() for that, | |
128 # or later in onSaveParams do something like ctrl.getParent() | |
129 ctrl.genericList._param_category = self._current_category | |
130 ctrl.genericList._param_name = name | |
124 ctrl._param_category = self._current_category | 131 ctrl._param_category = self._current_category |
125 ctrl._param_name = name | 132 ctrl._param_name = name |
126 parent.append(ctrl) | 133 parent.append(ctrl) |
127 | 134 |
128 def __parseChilds(self, current, elem, wanted = ['layout'], data = None): | 135 def __parseChilds(self, current, elem, wanted = ['layout'], data = None): |
226 callback_id, fields = button.param_id | 233 callback_id, fields = button.param_id |
227 data = {"callback_id":callback_id} | 234 data = {"callback_id":callback_id} |
228 for field in fields: | 235 for field in fields: |
229 ctrl = self.ctrl_list[field] | 236 ctrl = self.ctrl_list[field] |
230 if isinstance(ctrl['control'],sat_widgets.List): | 237 if isinstance(ctrl['control'],sat_widgets.List): |
231 data[field] = '\t'.join(ctrl['control'].getSelectedValues()) | 238 data[field] = u'\t'.join(ctrl['control'].getSelectedValues()) |
232 else: | 239 else: |
233 data[field] = ctrl['control'].getValue() | 240 data[field] = ctrl['control'].getValue() |
234 | 241 |
235 id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile) | 242 id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile) |
236 self.host.current_action_ids.add(id) | 243 self.host.current_action_ids.add(id) |
243 def onFormSubmitted(self, button): | 250 def onFormSubmitted(self, button): |
244 data = [] | 251 data = [] |
245 for ctrl_name in self.ctrl_list: | 252 for ctrl_name in self.ctrl_list: |
246 ctrl = self.ctrl_list[ctrl_name] | 253 ctrl = self.ctrl_list[ctrl_name] |
247 if isinstance(ctrl['control'], sat_widgets.List): | 254 if isinstance(ctrl['control'], sat_widgets.List): |
248 data.append((ctrl_name, ctrl['control'].getSelectedValue())) | 255 data.append((ctrl_name, u'\t'.join(ctrl['control'].getSelectedValues()))) |
249 elif isinstance(ctrl['control'], urwid.CheckBox): | 256 elif isinstance(ctrl['control'], urwid.CheckBox): |
250 data.append((ctrl_name, "true" if ctrl['control'].get_state() else "false")) | 257 data.append((ctrl_name, "true" if ctrl['control'].get_state() else "false")) |
251 else: | 258 else: |
252 data.append((ctrl_name, ctrl['control'].get_edit_text())) | 259 data.append((ctrl_name, ctrl['control'].get_edit_text())) |
253 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned | 260 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned |
271 | 278 |
272 def onSaveParams(self, button): | 279 def onSaveParams(self, button): |
273 for ctrl in self.param_changed: | 280 for ctrl in self.param_changed: |
274 if isinstance(ctrl, urwid.CheckBox): | 281 if isinstance(ctrl, urwid.CheckBox): |
275 value = "true" if ctrl.get_state() else "false" | 282 value = "true" if ctrl.get_state() else "false" |
283 elif isinstance(ctrl, sat_widgets.GenericList): | |
284 value = u'\t'.join(ctrl.getSelectedValues()) | |
276 else: | 285 else: |
277 value = ctrl.get_edit_text() | 286 value = ctrl.get_edit_text() |
278 self.host.bridge.setParam(ctrl._param_name, value, ctrl._param_category, | 287 self.host.bridge.setParam(ctrl._param_name, value, ctrl._param_category, |
279 profile_key=self.host.profile) | 288 profile_key=self.host.profile) |
280 self.host.removeWindow() | 289 self.host.removeWindow() |