Mercurial > libervia-backend
view frontends/wix/param.py @ 22:bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 01 Dec 2009 04:56:08 +0100 |
parents | 633c5ed65701 |
children | 925ab466c5ec |
line wrap: on
line source
#!/usr/bin/python # -*- coding: utf-8 -*- """ wix: a SAT frontend Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import wx import pdb from xml.dom import minidom from logging import debug, info, error class Param(wx.Frame): def __init__(self, host, title="Configuration"): super(Param, self).__init__(None, title=title) self.host = host self.modified={} # dict of modified data (i.e. what we have to save) self.sizer = wx.BoxSizer(wx.VERTICAL) self.notebook=wx.Notebook(self, -1, style=wx.NB_LEFT) self.sizer.Add(self.notebook, 1, flag=wx.EXPAND) self.SetSizer(self.sizer) self.SetAutoLayout(True) #events self.Bind(wx.EVT_CLOSE, self.onClose, self) self.MakeModal() for category in self.host.bridge.getParamsCategories(): self.addCategory(category) self.Show() def addCategory(self, category): panel=wx.Panel(self.notebook) panel.sizer = wx.BoxSizer(wx.VERTICAL) cat_dom = minidom.parseString(self.host.bridge.getParamsForCategory(category)) for param in cat_dom.documentElement.getElementsByTagName("param"): name = param.getAttribute("name") type = param.getAttribute("type") value = param.getAttribute("value") sizer = wx.BoxSizer(wx.HORIZONTAL) if type=="string": label=wx.StaticText(panel, -1, name+" ") ctrl = wx.TextCtrl(panel, -1, value) sizer.Add(label) elif type=="password": label=wx.StaticText(panel, -1, name+" ") ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD) sizer.Add(label) elif type=="button": ctrl = wx.Button(panel, -1, value) else: error("FIXME FIXME FIXME") #FIXME ! raise NotImplementedError ctrl.param_id=(name, category) sizer.Add(ctrl, 1, flag=wx.EXPAND) panel.sizer.Add(sizer, flag=wx.EXPAND) if type=="string" or type=="password": panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl) elif type=="button": panel.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl) panel.SetSizer(panel.sizer) panel.SetAutoLayout(True) self.notebook.AddPage(panel, category) cat_dom.unlink() def onTextChanged(self, event): """Called when a paramated is modified""" self.modified[event.GetEventObject().param_id]=event.GetString() event.Skip() def onButtonClicked(self, event): """Called when a paramated is modified""" print "Button Clicked (%s/%s)" % event.GetEventObject().param_id name, category = event.GetEventObject().param_id data = {"name":name, "category":category} id = self.host.bridge.launchAction("button", data) self.host.current_action_ids.add(id) print "action id:",id event.Skip() def onClose(self, event): """Close event: we have to save the params.""" debug("close") #now we save the modifier params for param in self.modified: self.host.bridge.setParam(param[0], self.modified[param], param[1]) self.MakeModal(False) event.Skip()