Mercurial > libervia-backend
changeset 105:d2630fba8dfd
params to XMLUI tools
- xml_tools: new paramsXml2xmlUI method, for conversion from params xml to User Interface XML
- xml_tools: new addButton method
- bridge: new method getParamsUI
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 23 Jun 2010 17:26:21 +0800 |
parents | 5458ac1380cc |
children | 138d82f64b6f |
files | frontends/sat_bridge_frontend/DBus.py frontends/wix/main_window.py frontends/wix/xmlui.py sat.tac sat_bridge/DBus.py tools/memory.py tools/xml_tools.py |
diffstat | 7 files changed, 80 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/sat_bridge_frontend/DBus.py Wed Jun 23 14:55:04 2010 +0800 +++ b/frontends/sat_bridge_frontend/DBus.py Wed Jun 23 17:26:21 2010 +0800 @@ -85,6 +85,9 @@ def getParamA(self, name, category, profile_key='@DEFAULT@'): return self.db_comm_iface.getParamA(name, category, profile_key) + def getParamsUI(self, profile_key='@DEFAULT@'): + return self.db_comm_iface.getParamsUI(profile_key) + def getParams(self, profile_key='@DEFAULT@'): return self.db_comm_iface.getParams(profile_key)
--- a/frontends/wix/main_window.py Wed Jun 23 14:55:04 2010 +0800 +++ b/frontends/wix/main_window.py Wed Jun 23 17:26:21 2010 +0800 @@ -372,6 +372,8 @@ def onParam(self, e): debug(_("Param request")) + #xmlui = self.bridge.getParamsUI(self.profile) + #XMLUI(self, xml_data = xmlui) param=Param(self) def onExit(self, e):
--- a/frontends/wix/xmlui.py Wed Jun 23 14:55:04 2010 +0800 +++ b/frontends/wix/xmlui.py Wed Jun 23 17:26:21 2010 +0800 @@ -87,6 +87,8 @@ ctrl = wx.ListBox(parent, -1, choices=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=wx.LB_SINGLE) self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) _proportion = 1 + elif type=="button": + pass else: error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME ! raise NotImplementedError @@ -102,10 +104,12 @@ if wanted and not node.nodeName in wanted: raise Exception("Invalid XMLUI") #TODO: make a custom exception if node.nodeName == "layout": + _proportion = 0 type = node.getAttribute('type') if type == "tabs": current = wx.Notebook(parent, -1, style=wx.NB_LEFT if self.type=='param' else 0) self.__parseChilds(current, None, node, ['category']) + _proportion = 1 else: if current_param == None: current = wx.Panel(parent, -1) @@ -122,7 +126,7 @@ current.SetSizer(current.sizer) self.__parseElems(node, current) if parent: - parent.sizer.Add(current, flag=wx.EXPAND) + parent.sizer.Add(current, _proportion, flag=wx.EXPAND) elif node.nodeName == "category": name = node.getAttribute('name') if not node.nodeName in wanted or not name or not isinstance(parent,wx.Notebook):
--- a/sat.tac Wed Jun 23 14:55:04 2010 +0800 +++ b/sat.tac Wed Jun 23 17:26:21 2010 +0800 @@ -346,6 +346,7 @@ self.bridge.register("sendMessage", self.sendMessage) self.bridge.register("setParam", self.setParam) self.bridge.register("getParamA", self.memory.getParamA) + self.bridge.register("getParamsUI", self.memory.getParamsUI) self.bridge.register("getParams", self.memory.getParams) self.bridge.register("getParamsForCategory", self.memory.getParamsForCategory) self.bridge.register("getParamsCategories", self.memory.getParamsCategories)
--- a/sat_bridge/DBus.py Wed Jun 23 14:55:04 2010 +0800 +++ b/sat_bridge/DBus.py Wed Jun 23 17:26:21 2010 +0800 @@ -197,6 +197,12 @@ def getParamA(self, name, category="default", profile_key='@DEFAULT@'): return self.cb["getParamA"](name, category, profile_key = profile_key) + + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, + in_signature='s', out_signature='s') + def getParamsUI(self, profile_key='@DEFAULT@'): + return self.cb["getParamsUI"](profile_key) + @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, in_signature='s', out_signature='s') def getParams(self, profile_key='@DEFAULT@'):
--- a/tools/memory.py Wed Jun 23 14:55:04 2010 +0800 +++ b/tools/memory.py Wed Jun 23 17:26:21 2010 +0800 @@ -29,6 +29,7 @@ import pdb from twisted.internet import defer from twisted.words.protocols.jabber import jid +from tools.xml_tools import paramsXml2xmlUI SAVEFILE_PARAM_XML="/param" #xml parameters template SAVEFILE_PARAM_DATA="/param" #individual & general parameters; _ind and _gen suffixes will be added @@ -281,6 +282,14 @@ return prof_xml + def getParamsUI(self, profile_key='@DEFAULT'): + """Return a SàT XMLUI for parameters, with given profile""" + profile = self.getProfileName(profile_key) + if not profile: + error(_("Asking params for inexistant profile")) + return "" + param_xml = self.getParams(profile) + return paramsXml2xmlUI(param_xml) def getParams(self, profile_key='@DEFAULT@'): """Construct xml for asked profile @@ -618,8 +627,11 @@ def getParamA(self, name, category, attr="value", profile_key="@DEFAULT@"): return self.params.getParamA(name, category, attr, profile_key) - def getParams(self): - return self.params.getParams() + def getParamsUI(self, profile_key='@DEFAULT@'): + return self.params.getParamsUI(profile_key) + + def getParams(self, profile_key='@DEFAULT@'): + return self.params.getParams(profile_key) def getParamsForCategory(self, category, profile_key='@DEFAULT@'): return self.params.getParamsForCategory(category, profile_key)
--- a/tools/xml_tools.py Wed Jun 23 14:55:04 2010 +0800 +++ b/tools/xml_tools.py Wed Jun 23 17:26:21 2010 +0800 @@ -30,13 +30,12 @@ def dataForm2xml(form): """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml""" - form_panel = XMLUI("form", "vertical") - + form_ui = XMLUI("form", "vertical") if form.instructions: - form_panel.addText('\n'.join(form.instructions), 'instructions') + form_ui.addText('\n'.join(form.instructions), 'instructions') - form_panel.changeLayout("pairs") + form_ui.changeLayout("pairs") for field in form.fieldList: if field.fieldType == 'fixed': @@ -52,12 +51,12 @@ __field_type = "string" if field.label: - form_panel.addLabel(field.label) + form_ui.addLabel(field.label) else: - form_panel.addEmpty() + form_ui.addEmpty() - elem = form_panel.addElement(__field_type, field.var, None, field.value, [option.value for option in field.options]) - return form_panel.toXml() + elem = form_ui.addElement(__field_type, field.var, None, field.value, [option.value for option in field.options]) + return form_ui.toXml() def tupleList2dataForm(values): """convert a list of tuples (name,value) to a wokkel submit data form""" @@ -68,6 +67,36 @@ return form +def paramsXml2xmlUI(xml): + """Convert the xml for parameter to a SàT XML User Interface""" + params_doc = minidom.parseString(xml) + top = params_doc.documentElement + if top.nodeName != 'params': + error(_('INTERNAL ERROR: parameters xml not valid')) + assert(False) + param_ui = XMLUI("param", "tabs") + for category in top.getElementsByTagName("category"): + name = category.getAttribute('name') + if not name: + error(_('INTERNAL ERROR: params categories must have a name')) + assert(False) + param_ui.addCategory(name, 'pairs') + for param in category.getElementsByTagName("param"): + name = param.getAttribute('name') + if not name: + error(_('INTERNAL ERROR: params must have a name')) + assert(False) + type = param.getAttribute('type') + value = param.getAttribute('value') or None + callback = param.getAttribute('callback') or None + param_ui.addLabel(name) + param_ui.addElement(name=name, type=type, value=value, callback=callback) + + return param_ui.toXml() + + + + class XMLUI: """This class is used to create a user interface (form/window/parameters/etc) using SàT XML""" @@ -170,8 +199,16 @@ self.addOptions(options, elem) if value: elem.setAttribute('value', value) + + def addButton(self, callback, name): + """Add a button + @param callback: callback which will be called if button is pressed + @param name: name shown on the button""" + elem = self.__createElem('button', name, self.currentLayout) + elem.setAttribute('callback', callback) + - def addElement(self, type, name = None, content = None, value = None, options = None): + def addElement(self, type, name = None, content = None, value = None, options = None, callback = None): """Convenience method to add element, the params correspond to the ones in addSomething methods""" if type == 'empty': self.addEmpty(name) @@ -186,6 +223,9 @@ self.addPassword(name, value) elif type == 'list': self.addList(options, name, value) + elif type == 'button': + assert(callback and name) + self.addButton(callback, name) def addOptions(self, options, parent): """Add options to a multi-values element (e.g. list)