Mercurial > libervia-backend
changeset 152:b1f1955d96b3
Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 31 Jul 2010 00:32:51 +0800 (2010-07-30) |
parents | 7fcb4f083686 |
children | f197b52796ee |
files | frontends/primitivus/xmlui.py |
diffstat | 1 files changed, 31 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/primitivus/xmlui.py Fri Jul 30 18:43:09 2010 +0800 +++ b/frontends/primitivus/xmlui.py Sat Jul 31 00:32:51 2010 +0800 @@ -35,7 +35,7 @@ def append(self, widget): pile = self._w.widget_list[self.idx] - if pile.__class__ == urwid.Text: + if isinstance(pile, urwid.Text): self._w.widget_list[self.idx] = urwid.Pile([widget]) if self.idx == 1: self._w.set_focus(1) @@ -44,6 +44,8 @@ pile.item_types.append(('weight',getattr(self,'weight_'+str(self.idx)))) self.idx = (self.idx + 1) % 2 +class InvalidXMLUI(Exception): + pass class XMLUI(urwid.WidgetWrap): @@ -78,13 +80,13 @@ elif type=="label": ctrl = urwid.Text(value+": ") elif type=="string": - ctrl = urwid.Edit(edit_text = value) + ctrl = custom_widgets.AdvancedEdit(edit_text = value) self.ctrl_list[name] = ({'type':type, 'control':ctrl}) elif type=="password": ctrl = custom_widgets.Password(edit_text = value) self.ctrl_list[name] = ({'type':type, 'control':ctrl}) elif type=="textbox": - ctrl = urwid.Edit(edit_text = value, multiline=True) + ctrl = custom_widgets.AdvancedEdit(edit_text = value, multiline=True) self.ctrl_list[name] = ({'type':type, 'control':ctrl}) elif type=="list": style=[] if elem.getAttribute("multi")=='yes' else ['single'] @@ -92,66 +94,65 @@ self.ctrl_list[name] = ({'type':type, 'control':ctrl}) elif type=="button": callback_id = elem.getAttribute("callback_id") - ctrl = urwid.Button(value, on_press=self.onButtonPress) + ctrl = custom_widgets.CustomButton(value, on_press=self.onButtonPress) ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")]) else: error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME ! raise NotImplementedError parent.append(ctrl) - def __parseChilds(self, current, elem, wanted = ['layout']): + def __parseChilds(self, current, elem, wanted = ['layout'], data = None): """Recursively parse childNodes of an elemen @param current: widget container with 'append' method @param elem: element from which childs will be parsed @param wanted: list of tag names that can be present in the childs to be SàT XMLUI compliant""" for node in elem.childNodes: if wanted and not node.nodeName in wanted: - raise Exception("Invalid XMLUI") #TODO: make a custom exception + raise InvalidXMLUI if node.nodeName == "layout": type = node.getAttribute('type') if type == "tabs": - raise NotImplementedError - self.__parseChilds(current, None, node, ['category']) + tab_cont = custom_widgets.TabsContainer() + self.__parseChilds(current, node, ['category'], tab_cont) + current.append(tab_cont) + elif type == "vertical": + self.__parseElems(node, current) + elif type == "pairs": + pairs = Pairs() + self.__parseElems(node, pairs) + current.append(pairs) else: - if type == "vertical": - pass - elif type == "pairs": - pairs = Pairs() - current.append(pairs) - current = pairs - else: - warning(_("Unknown layout, using default one")) + warning(_("Unknown layout, using default one")) self.__parseElems(node, current) elif node.nodeName == "category": - raise NotImplementedError - """name = node.getAttribute('name') - if not node.nodeName in wanted or not name or not isinstance(parent,wx.Notebook): - raise Exception("Invalid XMLUI") #TODO: make a custom exception - notebook = parent - tab_panel = wx.Panel(notebook, -1) - tab_panel.sizer = wx.BoxSizer(wx.VERTICAL) - tab_panel.SetSizer(tab_panel.sizer) - notebook.AddPage(tab_panel, name) - self.__parseChilds(tab_panel, None, node, ['layout'])""" - + name = node.getAttribute('name') + if not name or not isinstance(data,custom_widgets.TabsContainer): + raise InvalidXMLUI + tab_cont = data + listbox = tab_cont.addTab(name) + self.__parseChilds(listbox.body, node, ['layout']) else: message=_("Unknown tag") error(message) - raise Exception(message) #TODO: raise a custom exception here + raise NotImplementedError def constructUI(self, xml_data): list_box = urwid.ListBox(urwid.SimpleListWalker([])) cat_dom = minidom.parseString(xml_data.encode('utf-8')) - top= cat_dom.documentElement + top=cat_dom.documentElement self.type = top.getAttribute("type") if not self.title: self.title = top.getAttribute("title") #TODO: manage title if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: - raise Exception("Invalid XMLUI") #TODO: make a custom exception + raise InvalidXMLUI self.__parseChilds(list_box.body, cat_dom.documentElement) + + assert list_box.body + if isinstance(list_box.body[0],custom_widgets.TabsContainer): + return list_box.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox if self.type == 'form': buttons = [] @@ -162,7 +163,6 @@ grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center') list_box.body.append(grid_wid) - return list_box def show(self):