tools, frontends (xmlui): add setter methods for widgets + new widget InternalButton to process UI operations

This commit is contained in:
souliane 2014-04-01 21:30:21 +02:00
commit 6608eafb9f
4 changed files with 119 additions and 0 deletions

View file

@ -311,6 +311,10 @@ class XMLUI(object):
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 @@ class XMLUI(object):
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