annotate frontends/src/wix/param.py @ 598:af900f49df89

misc: add ctags_links to .hgignore
author Goffi <goffi@goffi.org>
date Wed, 20 Feb 2013 20:08:15 +0100
parents 952322b1d490
children 84a6e83157c2
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
572
ca13633d3b6b dates update
Goffi <goffi@goffi.org>
parents: 545
diff changeset
6 Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
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
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
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
goffi@necton2
parents:
diff changeset
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
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
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 0
diff changeset
26 from xml.dom import minidom
0
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
29
goffi@necton2
parents:
diff changeset
30
goffi@necton2
parents:
diff changeset
31 class Param(wx.Frame):
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
32 def __init__(self, host, title=_("Configuration")):
0
goffi@necton2
parents:
diff changeset
33 super(Param, self).__init__(None, title=title)
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
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)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
45
0
goffi@necton2
parents:
diff changeset
46 #events
goffi@necton2
parents:
diff changeset
47 self.Bind(wx.EVT_CLOSE, self.onClose, self)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
48
0
goffi@necton2
parents:
diff changeset
49 self.MakeModal()
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
52 self.addCategory(category)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
53
0
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
545
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
60 def errorGettingParams(ignore):
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
61 wx.MessageDialog(self, _("Can't get parameters"), _("Parameters error"), wx.ICON_ERROR).ShowModal()
0
goffi@necton2
parents:
diff changeset
62
545
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
63 def gotParams(result):
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
64 cat_dom = minidom.parseString(result.encode('utf-8'))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
65
545
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
66 for param in cat_dom.documentElement.getElementsByTagName("param"):
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
67 name = param.getAttribute("name")
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
68 label = param.getAttribute("label")
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
69 type = param.getAttribute("type")
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
70 value = param.getAttribute("value")
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
71 sizer = wx.BoxSizer(wx.HORIZONTAL)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
72 if type=="string":
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
73 label=wx.StaticText(panel, -1, (label or name)+" ")
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
74 ctrl = wx.TextCtrl(panel, -1, value)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
75 sizer.Add(label)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
76 elif type=="password":
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
77 label=wx.StaticText(panel, -1, (label or name)+" ")
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
78 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
79 sizer.Add(label)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
80 elif type=="bool":
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
81 ctrl = wx.CheckBox(panel, -1, label or name, style = wx.CHK_2STATE)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
82 ctrl.SetValue(value=="true")
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
83 elif type=="button":
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
84 ctrl = wx.Button(panel, -1, value)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
85 ctrl.callback_id = param.getAttribute("callback_id")
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
86 else:
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
87 error(_("FIXME FIXME FIXME")) #FIXME !
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
88 raise NotImplementedError
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
89 if name:
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
90 ctrl.param_id=(name, category)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
91 self.ctl_list[(name, category)] = ctrl
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
92 sizer.Add(ctrl, 1, flag=wx.EXPAND)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
93 panel.sizer.Add(sizer, flag=wx.EXPAND)
21
633c5ed65701 parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
94
545
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
95 if type=="string" or type=="password":
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
96 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
97 elif type=="bool":
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
98 panel.Bind(wx.EVT_CHECKBOX, self.onCheckBoxClicked, ctrl)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
99 elif type=="button":
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
100 panel.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
101
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
102 panel.SetSizer(panel.sizer)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
103 panel.SetAutoLayout(True)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
104 self.notebook.AddPage(panel, category)
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
105 cat_dom.unlink()
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
106
8f88ae7ed886 wix: fixed parameters management
Goffi <goffi@goffi.org>
parents: 480
diff changeset
107 self.host.bridge.getParamsForCategory(category, profile_key = self.host.profile, callback = gotParams, errback = errorGettingParams)
0
goffi@necton2
parents:
diff changeset
108
goffi@necton2
parents:
diff changeset
109 def onTextChanged(self, event):
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 135
diff changeset
110 """Called when a string paramater is modified"""
0
goffi@necton2
parents:
diff changeset
111 self.modified[event.GetEventObject().param_id]=event.GetString()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
112
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
113 ### 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
114 if event.GetEventObject().param_id == ('JabberID', 'Connection'):
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
115 domain = JID(event.GetString()).domain
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
116 self.ctl_list[('Server', 'Connection')].SetValue(domain)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
117 self.modified[('Server', 'Connection')] = domain
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
118
0
goffi@necton2
parents:
diff changeset
119 event.Skip()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
120
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 135
diff changeset
121 def onCheckBoxClicked(self, event):
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 135
diff changeset
122 """Called when a bool paramater is modified"""
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 135
diff changeset
123 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
124 event.Skip()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
125
21
633c5ed65701 parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
126 def onButtonClicked(self, event):
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 135
diff changeset
127 """Called when a button paramater is modified"""
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
128 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
129 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
130 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
131 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
132 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
133 self.host.current_action_ids.add(id)
21
633c5ed65701 parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents: 18
diff changeset
134 event.Skip()
0
goffi@necton2
parents:
diff changeset
135
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
136 def __save_parameters(self):
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
137 for param in self.modified:
89
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 70
diff changeset
138 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
139 self.modified.clear()
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
140
0
goffi@necton2
parents:
diff changeset
141 def onClose(self, event):
goffi@necton2
parents:
diff changeset
142 """Close event: we have to save the params."""
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
143 debug(_("close"))
0
goffi@necton2
parents:
diff changeset
144 #now we save the modifier params
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
145 self.__save_parameters()
0
goffi@necton2
parents:
diff changeset
146
goffi@necton2
parents:
diff changeset
147 self.MakeModal(False)
goffi@necton2
parents:
diff changeset
148 event.Skip()
goffi@necton2
parents:
diff changeset
149