annotate frontends/src/wix/xmlui.py @ 622:9a8fbf0e8691

pluging maildir: some trivial fixes: - path is now (local dir)/maildir/(profile name) instead of directly (profile name) - removed forgotten breakpoint - use of MaildirError instead of the inexistant MailboxException - fixed some forgotten "self."
author Goffi <goffi@goffi.org>
date Thu, 20 Jun 2013 12:37:06 +0200
parents 84a6e83157c2
children 93bd868b8fb6
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
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
4 # wix: a SAT frontend
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
10 # (at your option) any later version.
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
15 # GNU Affero General Public License for more details.
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
19
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 import wx
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
23 import pdb
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from xml.dom import minidom
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
25 from logging import debug, info, warning, error
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
26 from sat.tools.jid import JID
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
27
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
28
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
29 class XMLUI(wx.Frame):
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
30 """Create an user interface from a SàT xml"""
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
31
555
1d58758689e9 primitivus, wix: fixed bad defaults values for XMLUI class
Goffi <goffi@goffi.org>
parents: 480
diff changeset
32 def __init__(self, host, xml_data='', title="Form", options = None, misc = None):
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
33 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
34 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
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
36 self.host = host
555
1d58758689e9 primitivus, wix: fixed bad defaults values for XMLUI class
Goffi <goffi@goffi.org>
parents: 480
diff changeset
37 self.options = options or []
1d58758689e9 primitivus, wix: fixed bad defaults values for XMLUI class
Goffi <goffi@goffi.org>
parents: 480
diff changeset
38 self.misc = misc or {}
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
39 self.ctrl_list = {} # usefull to access ctrl
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
40
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
41 self.sizer = wx.BoxSizer(wx.VERTICAL)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
42 self.SetSizer(self.sizer)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
43 self.SetAutoLayout(True)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
44
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
45 #events
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
46 if not 'NO_CANCEL' in self.options:
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
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
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.MakeModal()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
50
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
51 self.constructUI(xml_data)
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
52
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.Show()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
54
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
55 def __parseElems(self, node, parent):
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
56 """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
57 for elem in node.childNodes:
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
58 if elem.nodeName != "elem":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
59 message=_("Unmanaged tag")
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
60 error(message)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
61 raise Exception(message)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
62 _proportion = 0
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
63 id = elem.getAttribute("id")
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
64 name = elem.getAttribute("name")
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
65 type = elem.getAttribute("type")
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
66 value = elem.getAttribute("value") if elem.hasAttribute('value') else u''
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
67 if type=="empty":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
68 ctrl = wx.Window(parent, -1)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
69 elif type=="text":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
70 try:
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
71 value = elem.childNodes[0].wholeText
149
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 135
diff changeset
72 except IndexError:
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
73 warning (_("text node has no child !"))
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
74 ctrl = wx.StaticText(parent, -1, value)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
75 elif type=="label":
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=="string":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
78 ctrl = wx.TextCtrl(parent, -1, value)
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
79 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
80 _proportion = 1
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
81 elif type=="password":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
82 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
83 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
84 _proportion = 1
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
85 elif type=="textbox":
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
86 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
87 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
88 _proportion = 1
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
89 elif type=="bool":
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
90 ctrl = wx.CheckBox(panel, -1, "", style = wx.CHK_2STATE)
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
91 ctrl.SetValue(value=="true")
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
92 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
93 _proportion = 1
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
94 elif type=="list":
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
95 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
96 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
97 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
98 _proportion = 1
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
99 elif type=="button":
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
100 callback_id = elem.getAttribute("callback_id")
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
101 ctrl = wx.Button(parent, -1, value)
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
102 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
103 parent.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
104 else:
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
105 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME !
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
106 raise NotImplementedError
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
107 parent.sizer.Add(ctrl, _proportion, flag=wx.EXPAND)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
108
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
109 def __parseChilds(self, parent, current_param, elem, wanted = ['layout']):
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
110 """Recursively parse childNodes of an elemen
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
111 @param parent: parent wx.Window
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
112 @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
113 @param elem: element from which childs will be parsed
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
114 @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
115 for node in elem.childNodes:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
116 if wanted and not node.nodeName in wanted:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
117 raise Exception("Invalid XMLUI") #TODO: make a custom exception
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
118 if node.nodeName == "layout":
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
119 _proportion = 0
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
120 type = node.getAttribute('type')
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
121 if type == "tabs":
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
122 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
123 self.__parseChilds(current, None, node, ['category'])
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
124 _proportion = 1
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
125 else:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
126 if current_param == None:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
127 current = wx.Panel(parent, -1)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
128 else:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
129 current = current_param
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
130 if type == "vertical":
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
131 current.sizer = wx.BoxSizer(wx.VERTICAL)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
132 elif type == "pairs":
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
133 current.sizer = wx.FlexGridSizer(cols=2)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
134 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
135 else:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
136 warning(_("Unknown layout, using default one"))
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
137 current.sizer = wx.BoxSizer(wx.VERTICAL)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
138 current.SetSizer(current.sizer)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
139 self.__parseElems(node, current)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
140 if parent:
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
141 parent.sizer.Add(current, _proportion, flag=wx.EXPAND)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
142 elif node.nodeName == "category":
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
143 name = node.getAttribute('name')
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
144 label = node.getAttribute('label')
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
145 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
146 raise Exception("Invalid XMLUI") #TODO: make a custom exception
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
147 notebook = parent
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
148 tab_panel = wx.Panel(notebook, -1)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
149 tab_panel.sizer = wx.BoxSizer(wx.VERTICAL)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
150 tab_panel.SetSizer(tab_panel.sizer)
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
151 notebook.AddPage(tab_panel, label or name)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
152 self.__parseChilds(tab_panel, None, node, ['layout'])
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
153
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
154 else:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
155 message=_("Unknown tag")
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
156 error(message)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
157 raise Exception(message) #TODO: raise a custom exception here
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
158
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
159
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
160 def constructUI(self, xml_data):
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
161 panel=wx.Panel(self)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
162 panel.sizer = wx.BoxSizer(wx.VERTICAL)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
163
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
164 cat_dom = minidom.parseString(xml_data.encode('utf-8'))
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
165 top= cat_dom.documentElement
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
166 self.type = top.getAttribute("type")
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
167 self.title = top .getAttribute("title")
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
168 if self.title:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
169 self.SetTitle(self.title)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
170 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
171 raise Exception("Invalid XMLUI") #TODO: make a custom exception
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
172
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
173 self.__parseChilds(panel, None, cat_dom.documentElement)
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
174
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
175 if self.type == 'form':
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
176 dialogButtons = wx.StdDialogButtonSizer()
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
177 submitButton = wx.Button(panel,wx.ID_OK, label=_("Submit"))
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
178 dialogButtons.AddButton(submitButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
179 panel.Bind(wx.EVT_BUTTON, self.onFormSubmitted, submitButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
180 if not 'NO_CANCEL' in self.options:
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
181 cancelButton = wx.Button(panel,wx.ID_CANCEL)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
182 dialogButtons.AddButton(cancelButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
183 panel.Bind(wx.EVT_BUTTON, self.onFormCancelled, cancelButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
184 dialogButtons.Realize()
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
185 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
186
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
187 panel.SetSizer(panel.sizer)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
188 panel.SetAutoLayout(True)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
189 panel.sizer.Fit(self)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
190 self.sizer.Add(panel, 1, flag=wx.EXPAND)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
191 cat_dom.unlink()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
192
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
193 ###events
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
194
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
195 def onButtonClicked(self, event):
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
196 """Called when a button is pushed"""
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
197 callback_id, fields = event.GetEventObject().param_id
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
198 data = {"callback_id":callback_id}
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
199 for field in fields:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
200 ctrl = self.ctrl_list[field]
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
201 if isinstance(ctrl['control'], wx.ListBox):
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
202 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
203 else:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
204 data[field] = ctrl['control'].GetValue()
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
205
135
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 107
diff changeset
206 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
207 self.host.current_action_ids.add(id)
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
208 event.Skip()
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
209
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
210 def onFormSubmitted(self, event):
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
211 """Called when submit button is clicked"""
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
212 debug(_("Submitting form"))
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
213 data = []
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
214 for ctrl_name in self.ctrl_list:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
215 ctrl = self.ctrl_list[ctrl_name]
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
216 if isinstance(ctrl['control'], wx.ListBox):
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
217 data.append((ctrl_name, ctrl['control'].GetStringSelection()))
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
218 elif isinstance(ctrl['control'], wx.CheckBox):
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
219 data.append((ctrl_name, "true" if ctrl['control'].GetValue() else "false"))
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
220 else:
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
221 data.append((ctrl_name, ctrl['control'].GetValue()))
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
222 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
223 id = self.misc['action_back']("SUBMIT",self.misc['target'], data)
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
224 self.host.current_action_ids.add(id)
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
225 elif self.misc.has_key('callback'):
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
226 self.misc['callback'](data)
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
227 else:
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
228 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
229 self.MakeModal(False)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
230 self.Destroy()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
231
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
232 def onFormCancelled(self, event):
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
233 """Called when cancel button is clicked"""
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
234 debug(_("Cancelling form"))
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
235 self.MakeModal(False)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
236 self.Close()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
237
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
238 def onClose(self, event):
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
239 """Close event: we have to send the form."""
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
240 debug(_("close"))
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
241 self.MakeModal(False)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
242 event.Skip()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
243