annotate frontends/src/wix/xmlui.py @ 773:eac23b1aad90

core: dynamics menus refactoring: - menu now use generic callback system, with extra data - asyncMenuCall is removed in favor of launchAction - menu_id (== callback_id) is used to identify menu instead of category/name/type tuple - i18n is managed throught deferred translation, and returned with _i18n suffix e.g.: menu (D_('File'), D_('Open')): (u'File', u'Open') is menu_path, (u'Fichier', u'Ouvrir') is french menu_path_i18n. - type actually can have the following values: - NORMAL: classical menu - JID_CONTEXT: contextual menu, used with any jid - ROSTER_JID_CONTEXT: like JID_CONTEXT, but restricted to jids in roster. - ROSTER_GROUP_CONTEXT: contextual menu, use with groups - security_limit is used, in the same way as for parameters - when using importMenu, callback can be an actual callback, or one already registered with registerCallback
author Goffi <goffi@goffi.org>
date Sun, 29 Dec 2013 17:10:14 +0100
parents bfabeedbf32e
children 46aa5ada61bf
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
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 762
diff changeset
22 from sat.core.i18n import _
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
23 import wx
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
24 import pdb
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from xml.dom import minidom
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
26 from logging import debug, info, warning, error
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
27 from sat.tools.jid import JID
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
28
762
aed7d99276b8 core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents: 760
diff changeset
29 SAT_FORM_PREFIX = "SAT_FORM_"
aed7d99276b8 core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents: 760
diff changeset
30
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
31
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
32 class XMLUI(wx.Frame):
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
33 """Create an user interface from a SàT xml"""
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
34
555
1d58758689e9 primitivus, wix: fixed bad defaults values for XMLUI class
Goffi <goffi@goffi.org>
parents: 480
diff changeset
35 def __init__(self, host, xml_data='', title="Form", options = None, misc = None):
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
36 if options is None:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
37 options = []
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
38 style = wx.DEFAULT_FRAME_STYLE & ~wx.CLOSE_BOX if 'NO_CANCEL' in options else wx.DEFAULT_FRAME_STYLE #FIXME: Q&D tmp hack
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
39 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
40
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
41 self.host = host
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
42 self.options = options
555
1d58758689e9 primitivus, wix: fixed bad defaults values for XMLUI class
Goffi <goffi@goffi.org>
parents: 480
diff changeset
43 self.misc = misc or {}
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
44 self.ctrl_list = {} # usefull to access ctrl
35
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.sizer = wx.BoxSizer(wx.VERTICAL)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.SetSizer(self.sizer)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.SetAutoLayout(True)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
49
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
50 #events
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
51 if not 'NO_CANCEL' in self.options:
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
52 self.Bind(wx.EVT_CLOSE, self.onClose, self)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
53
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.MakeModal()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
55
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
56 self.constructUI(xml_data)
35
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 self.Show()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
59
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
60 def __parseElems(self, node, parent):
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
61 """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
62 for elem in node.childNodes:
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
63 if elem.nodeName != "elem":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
64 message=_("Unmanaged tag")
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
65 error(message)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
66 raise Exception(message)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
67 _proportion = 0
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
68 id = elem.getAttribute("id")
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
69 name = elem.getAttribute("name")
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
70 type = elem.getAttribute("type")
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
71 value = elem.getAttribute("value") if elem.hasAttribute('value') else u''
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
72 if type=="empty":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
73 ctrl = wx.Window(parent, -1)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
74 elif type=="text":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
75 try:
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
76 value = elem.childNodes[0].wholeText
149
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 135
diff changeset
77 except IndexError:
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
78 warning (_("text node has no child !"))
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
79 ctrl = wx.StaticText(parent, -1, value)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
80 elif type=="label":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
81 ctrl = wx.StaticText(parent, -1, value+": ")
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
82 elif type=="string":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
83 ctrl = wx.TextCtrl(parent, -1, value)
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
84 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
85 _proportion = 1
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
86 elif type=="password":
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
87 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
88 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
89 _proportion = 1
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
90 elif type=="textbox":
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
91 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
92 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
93 _proportion = 1
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
94 elif type=="bool":
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
95 ctrl = wx.CheckBox(panel, -1, "", style = wx.CHK_2STATE)
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
96 ctrl.SetValue(value=="true")
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
97 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
98 _proportion = 1
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
99 elif type=="list":
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
100 style=wx.LB_MULTIPLE if elem.getAttribute("multi")=='yes' else wx.LB_SINGLE
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
101 _options = [(option.getAttribute("label"), option.getAttribute("value")) for option in elem.getElementsByTagName("option")]
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
102 attr_map = {label: value for label, value in _options}
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
103 ctrl = wx.ListBox(parent, -1, choices=[option[0] for option in _options], style=style)
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
104 self.ctrl_list[name] = ({'type':type, 'control':ctrl, 'attr_map': attr_map})
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
105 _proportion = 1
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
106 elif type=="button":
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
107 callback_id = elem.getAttribute("callback_id")
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
108 ctrl = wx.Button(parent, -1, value)
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
109 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
110 parent.Bind(wx.EVT_BUTTON, self.onButtonClicked, ctrl)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
111 else:
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
112 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME !
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
113 raise NotImplementedError
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
114 parent.sizer.Add(ctrl, _proportion, flag=wx.EXPAND)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
115
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
116 def __parseChilds(self, parent, current_param, elem, wanted = ['layout']):
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
117 """Recursively parse childNodes of an elemen
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
118 @param parent: parent wx.Window
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
119 @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
120 @param elem: element from which childs will be parsed
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
121 @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
122 for node in elem.childNodes:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
123 if wanted and not node.nodeName in wanted:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
124 raise Exception("Invalid XMLUI") #TODO: make a custom exception
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
125 if node.nodeName == "layout":
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
126 _proportion = 0
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
127 type = node.getAttribute('type')
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
128 if type == "tabs":
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
129 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
130 self.__parseChilds(current, None, node, ['category'])
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
131 _proportion = 1
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
132 else:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
133 if current_param == None:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
134 current = wx.Panel(parent, -1)
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 current = current_param
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
137 if type == "vertical":
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
138 current.sizer = wx.BoxSizer(wx.VERTICAL)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
139 elif type == "pairs":
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
140 current.sizer = wx.FlexGridSizer(cols=2)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
141 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
142 else:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
143 warning(_("Unknown layout, using default one"))
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
144 current.sizer = wx.BoxSizer(wx.VERTICAL)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
145 current.SetSizer(current.sizer)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
146 self.__parseElems(node, current)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
147 if parent:
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
148 parent.sizer.Add(current, _proportion, flag=wx.EXPAND)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
149 elif node.nodeName == "category":
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
150 name = node.getAttribute('name')
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
151 label = node.getAttribute('label')
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
152 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
153 raise Exception("Invalid XMLUI") #TODO: make a custom exception
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
154 notebook = parent
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
155 tab_panel = wx.Panel(notebook, -1)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
156 tab_panel.sizer = wx.BoxSizer(wx.VERTICAL)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
157 tab_panel.SetSizer(tab_panel.sizer)
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
158 notebook.AddPage(tab_panel, label or name)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
159 self.__parseChilds(tab_panel, None, node, ['layout'])
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
160
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
161 else:
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
162 message=_("Unknown tag")
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
163 error(message)
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
164 raise Exception(message) #TODO: raise a custom exception here
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
165
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
166
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
167 def constructUI(self, xml_data):
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
168 panel=wx.Panel(self)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
169 panel.sizer = wx.BoxSizer(wx.VERTICAL)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
170
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
171 cat_dom = minidom.parseString(xml_data.encode('utf-8'))
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
172 top= cat_dom.documentElement
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
173 self.type = top.getAttribute("type")
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
174 self.title = top .getAttribute("title")
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
175 self.session_id = top.getAttribute("session_id") or None
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
176 self.submit_id = top.getAttribute("submit") or None
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
177 if self.title:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
178 self.SetTitle(self.title)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
179 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
180 raise Exception("Invalid XMLUI") #TODO: make a custom exception
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
181
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
182 self.__parseChilds(panel, None, cat_dom.documentElement)
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
183
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
184 if self.type == 'form':
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
185 dialogButtons = wx.StdDialogButtonSizer()
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
186 submitButton = wx.Button(panel,wx.ID_OK, label=_("Submit"))
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
187 dialogButtons.AddButton(submitButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
188 panel.Bind(wx.EVT_BUTTON, self.onFormSubmitted, submitButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
189 if not 'NO_CANCEL' in self.options:
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
190 cancelButton = wx.Button(panel,wx.ID_CANCEL)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
191 dialogButtons.AddButton(cancelButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
192 panel.Bind(wx.EVT_BUTTON, self.onFormCancelled, cancelButton)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
193 dialogButtons.Realize()
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 92
diff changeset
194 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
195
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
196 panel.SetSizer(panel.sizer)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
197 panel.SetAutoLayout(True)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
198 panel.sizer.Fit(self)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
199 self.sizer.Add(panel, 1, flag=wx.EXPAND)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
200 cat_dom.unlink()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
201
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
202 ###events
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
203
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
204 def onButtonClicked(self, event):
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
205 """Called when a button is pushed"""
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
206 callback_id, fields = event.GetEventObject().param_id
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
207 for field in fields:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
208 ctrl = self.ctrl_list[field]
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
209 if isinstance(ctrl['control'], wx.ListBox):
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
210 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
211 else:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
212 data[field] = ctrl['control'].GetValue()
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
213
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
214 self.host.launchAction(callback_id, None, profile_key = self.host.profile)
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
215 event.Skip()
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
216
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
217 def onFormSubmitted(self, event):
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
218 """Called when submit button is clicked"""
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
219 debug(_("Submitting form"))
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
220 selected_values = []
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
221 for ctrl_name in self.ctrl_list:
762
aed7d99276b8 core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents: 760
diff changeset
222 escaped = u"%s%s" % (SAT_FORM_PREFIX, ctrl_name)
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
223 ctrl = self.ctrl_list[ctrl_name]
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
224 if isinstance(ctrl['control'], wx.ListBox):
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
225 label = ctrl['control'].GetStringSelection()
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
226 value = ctrl['attr_map'][label]
762
aed7d99276b8 core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents: 760
diff changeset
227 selected_values.append((escaped, value))
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 149
diff changeset
228 elif isinstance(ctrl['control'], wx.CheckBox):
762
aed7d99276b8 core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents: 760
diff changeset
229 selected_values.append((escaped, "true" if ctrl['control'].GetValue() else "false"))
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
230 else:
762
aed7d99276b8 core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents: 760
diff changeset
231 selected_values.append((escaped, ctrl['control'].GetValue()))
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
232 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
233 id = self.misc['action_back']("SUBMIT",self.misc['target'], selected_values)
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
234 self.host.current_action_ids.add(id)
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
235 elif self.misc.has_key('callback'):
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
236 self.misc['callback'](selected_values)
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
237
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
238 elif self.submit_id is not None:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
239 data = dict(selected_values)
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
240 if self.session_id is not None:
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
241 data["session_id"] = self.session_id
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
242 self.host.launchAction(self.submit_id, data, profile_key=self.host.profile)
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
243 else:
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 70
diff changeset
244 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
245 self.MakeModal(False)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
246 self.Destroy()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
247
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
248 def onFormCancelled(self, event):
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 35
diff changeset
249 """Called when cancel button is clicked"""
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
250 debug(_("Cancelling form"))
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
251 self.MakeModal(False)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
252 self.Close()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
253
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
254 def onClose(self, event):
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
255 """Close event: we have to send the form."""
70
Goffi <goffi@goffi.org>
parents: 57
diff changeset
256 debug(_("close"))
35
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
257 self.MakeModal(False)
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
258 event.Skip()
c45deebb40a5 Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
diff changeset
259