Mercurial > libervia-backend
annotate frontends/wix/form.py @ 91:39c672544593
Tarot: bidding phase
- quick_app: command line is now parsed, "profile" option allow to select it
- xml_tools: list-single is now managed
- plugin tarot: method and signal to manage contract (contrat): tarotChooseContrat & tarotGameContratChoosed
- wix: Q&D Form hack to manage more generic form (not only registration), used to show contract selection form
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 27 May 2010 19:26:19 +0930 |
parents | 8f2ed279784b |
children | 2503de7fb4c7 |
rev | line source |
---|---|
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 wix: a SAT frontend |
57 | 6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 it under the terms of the GNU General Public License as published by |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GNU General Public License for more details. |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU General Public License |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 import wx |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 import pdb |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from xml.dom import minidom |
91 | 27 from logging import debug, info, warning, error |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from tools.jid import JID |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 class Form(wx.Frame): |
91 | 32 """Create a form from a SàT xml""" |
33 | |
34 def __init__(self, host, xml_data='', title="Form", options=[], misc={}): | |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 super(Form, self).__init__(None, title=title) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 self.host = host |
91 | 38 self.options = options |
39 self.misc = misc | |
36 | 40 self.ctl_list = [] # usefull to access ctrl |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 self.sizer = wx.BoxSizer(wx.VERTICAL) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 self.SetSizer(self.sizer) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 self.SetAutoLayout(True) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 #events |
91 | 47 if not 'NO_CANCEL' in self.options: |
48 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 self.MakeModal() |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 self.constructForm(xml_data) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 self.Show() |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 def constructForm(self, xml_data): |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 panel=wx.Panel(self) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 panel.sizer = wx.BoxSizer(wx.VERTICAL) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 cat_dom = minidom.parseString(xml_data.encode('utf-8')) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 for elem in cat_dom.documentElement.getElementsByTagName("elem"): |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 name = elem.getAttribute("name") |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 label = elem.getAttribute("label") if elem.hasAttribute('label') else name |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 type = elem.getAttribute("type") |
91 | 66 value = elem.getAttribute("value") if elem.hasAttribute('value') else u'' |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 sizer = wx.BoxSizer(wx.HORIZONTAL) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 if type=="text": |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 ctrl = wx.StaticText(panel, -1, value) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 elif type=="string": |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 label=wx.StaticText(panel, -1, label+": ") |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 ctrl = wx.TextCtrl(panel, -1, value) |
36 | 73 self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 sizer.Add(label) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 elif type=="password": |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 label=wx.StaticText(panel, -1, label+": ") |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD) |
36 | 78 self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 sizer.Add(label) |
91 | 80 elif type=="list": |
81 label=wx.StaticText(panel, -1, label+": ") | |
82 ctrl = wx.ListBox(panel, -1, choices=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=wx.LB_SINGLE) | |
83 self.ctl_list.append({'name':name, 'type':type, 'control':ctrl}) | |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 else: |
70 | 85 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME ! |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 raise NotImplementedError |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 sizer.Add(ctrl, 1, flag=wx.EXPAND) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 #self.ctl_list[(name, category)] = ctrl |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 panel.sizer.Add(sizer, flag=wx.EXPAND) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 |
36 | 91 dialogButtons = wx.StdDialogButtonSizer() |
91 | 92 submitButton = wx.Button(panel,wx.ID_OK, label=_("Submit")) |
36 | 93 dialogButtons.AddButton(submitButton) |
91 | 94 panel.Bind(wx.EVT_BUTTON, self.onFormSubmitted, submitButton) |
95 if not 'NO_CANCEL' in self.options: | |
96 cancelButton = wx.Button(panel,wx.ID_CANCEL) | |
97 dialogButtons.AddButton(cancelButton) | |
98 panel.Bind(wx.EVT_BUTTON, self.onFormCancelled, cancelButton) | |
36 | 99 dialogButtons.Realize() |
100 panel.sizer.Add(dialogButtons, flag=wx.ALIGN_CENTER_HORIZONTAL) | |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 panel.SetSizer(panel.sizer) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 panel.SetAutoLayout(True) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 panel.sizer.Fit(self) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 self.sizer.Add(panel, 1, flag=wx.EXPAND) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 cat_dom.unlink() |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 |
36 | 108 def onFormSubmitted(self, event): |
109 """Called when submit button is clicked""" | |
70 | 110 debug(_("Submitting form")) |
36 | 111 data = [] |
112 for ctrl in self.ctl_list: | |
91 | 113 if isinstance(ctrl['control'], wx.ListBox): |
114 data.append((ctrl['name'], ctrl['control'].GetStringSelection())) | |
115 else: | |
116 data.append((ctrl["name"], ctrl["control"].GetValue())) | |
117 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned | |
118 id = self.misc['action_back']("SUBMIT",self.misc['target'], data) | |
119 self.host.current_action_ids.add(id) | |
120 elif self.misc.has_key('callback'): | |
121 self.misc['callback'](data) | |
122 else: | |
123 warning (_("The form data is not sent back, the type is not managed properly")) | |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
124 self.MakeModal(False) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
125 self.Destroy() |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 |
36 | 127 def onFormCancelled(self, event): |
128 """Called when cancel button is clicked""" | |
70 | 129 debug(_("Cancelling form")) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
130 self.MakeModal(False) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
131 self.Close() |
36 | 132 |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 def onClose(self, event): |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 """Close event: we have to send the form.""" |
70 | 135 debug(_("close")) |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 self.MakeModal(False) |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 event.Skip() |
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |