annotate frontends/wix/param.py @ 16:0a024d5e0cd0

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