Mercurial > libervia-backend
annotate frontends/wix/param.py @ 30:d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
- wix: register in gateways manager now call the in-band registration process
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 08 Dec 2009 04:19:41 +0100 |
parents | 925ab466c5ec |
children | a544b376b6f0 |
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 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
28 from tools.jid import JID |
0 | 29 |
30 | |
31 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
|
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 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
21
diff
changeset
|
60 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
|
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") |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
64 type = param.getAttribute("type") |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
65 value = param.getAttribute("value") |
0 | 66 sizer = wx.BoxSizer(wx.HORIZONTAL) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
67 if type=="string": |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
68 label=wx.StaticText(panel, -1, name+" ") |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
69 ctrl = wx.TextCtrl(panel, -1, value) |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
70 sizer.Add(label) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
71 elif type=="password": |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
72 label=wx.StaticText(panel, -1, name+" ") |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
73 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
|
74 sizer.Add(label) |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
75 elif type=="button": |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
76 ctrl = wx.Button(panel, -1, value) |
0 | 77 else: |
78 error("FIXME FIXME FIXME") #FIXME ! | |
79 raise NotImplementedError | |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
80 ctrl.param_id=(name, category) |
0 | 81 sizer.Add(ctrl, 1, flag=wx.EXPAND) |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
82 self.ctl_list[(name, category)] = ctrl |
0 | 83 panel.sizer.Add(sizer, flag=wx.EXPAND) |
84 | |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
85 if type=="string" or type=="password": |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
86 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl) |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
87 elif type=="button": |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
88 panel.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl) |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
89 |
0 | 90 panel.SetSizer(panel.sizer) |
91 panel.SetAutoLayout(True) | |
92 self.notebook.AddPage(panel, category) | |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
93 cat_dom.unlink() |
0 | 94 |
95 def onTextChanged(self, event): | |
96 """Called when a paramated is modified""" | |
97 self.modified[event.GetEventObject().param_id]=event.GetString() | |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
98 |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
99 ### 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
|
100 if event.GetEventObject().param_id == ('JabberID', 'Connection'): |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
101 domain = JID(event.GetString()).domain |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
102 self.ctl_list[('Server', 'Connection')].SetValue(domain) |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
103 self.modified[('Server', 'Connection')] = domain |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
104 |
0 | 105 event.Skip() |
106 | |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
107 def onButtonClicked(self, event): |
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
108 """Called when a paramated is modified""" |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 print "action id:",id |
21
633c5ed65701
parameters: new button type (not finished)
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
116 event.Skip() |
0 | 117 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
118 def __save_parameters(self): |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
119 for param in self.modified: |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
120 self.host.bridge.setParam(param[0], self.modified[param], param[1]) |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
121 self.modified.clear() |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
122 |
0 | 123 def onClose(self, event): |
124 """Close event: we have to save the params.""" | |
125 debug("close") | |
126 #now we save the modifier params | |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
127 self.__save_parameters() |
0 | 128 |
129 self.MakeModal(False) | |
130 event.Skip() | |
131 |