annotate frontends/wix/form.py @ 62:93cb45a7420f

SàT multi-profile: connection using profiles - /!\ plugins are temporarly deactivated
author Goffi <goffi@goffi.org>
date Fri, 29 Jan 2010 13:55:41 +1100
parents a5b5fb5fc9fd
children 8f2ed279784b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
a5b5fb5fc9fd updated README and copyright note
Goffi <goffi@goffi.org>
parents: 37
diff changeset
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
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from logging import debug, info, error
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):
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
32 def __init__(self, host, target, xml_data='', title="Form", type="Form"):
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
33 super(Form, self).__init__(None, title=title)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
34
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
35 self.host = host
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
36 self.target = target
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
37 self.ctl_list = [] # usefull to access ctrl
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
38
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self.sizer = wx.BoxSizer(wx.VERTICAL)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
40 self.SetSizer(self.sizer)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
41 self.SetAutoLayout(True)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
42
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
43 #events
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.Bind(wx.EVT_CLOSE, self.onClose, self)
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 self.MakeModal()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
47
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.constructForm(xml_data)
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.Show()
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 def constructForm(self, xml_data):
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
53 panel=wx.Panel(self)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
54 panel.sizer = wx.BoxSizer(wx.VERTICAL)
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 cat_dom = minidom.parseString(xml_data.encode('utf-8'))
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
57
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
58 for elem in cat_dom.documentElement.getElementsByTagName("elem"):
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
59 name = elem.getAttribute("name")
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
60 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
61 type = elem.getAttribute("type")
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
62 value = elem.firstChild.wholeText if elem.firstChild else u'' #TODO: must check if the first child is really the text value
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
63 sizer = wx.BoxSizer(wx.HORIZONTAL)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
64 if type=="text":
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
65 ctrl = wx.StaticText(panel, -1, value)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
66 elif type=="string":
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
67 label=wx.StaticText(panel, -1, label+": ")
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
68 ctrl = wx.TextCtrl(panel, -1, value)
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
69 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
70 sizer.Add(label)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
71 elif type=="password":
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
72 label=wx.StaticText(panel, -1, label+": ")
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
73 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
74 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
75 sizer.Add(label)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
76 else:
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
77 error("FIXME FIXME FIXME: type [%s] is not implemented" % type) #FIXME !
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
78 raise NotImplementedError
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
79 sizer.Add(ctrl, 1, flag=wx.EXPAND)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
80 #self.ctl_list[(name, category)] = ctrl
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
81 panel.sizer.Add(sizer, flag=wx.EXPAND)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
82
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
83 submitButton = wx.Button(panel,wx.ID_OK, label="Submit")
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
84 cancelButton = wx.Button(panel,wx.ID_CANCEL)
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
85 dialogButtons = wx.StdDialogButtonSizer()
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
86 dialogButtons.AddButton(submitButton)
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
87 dialogButtons.AddButton(cancelButton)
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
88 dialogButtons.Realize()
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
89 panel.Bind(wx.EVT_BUTTON, self.onFormSubmitted, submitButton)
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
90 panel.Bind(wx.EVT_BUTTON, self.onFormCancelled, cancelButton)
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
91 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
92
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
93 panel.SetSizer(panel.sizer)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
94 panel.SetAutoLayout(True)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
95 panel.sizer.Fit(self)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
96 self.sizer.Add(panel, 1, flag=wx.EXPAND)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
97 cat_dom.unlink()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
98
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
99 def onFormSubmitted(self, event):
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
100 """Called when submit button is clicked"""
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
101 debug("Submitting form")
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
102 data = []
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
103 for ctrl in self.ctl_list:
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
104 data.append((ctrl["name"], ctrl["control"].GetValue()))
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
105 print "submitting:",data
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
106 id = self.host.bridge.gatewayRegister("SUBMIT",self.target, data)
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
107 self.host.current_action_ids.add(id)
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
108 print "action id:",id
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
109 self.MakeModal(False)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
110 self.Destroy()
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
111
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
112 def onFormCancelled(self, event):
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
113 """Called when cancel button is clicked"""
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
114 debug("Cancelling form")
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
115 self.MakeModal(False)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
116 self.Close()
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
117
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
118 def onClose(self, event):
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
119 """Close event: we have to send the form."""
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
120 debug("close")
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
121 self.MakeModal(False)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
122 event.Skip()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
123