From 7f612cb9e18f2a73266fe020dbbdc9208531b8d6 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sun, 8 Sep 2013 18:05:19 +0200 Subject: [PATCH] =?UTF-8?q?primitivus:=20really=20basic=20implementation?= =?UTF-8?q?=20of=20advanced=20list.=20=20=20=20=20Advanced=20list=20are=20?= =?UTF-8?q?here=20to=20allow=20complex=20lists,=20with=20columns,=20orderi?= =?UTF-8?q?ng,=20customization=20=C3=A0=20la=20amarok=202.=20This=20implem?= =?UTF-8?q?entation=20is=20just=20a=20first=20draft=20which=20show=20the?= =?UTF-8?q?=20text=20version=20of=20items=20in=20a=20List.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontends/src/primitivus/xmlui.py | 58 +++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/frontends/src/primitivus/xmlui.py b/frontends/src/primitivus/xmlui.py index 87831e6d..4e8af91c 100644 --- a/frontends/src/primitivus/xmlui.py +++ b/frontends/src/primitivus/xmlui.py @@ -22,6 +22,18 @@ from urwid_satext import sat_widgets from logging import debug, info, warning, error from xml.dom import minidom +def getText(node): + """Get child text nodes + @param node: dom Node + @return: joined unicode text of all nodes + + """ + data = [] + for child in node.childNodes: + if child.nodeType == child.TEXT_NODE: + data.append(child.wholeText) + return u"".join(data) + class Pairs(urwid.WidgetWrap): def __init__(self, weight_0='1', weight_1='1'): @@ -64,42 +76,46 @@ class XMLUI(urwid.WidgetWrap): message=_("Unmanaged tag") error(message) raise Exception(message) - id = elem.getAttribute("id") + id_ = elem.getAttribute("id") name = elem.getAttribute("name") - type = elem.getAttribute("type") + type_ = elem.getAttribute("type") value = elem.getAttribute("value") if elem.hasAttribute('value') else u'' - if type=="empty": + if type_=="empty": ctrl = urwid.Text('') - elif type=="text": + elif type_=="text": try: value = elem.childNodes[0].wholeText except IndexError: warning (_("text node has no child !")) ctrl = urwid.Text(value) - elif type=="label": + elif type_=="label": ctrl = urwid.Text(value+": ") - elif type=="string": + elif type_=="string": ctrl = sat_widgets.AdvancedEdit(edit_text = value) - self.ctrl_list[name] = ({'type':type, 'control':ctrl}) - elif type=="password": + self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) + elif type_=="password": ctrl = sat_widgets.Password(edit_text = value) - self.ctrl_list[name] = ({'type':type, 'control':ctrl}) - elif type=="textbox": + self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) + elif type_=="textbox": ctrl = sat_widgets.AdvancedEdit(edit_text = value, multiline=True) - self.ctrl_list[name] = ({'type':type, 'control':ctrl}) - elif type=="bool": + 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": + self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) + elif type_=="list": style=[] if elem.getAttribute("multi")=='yes' else ['single'] ctrl = sat_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style) - self.ctrl_list[name] = ({'type':type, 'control':ctrl}) - elif type=="button": + self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) + elif type_=="button": callback_id = elem.getAttribute("callback_id") ctrl = sat_widgets.CustomButton(value, on_press=self.onButtonPress) ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")]) + elif type_=="advanced_list": + ctrl = sat_widgets.List(options=[getText(txt_elt) for txt_elt in elem.getElementsByTagName("text")], style=['can_select_none'], max_height=20) + + self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) else: - error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME ! + error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type_) #FIXME ! raise NotImplementedError if self.type == 'param': if isinstance(ctrl,urwid.Edit) or isinstance(ctrl,urwid.CheckBox): @@ -236,8 +252,12 @@ class XMLUI(urwid.WidgetWrap): if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned raise NotImplementedError self.host.debug() - elif self.misc.has_key('callback'): - self.misc['callback'](data) + elif 'callback' in self.misc: + try: + self.misc['callback'](data, *self.misc['callback_args']) + except KeyError: + self.misc['callback'](data) + else: warning (_("The form data is not sent back, the type is not managed properly")) self.host.removePopUp()