Mercurial > libervia-backend
annotate frontends/src/wix/param.py @ 622:9a8fbf0e8691
pluging maildir: some trivial fixes:
- path is now (local dir)/maildir/(profile name) instead of directly (profile name)
- removed forgotten breakpoint
- use of MaildirError instead of the inexistant MailboxException
- fixed some forgotten "self."
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 20 Jun 2013 12:37:06 +0200 |
parents | 84a6e83157c2 |
children | ca2cae6b2c6d |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
4 # wix: a SAT frontend |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
0 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
10 # (at your option) any later version. |
0 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
15 # GNU Affero General Public License for more details. |
0 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
20 | |
21 | |
22 import wx | |
23 import pdb | |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
24 from xml.dom import minidom |
0 | 25 from logging import debug, info, error |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
26 from sat.tools.jid import JID |
0 | 27 |
28 | |
29 class Param(wx.Frame): | |
70 | 30 def __init__(self, host, title=_("Configuration")): |
0 | 31 super(Param, self).__init__(None, title=title) |
32 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
33 self.host = host |
0 | 34 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
35 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
|
36 self.ctl_list = {} # usefull to access ctrl, key = (name, category) |
0 | 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) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
43 |
0 | 44 #events |
45 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
46 |
0 | 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) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
51 |
0 | 52 self.Show() |
53 | |
54 def addCategory(self, category): | |
55 panel=wx.Panel(self.notebook) | |
56 panel.sizer = wx.BoxSizer(wx.VERTICAL) | |
57 | |
545 | 58 def errorGettingParams(ignore): |
59 wx.MessageDialog(self, _("Can't get parameters"), _("Parameters error"), wx.ICON_ERROR).ShowModal() | |
0 | 60 |
545 | 61 def gotParams(result): |
62 cat_dom = minidom.parseString(result.encode('utf-8')) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
63 |
545 | 64 for param in cat_dom.documentElement.getElementsByTagName("param"): |
65 name = param.getAttribute("name") | |
66 label = param.getAttribute("label") | |
67 type = param.getAttribute("type") | |
68 value = param.getAttribute("value") | |
69 sizer = wx.BoxSizer(wx.HORIZONTAL) | |
70 if type=="string": | |
71 label=wx.StaticText(panel, -1, (label or name)+" ") | |
72 ctrl = wx.TextCtrl(panel, -1, value) | |
73 sizer.Add(label) | |
74 elif type=="password": | |
75 label=wx.StaticText(panel, -1, (label or name)+" ") | |
76 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD) | |
77 sizer.Add(label) | |
78 elif type=="bool": | |
79 ctrl = wx.CheckBox(panel, -1, label or name, style = wx.CHK_2STATE) | |
80 ctrl.SetValue(value=="true") | |
81 elif type=="button": | |
82 ctrl = wx.Button(panel, -1, value) | |
83 ctrl.callback_id = param.getAttribute("callback_id") | |
84 else: | |
85 error(_("FIXME FIXME FIXME")) #FIXME ! | |
86 raise NotImplementedError | |
87 if name: | |
88 ctrl.param_id=(name, category) | |
89 self.ctl_list[(name, category)] = ctrl | |
90 sizer.Add(ctrl, 1, flag=wx.EXPAND) | |
91 panel.sizer.Add(sizer, flag=wx.EXPAND) | |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
92 |
545 | 93 if type=="string" or type=="password": |
94 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl) | |
95 elif type=="bool": | |
96 panel.Bind(wx.EVT_CHECKBOX, self.onCheckBoxClicked, ctrl) | |
97 elif type=="button": | |
98 panel.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl) | |
99 | |
100 panel.SetSizer(panel.sizer) | |
101 panel.SetAutoLayout(True) | |
102 self.notebook.AddPage(panel, category) | |
103 cat_dom.unlink() | |
104 | |
105 self.host.bridge.getParamsForCategory(category, profile_key = self.host.profile, callback = gotParams, errback = errorGettingParams) | |
0 | 106 |
107 def onTextChanged(self, event): | |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
108 """Called when a string paramater is modified""" |
0 | 109 self.modified[event.GetEventObject().param_id]=event.GetString() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
110 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
111 ### 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
|
112 if event.GetEventObject().param_id == ('JabberID', 'Connection'): |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
113 domain = JID(event.GetString()).domain |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
114 self.ctl_list[('Server', 'Connection')].SetValue(domain) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
115 self.modified[('Server', 'Connection')] = domain |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
116 |
0 | 117 event.Skip() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
118 |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
119 def onCheckBoxClicked(self, event): |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
120 """Called when a bool paramater is modified""" |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
121 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
|
122 event.Skip() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
123 |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
124 def onButtonClicked(self, event): |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
135
diff
changeset
|
125 """Called when a button paramater is modified""" |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 self.host.current_action_ids.add(id) |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
132 event.Skip() |
0 | 133 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
134 def __save_parameters(self): |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
135 for param in self.modified: |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
70
diff
changeset
|
136 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
|
137 self.modified.clear() |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
138 |
0 | 139 def onClose(self, event): |
140 """Close event: we have to save the params.""" | |
70 | 141 debug(_("close")) |
0 | 142 #now we save the modifier params |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
143 self.__save_parameters() |
0 | 144 |
145 self.MakeModal(False) | |
146 event.Skip() | |
147 |