Mercurial > libervia-backend
comparison frontends/wix/param.py @ 0:c4bc297b82f0
sat:
- first public release, initial commit
author | goffi@necton2 |
---|---|
date | Sat, 29 Aug 2009 13:34:59 +0200 |
parents | |
children | 6928e3cb73a8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c4bc297b82f0 |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 wix: a SAT frontend | |
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 | |
23 | |
24 import wx | |
25 import pdb | |
26 from logging import debug, info, error | |
27 | |
28 | |
29 class Param(wx.Frame): | |
30 def __init__(self, setParam, getParam, getParams, getParamsCategories, title="Configuration"): | |
31 super(Param, self).__init__(None, title=title) | |
32 | |
33 self.setParam=setParam | |
34 self.getParam=getParam | |
35 self.getParams=getParams | |
36 self.getParamsCategories=getParamsCategories | |
37 | |
38 self.modified={} # dict of modified data (i.e. what we have to save) | |
39 | |
40 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
41 self.notebook=wx.Notebook(self, -1, style=wx.NB_LEFT) | |
42 self.sizer.Add(self.notebook, 1, flag=wx.EXPAND) | |
43 self.SetSizer(self.sizer) | |
44 self.SetAutoLayout(True) | |
45 | |
46 #events | |
47 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
48 | |
49 self.MakeModal() | |
50 | |
51 for category in self.getParamsCategories(): | |
52 self.addCategory(category) | |
53 | |
54 self.Show() | |
55 | |
56 def addCategory(self, category): | |
57 panel=wx.Panel(self.notebook) | |
58 panel.sizer = wx.BoxSizer(wx.VERTICAL) | |
59 | |
60 for param in self.getParams(category): | |
61 sizer = wx.BoxSizer(wx.HORIZONTAL) | |
62 label=wx.StaticText(panel, -1, param[0]+" ") | |
63 if param[2]=="string": | |
64 ctrl = wx.TextCtrl(panel, -1, param[1]) | |
65 elif param[2]=="password": | |
66 ctrl = wx.TextCtrl(panel, -1, param[1], style=wx.TE_PASSWORD) | |
67 else: | |
68 error("FIXME FIXME FIXME") #FIXME ! | |
69 raise NotImplementedError | |
70 ctrl.param_id=(param[0], category) | |
71 sizer.Add(label) | |
72 sizer.Add(ctrl, 1, flag=wx.EXPAND) | |
73 panel.sizer.Add(sizer, flag=wx.EXPAND) | |
74 | |
75 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl) | |
76 panel.SetSizer(panel.sizer) | |
77 panel.SetAutoLayout(True) | |
78 self.notebook.AddPage(panel, category) | |
79 | |
80 def onTextChanged(self, event): | |
81 """Called when a paramated is modified""" | |
82 self.modified[event.GetEventObject().param_id]=event.GetString() | |
83 event.Skip() | |
84 | |
85 | |
86 def onClose(self, event): | |
87 """Close event: we have to save the params.""" | |
88 debug("close") | |
89 #now we save the modifier params | |
90 for param in self.modified: | |
91 self.setParam(param[0], self.modified[param], param[1]) | |
92 | |
93 self.MakeModal(False) | |
94 event.Skip() | |
95 |