Mercurial > libervia-backend
diff frontends/wix/xmlui.py @ 107:5ae370c71803
CS: message sending is now working
- xmltools/xmlui: buttons can now send fields of the ui when used
- xmltools/xmlui: new textbox element, to write a large text (used for messages in CS plugin)
- xmltools/xmlui: list have now an attribute multi for selecting several options
- xmltools/xmlui: window title can now be specified in the xml (attribute title)
- CS_plugin: message sending interface & management
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 28 Jun 2010 15:18:59 +0800 |
parents | 138d82f64b6f |
children | 7452ac3818e7 |
line wrap: on
line diff
--- a/frontends/wix/xmlui.py Sat Jun 26 15:33:16 2010 +0800 +++ b/frontends/wix/xmlui.py Mon Jun 28 15:18:59 2010 +0800 @@ -38,7 +38,7 @@ self.host = host self.options = options self.misc = misc - self.ctl_list = [] # usefull to access ctrl + self.ctrl_list = {} # usefull to access ctrl self.sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.sizer) @@ -78,20 +78,25 @@ ctrl = wx.StaticText(parent, -1, value+": ") elif type=="string": ctrl = wx.TextCtrl(parent, -1, value) - self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) + self.ctrl_list[name] = ({'type':type, 'control':ctrl}) _proportion = 1 elif type=="password": ctrl = wx.TextCtrl(parent, -1, value, style=wx.TE_PASSWORD) - self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) + self.ctrl_list[name] = ({'type':type, 'control':ctrl}) + _proportion = 1 + elif type=="textbox": + ctrl = wx.TextCtrl(parent, -1, value, style=wx.TE_MULTILINE) + self.ctrl_list[name] = ({'type':type, 'control':ctrl}) _proportion = 1 elif type=="list": - 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}) + style=wx.LB_MULTIPLE if elem.getAttribute("multi")=='yes' else wx.LB_SINGLE + ctrl = wx.ListBox(parent, -1, choices=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style) + self.ctrl_list[name] = ({'type':type, 'control':ctrl}) _proportion = 1 elif type=="button": callback_id = elem.getAttribute("callback_id") ctrl = wx.Button(parent, -1, value) - ctrl.param_id = callback_id + ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")]) parent.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl) else: error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME ! @@ -155,6 +160,9 @@ cat_dom = minidom.parseString(xml_data.encode('utf-8')) top= cat_dom.documentElement self.type = top.getAttribute("type") + self.title = top .getAttribute("title") + if self.title: + self.SetTitle(self.title) if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']: raise Exception("Invalid XMLUI") #TODO: make a custom exception @@ -182,8 +190,15 @@ def onButtonClicked(self, event): """Called when a button is pushed""" - callback_id = event.GetEventObject().param_id + callback_id, fields = event.GetEventObject().param_id data = {"callback_id":callback_id} + for field in fields: + ctrl = self.ctrl_list[field] + if isinstance(ctrl['control'], wx.ListBox): + data[field] = '\t'.join([ctrl['control'].GetString(idx) for idx in ctrl['control'].GetSelections()]) + else: + data[field] = ctrl['control'].GetValue() + id = self.host.bridge.launchAction("button", data) self.host.current_action_ids.add(id) event.Skip() @@ -192,11 +207,12 @@ """Called when submit button is clicked""" debug(_("Submitting form")) data = [] - for ctrl in self.ctl_list: + for ctrl_name in self.ctrl_list: + ctrl = self.ctrl_list[ctrl_name] if isinstance(ctrl['control'], wx.ListBox): - data.append((ctrl['name'], ctrl['control'].GetStringSelection())) + data.append((ctrl_name, ctrl['control'].GetStringSelection())) else: - data.append((ctrl["name"], ctrl["control"].GetValue())) + data.append((ctrl_name, ctrl['control'].GetValue())) if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned id = self.misc['action_back']("SUBMIT",self.misc['target'], data) self.host.current_action_ids.add(id)