Mercurial > libervia-backend
annotate 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 |
rev | line source |
---|---|
0 | 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 | |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
26 from xml.dom import minidom |
0 | 27 from logging import debug, info, error |
28 | |
29 | |
30 class Param(wx.Frame): | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
31 def __init__(self, host, title="Configuration"): |
0 | 32 super(Param, self).__init__(None, title=title) |
33 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
34 self.host = host |
0 | 35 |
36 self.modified={} # dict of modified data (i.e. what we have to save) | |
37 | |
38 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
39 self.notebook=wx.Notebook(self, -1, style=wx.NB_LEFT) | |
40 self.sizer.Add(self.notebook, 1, flag=wx.EXPAND) | |
41 self.SetSizer(self.sizer) | |
42 self.SetAutoLayout(True) | |
43 | |
44 #events | |
45 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
46 | |
47 self.MakeModal() | |
48 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
49 for category in self.host.bridge.getParamsCategories(): |
0 | 50 self.addCategory(category) |
51 | |
52 self.Show() | |
53 | |
54 def addCategory(self, category): | |
55 panel=wx.Panel(self.notebook) | |
56 panel.sizer = wx.BoxSizer(wx.VERTICAL) | |
57 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
58 cat_dom = minidom.parseString(self.host.bridge.getParamsForCategory(category)) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
59 |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
60 for param in cat_dom.documentElement.getElementsByTagName("param"): |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
61 name = param.getAttribute("name") |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
62 type = param.getAttribute("type") |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
63 value = param.getAttribute("value") |
0 | 64 sizer = wx.BoxSizer(wx.HORIZONTAL) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
65 if type=="string": |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
66 label=wx.StaticText(panel, -1, name+" ") |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
67 ctrl = wx.TextCtrl(panel, -1, value) |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
68 sizer.Add(label) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
69 elif type=="password": |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
70 label=wx.StaticText(panel, -1, name+" ") |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
71 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD) |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
72 sizer.Add(label) |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
73 elif type=="button": |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
74 ctrl = wx.Button(panel, -1, value) |
0 | 75 else: |
76 error("FIXME FIXME FIXME") #FIXME ! | |
77 raise NotImplementedError | |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
78 ctrl.param_id=(name, category) |
0 | 79 sizer.Add(ctrl, 1, flag=wx.EXPAND) |
80 panel.sizer.Add(sizer, flag=wx.EXPAND) | |
81 | |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
82 if type=="string" or type=="password": |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
83 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl) |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
84 elif type=="button": |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
85 panel.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl) |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
86 |
0 | 87 panel.SetSizer(panel.sizer) |
88 panel.SetAutoLayout(True) | |
89 self.notebook.AddPage(panel, category) | |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
90 cat_dom.unlink() |
0 | 91 |
92 def onTextChanged(self, event): | |
93 """Called when a paramated is modified""" | |
94 self.modified[event.GetEventObject().param_id]=event.GetString() | |
95 event.Skip() | |
96 | |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
97 def onButtonClicked(self, event): |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
98 """Called when a paramated is modified""" |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
99 print "Button Clicked (%s/%s)" % event.GetEventObject().param_id |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
100 name, category = event.GetEventObject().param_id |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
101 data = {"name":name, "category":category} |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
102 id = self.host.bridge.launchAction("button", data) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
103 self.host.current_action_ids.add(id) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
104 print "action id:",id |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
105 event.Skip() |
0 | 106 |
107 def onClose(self, event): | |
108 """Close event: we have to save the params.""" | |
109 debug("close") | |
110 #now we save the modifier params | |
111 for param in self.modified: | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
112 self.host.bridge.setParam(param[0], self.modified[param], param[1]) |
0 | 113 |
114 self.MakeModal(False) | |
115 event.Skip() | |
116 |