Mercurial > libervia-backend
annotate frontends/src/wix/param.py @ 500:00d3679976ab
primitivus: keep focus position in contacts list on redraw
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 05 Sep 2012 00:19:32 +0200 |
parents | 2a072735e459 |
children | 8f88ae7ed886 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 wix: a SAT frontend | |
459 | 6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
0 | 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 | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
16 GNU Affero General Public License for more details. |
0 | 17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
0 | 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 |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
28 from sat.tools.jid import JID |
0 | 29 |
30 | |
31 class Param(wx.Frame): | |
70 | 32 def __init__(self, host, title=_("Configuration")): |
0 | 33 super(Param, self).__init__(None, title=title) |
34 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
35 self.host = host |
0 | 36 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
37 self.modified = {} # dict of modified data (i.e. what we have to save) |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
38 self.ctl_list = {} # usefull to access ctrl, key = (name, category) |
0 | 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 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
51 for category in self.host.bridge.getParamsCategories(): |
0 | 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 | |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
70
diff
changeset
|
60 cat_dom = minidom.parseString(self.host.bridge.getParamsForCategory(category, profile_key = self.host.profile).encode('utf-8')) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
61 |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
62 for param in cat_dom.documentElement.getElementsByTagName("param"): |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
63 name = param.getAttribute("name") |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
64 label = param.getAttribute("label") |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
65 type = param.getAttribute("type") |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
66 value = param.getAttribute("value") |
0 | 67 sizer = wx.BoxSizer(wx.HORIZONTAL) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
68 if type=="string": |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
69 label=wx.StaticText(panel, -1, (label or name)+" ") |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
70 ctrl = wx.TextCtrl(panel, -1, value) |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
71 sizer.Add(label) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
72 elif type=="password": |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
73 label=wx.StaticText(panel, -1, (label or name)+" ") |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
74 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
|
75 sizer.Add(label) |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
76 elif type=="bool": |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
77 ctrl = wx.CheckBox(panel, -1, label or name, style = wx.CHK_2STATE) |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
78 ctrl.SetValue(value=="true") |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
79 elif type=="button": |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
80 ctrl = wx.Button(panel, -1, value) |
135
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
81 ctrl.callback_id = param.getAttribute("callback_id") |
0 | 82 else: |
70 | 83 error(_("FIXME FIXME FIXME")) #FIXME ! |
0 | 84 raise NotImplementedError |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
85 if name: |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
86 ctrl.param_id=(name, category) |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
87 self.ctl_list[(name, category)] = ctrl |
0 | 88 sizer.Add(ctrl, 1, flag=wx.EXPAND) |
89 panel.sizer.Add(sizer, flag=wx.EXPAND) | |
90 | |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
91 if type=="string" or type=="password": |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
92 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl) |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
93 elif type=="bool": |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
94 panel.Bind(wx.EVT_CHECKBOX, self.onCheckBoxClicked, ctrl) |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
95 elif type=="button": |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
96 panel.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl) |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
97 |
0 | 98 panel.SetSizer(panel.sizer) |
99 panel.SetAutoLayout(True) | |
100 self.notebook.AddPage(panel, category) | |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
101 cat_dom.unlink() |
0 | 102 |
103 def onTextChanged(self, event): | |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
104 """Called when a string paramater is modified""" |
0 | 105 self.modified[event.GetEventObject().param_id]=event.GetString() |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
106 |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
107 ### FIXME # Some hacks for better presentation, should be generic # FIXME ### |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
108 if event.GetEventObject().param_id == ('JabberID', 'Connection'): |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
109 domain = JID(event.GetString()).domain |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
110 self.ctl_list[('Server', 'Connection')].SetValue(domain) |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
111 self.modified[('Server', 'Connection')] = domain |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
112 |
0 | 113 event.Skip() |
114 | |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
115 def onCheckBoxClicked(self, event): |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
116 """Called when a bool paramater is modified""" |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
117 self.modified[event.GetEventObject().param_id]="true" if event.GetEventObject().GetValue() else "false" |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
118 event.Skip() |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
119 |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
120 def onButtonClicked(self, event): |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
121 """Called when a button paramater is modified""" |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
122 self.__save_parameters() |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
123 name, category = event.GetEventObject().param_id |
135
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
124 callback_id = event.GetEventObject().callback_id |
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
125 data = {"name":name, "category":category, "callback_id":callback_id} |
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
126 id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
127 self.host.current_action_ids.add(id) |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
128 event.Skip() |
0 | 129 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
130 def __save_parameters(self): |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
131 for param in self.modified: |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
70
diff
changeset
|
132 self.host.bridge.setParam(param[0], self.modified[param], param[1], profile_key = self.host.profile) |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
133 self.modified.clear() |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
134 |
0 | 135 def onClose(self, event): |
136 """Close event: we have to save the params.""" | |
70 | 137 debug(_("close")) |
0 | 138 #now we save the modifier params |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
139 self.__save_parameters() |
0 | 140 |
141 self.MakeModal(False) | |
142 event.Skip() | |
143 |