annotate frontends/src/wix/xmlui.py @ 484:23cbdf0a0777

core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
author Goffi <goffi@goffi.org>
date Wed, 15 Aug 2012 15:50:46 +0200
parents 2a072735e459
children 1d58758689e9
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
459
cf005701624b copyleft date update
Goffi <goffi@goffi.org>
parents: 228
diff changeset
6 Copyright (C) 2009, 2010, 2011, 2012 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
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
35
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
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.
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
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
35
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
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
27 from logging import debug, info, warning, error
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
28 from sat.tools.jid import JID
35
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
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
31 class XMLUI(wx.Frame):
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
32 """Create an user interface from a SàT xml"""
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
33
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
34 def __init__(self, host, xml_data='', title="Form", options=[], misc={}):
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
35 style = wx.DEFAULT_FRAME_STYLE & ~wx.CLOSE_BOX if 'NO_CANCEL' in options else wx.DEFAULT_FRAME_STYLE #FIXME: gof: Q&D tmp hack
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
36 super(XMLUI, self).__init__(None, title=title, style=style)
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
37
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.host = host
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
39 self.options = options
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
40 self.misc = misc
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
41 self.ctrl_list = {} # usefull to access ctrl
35
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 self.sizer = wx.BoxSizer(wx.VERTICAL)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.SetSizer(self.sizer)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.SetAutoLayout(True)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
46
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
47 #events
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
48 if not 'NO_CANCEL' in self.options:
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
49 self.Bind(wx.EVT_CLOSE, self.onClose, self)
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
50
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.MakeModal()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
52
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
53 self.constructUI(xml_data)
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
54
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.Show()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
56
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
57 def __parseElems(self, node, parent):
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
58 """Parse elements inside a <layout> tags, and add them to the parent sizer"""
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
59 for elem in node.childNodes:
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
60 if elem.nodeName != "elem":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
61 message=_("Unmanaged tag")
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
62 error(message)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
63 raise Exception(message)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
64 _proportion = 0
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
65 id = elem.getAttribute("id")
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
66 name = elem.getAttribute("name")
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
67 type = elem.getAttribute("type")
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
68 value = elem.getAttribute("value") if elem.hasAttribute('value') else u''
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
69 if type=="empty":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
70 ctrl = wx.Window(parent, -1)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
71 elif type=="text":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
72 try:
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
73 value = elem.childNodes[0].wholeText
149
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 135
diff changeset
74 except IndexError:
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
75 warning (_("text node has no child !"))
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
76 ctrl = wx.StaticText(parent, -1, value)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
77 elif type=="label":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
78 ctrl = wx.StaticText(parent, -1, value+": ")
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
79 elif type=="string":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
80 ctrl = wx.TextCtrl(parent, -1, value)
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
81 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
82 _proportion = 1
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
83 elif type=="password":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
84 ctrl = wx.TextCtrl(parent, -1, value, style=wx.TE_PASSWORD)
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
85 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
86 _proportion = 1
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
87 elif type=="textbox":
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
88 ctrl = wx.TextCtrl(parent, -1, value, style=wx.TE_MULTILINE)
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
89 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
90 _proportion = 1
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
91 elif type=="bool":
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
92 ctrl = wx.CheckBox(panel, -1, "", style = wx.CHK_2STATE)
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
93 ctrl.SetValue(value=="true")
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
94 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
95 _proportion = 1
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
96 elif type=="list":
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
97 style=wx.LB_MULTIPLE if elem.getAttribute("multi")=='yes' else wx.LB_SINGLE
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
98 ctrl = wx.ListBox(parent, -1, choices=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style)
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
99 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
100 _proportion = 1
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
101 elif type=="button":
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
102 callback_id = elem.getAttribute("callback_id")
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
103 ctrl = wx.Button(parent, -1, value)
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
104 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")])
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
105 parent.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
106 else:
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
107 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME !
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
108 raise NotImplementedError
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
109 parent.sizer.Add(ctrl, _proportion, flag=wx.EXPAND)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
110
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
111 def __parseChilds(self, parent, current_param, elem, wanted = ['layout']):
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
112 """Recursively parse childNodes of an elemen
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
113 @param parent: parent wx.Window
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
114 @param current_param: current wx.Window (often wx.Panel) or None if we must create one
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
115 @param elem: element from which childs will be parsed
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
116 @param wanted: list of tag names that can be present in the childs to be SàT XMLUI compliant"""
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
117 for node in elem.childNodes:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
118 if wanted and not node.nodeName in wanted:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
119 raise Exception("Invalid XMLUI") #TODO: make a custom exception
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
120 if node.nodeName == "layout":
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
121 _proportion = 0
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
122 type = node.getAttribute('type')
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
123 if type == "tabs":
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
124 current = wx.Notebook(parent, -1, style=wx.NB_LEFT if self.type=='param' else 0)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
125 self.__parseChilds(current, None, node, ['category'])
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
126 _proportion = 1
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
127 else:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
128 if current_param == None:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
129 current = wx.Panel(parent, -1)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
130 else:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
131 current = current_param
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
132 if type == "vertical":
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
133 current.sizer = wx.BoxSizer(wx.VERTICAL)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
134 elif type == "pairs":
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
135 current.sizer = wx.FlexGridSizer(cols=2)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
136 current.sizer.AddGrowableCol(1) #The growable column need most of time to be the right one in pairs
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
137 else:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
138 warning(_("Unknown layout, using default one"))
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
139 current.sizer = wx.BoxSizer(wx.VERTICAL)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
140 current.SetSizer(current.sizer)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
141 self.__parseElems(node, current)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
142 if parent:
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
143 parent.sizer.Add(current, _proportion, flag=wx.EXPAND)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
144 elif node.nodeName == "category":
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
145 name = node.getAttribute('name')
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
146 label = node.getAttribute('label')
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
147 if not node.nodeName in wanted or not name or not isinstance(parent,wx.Notebook):
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
148 raise Exception("Invalid XMLUI") #TODO: make a custom exception
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
149 notebook = parent
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
150 tab_panel = wx.Panel(notebook, -1)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
151 tab_panel.sizer = wx.BoxSizer(wx.VERTICAL)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
152 tab_panel.SetSizer(tab_panel.sizer)
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
153 notebook.AddPage(tab_panel, label or name)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
154 self.__parseChilds(tab_panel, None, node, ['layout'])
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
155
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
156 else:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
157 message=_("Unknown tag")
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
158 error(message)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
159 raise Exception(message) #TODO: raise a custom exception here
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
160
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
161
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
162 def constructUI(self, xml_data):
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
163 panel=wx.Panel(self)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
164 panel.sizer = wx.BoxSizer(wx.VERTICAL)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
165
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
166 cat_dom = minidom.parseString(xml_data.encode('utf-8'))
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
167 top= cat_dom.documentElement
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
168 self.type = top.getAttribute("type")
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
169 self.title = top .getAttribute("title")
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
170 if self.title:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
171 self.SetTitle(self.title)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
172 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']:
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
173 raise Exception("Invalid XMLUI") #TODO: make a custom exception
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
174
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
175 self.__parseChilds(panel, None, cat_dom.documentElement)
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
176
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
177 if self.type == 'form':
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
178 dialogButtons = wx.StdDialogButtonSizer()
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
179 submitButton = wx.Button(panel,wx.ID_OK, label=_("Submit"))
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
180 dialogButtons.AddButton(submitButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
181 panel.Bind(wx.EVT_BUTTON, self.onFormSubmitted, submitButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
182 if not 'NO_CANCEL' in self.options:
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
183 cancelButton = wx.Button(panel,wx.ID_CANCEL)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
184 dialogButtons.AddButton(cancelButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
185 panel.Bind(wx.EVT_BUTTON, self.onFormCancelled, cancelButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
186 dialogButtons.Realize()
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
187 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
188
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
189 panel.SetSizer(panel.sizer)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
190 panel.SetAutoLayout(True)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
191 panel.sizer.Fit(self)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
192 self.sizer.Add(panel, 1, flag=wx.EXPAND)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
193 cat_dom.unlink()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
194
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
195 ###events
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
196
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
197 def onButtonClicked(self, event):
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
198 """Called when a button is pushed"""
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
199 callback_id, fields = event.GetEventObject().param_id
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
200 data = {"callback_id":callback_id}
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
201 for field in fields:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
202 ctrl = self.ctrl_list[field]
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
203 if isinstance(ctrl['control'], wx.ListBox):
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
204 data[field] = '\t'.join([ctrl['control'].GetString(idx) for idx in ctrl['control'].GetSelections()])
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
205 else:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
206 data[field] = ctrl['control'].GetValue()
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
207
135
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 107
diff changeset
208 id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile)
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
209 self.host.current_action_ids.add(id)
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
210 event.Skip()
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
211
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
212 def onFormSubmitted(self, event):
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
213 """Called when submit button is clicked"""
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
214 debug(_("Submitting form"))
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
215 data = []
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
216 for ctrl_name in self.ctrl_list:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
217 ctrl = self.ctrl_list[ctrl_name]
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
218 if isinstance(ctrl['control'], wx.ListBox):
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
219 data.append((ctrl_name, ctrl['control'].GetStringSelection()))
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
220 elif isinstance(ctrl['control'], wx.CheckBox):
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
221 data.append((ctrl_name, "true" if ctrl['control'].GetValue() else "false"))
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
222 else:
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
223 data.append((ctrl_name, ctrl['control'].GetValue()))
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
224 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
225 id = self.misc['action_back']("SUBMIT",self.misc['target'], data)
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
226 self.host.current_action_ids.add(id)
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
227 elif self.misc.has_key('callback'):
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
228 self.misc['callback'](data)
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
229 else:
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
230 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
231 self.MakeModal(False)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
232 self.Destroy()
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
233
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
234 def onFormCancelled(self, event):
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
235 """Called when cancel button is clicked"""
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
236 debug(_("Cancelling form"))
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
237 self.MakeModal(False)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
238 self.Close()
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
239
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
240 def onClose(self, event):
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
241 """Close event: we have to send the form."""
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
242 debug(_("close"))
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
243 self.MakeModal(False)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
244 event.Skip()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
245