Mercurial > libervia-backend
diff frontends/src/tools/xmlui.py @ 969:5c7707c958d8
tools, frontends (xmlui): add setter methods for widgets + new widget InternalButton to process UI operations
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 01 Apr 2014 21:30:21 +0200 |
parents | 75f3b3b430ff |
children | b37b1d183ac3 |
line wrap: on
line diff
--- a/frontends/src/tools/xmlui.py Tue Apr 01 21:21:13 2014 +0200 +++ b/frontends/src/tools/xmlui.py Tue Apr 01 21:30:21 2014 +0200 @@ -311,6 +311,10 @@ callback_id = node.getAttribute("callback") ctrl = self.widget_factory.createButtonWidget(parent, value, self.onButtonPress) ctrl._xmlui_param_id = (callback_id, [field.getAttribute('name') for field in node.getElementsByTagName("field_back")]) + elif type_ == "internal_button": + action = node.getAttribute("action") + ctrl = self.widget_factory.createButtonWidget(parent, value, self.onInternalButtonPress) + ctrl._xmlui_param_id = (action, [field.getAttribute('name') for field in node.getElementsByTagName("internal_field")]) else: print(_("FIXME FIXME FIXME: widget type [%s] is not implemented") % type_) raise NotImplementedError(_("FIXME FIXME FIXME: type [%s] is not implemented") % type_) @@ -413,6 +417,39 @@ data[escaped] = ctrl['control']._xmluiGetValue() self._xmluiLaunchAction(callback_id, data) + def onInternalButtonPress(self, button): + """ Called when an internal XMLUI button is clicked + Do the processing associated to the button + @param button: the button clicked + + """ + action, fields = button._xmlui_param_id + if action not in ('copy', 'move'): + raise NotImplementedError(_("FIXME: XMLUI internal action [%s] is not implemented") % action) + source = None + for field in fields: + widget = self.ctrl_list[field]['control'] + if not source: + source = widget + continue + if isinstance(widget, ListWidget): + if isinstance(source, ListWidget): + values = source._xmluiGetSelectedValues() + else: + values = [source._xmluiGetValue()] + if action == 'move': + source._xmluiSetValue('') + widget._xmluiAddValues(values, select=True) + else: + if isinstance(source, ListWidget): + value = u', '.join(source._xmluiGetSelectedValues()) + else: + value = source._xmluiGetValue() + if action == 'move': + source._xmluiSetValue('') + widget._xmluiSetValue(value) + source = None + def onFormSubmitted(self, ignore=None): """ An XMLUI form has been submited call the submit action associated with this form