annotate frontends/src/primitivus/xmlui.py @ 794:52c4b755aba6

test: make FakeClient profile dependent and add some tools to test MUC
author souliane <souliane@mailoo.org>
date Fri, 10 Jan 2014 18:15:02 +0100
parents bfabeedbf32e
children 46aa5ada61bf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
4 # Primitivus: a SAT frontend
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
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: 607
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: 607
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: 607
diff changeset
10 # (at your option) any later version.
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
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: 607
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: 607
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: 607
diff changeset
15 # GNU Affero General Public License for more details.
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
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: 607
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 762
diff changeset
20 from sat.core.i18n import _
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import urwid
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
22 from urwid_satext import sat_widgets
162
ae50b53ff868 misc Tarot fixes
Goffi <goffi@goffi.org>
parents: 157
diff changeset
23 from logging import debug, info, warning, error
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from xml.dom import minidom
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
25
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
26
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
27 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
28
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
29 def getText(node):
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
30 """Get child text nodes
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
31 @param node: dom Node
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
32 @return: joined unicode text of all nodes
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
33
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
34 """
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
35 data = []
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
36 for child in node.childNodes:
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
37 if child.nodeType == child.TEXT_NODE:
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
38 data.append(child.wholeText)
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
39 return u"".join(data)
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
40
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 632
diff changeset
41
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
42 class Pairs(urwid.WidgetWrap):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
43
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def __init__(self, weight_0='1', weight_1='1'):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.idx = 0
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.weight_0 = weight_0
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.weight_1 = weight_1
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
48 columns = urwid.Columns([urwid.Text(''), urwid.Text('')])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
49 #XXX: empty Text hack needed because Pile doesn't support empty list
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
50 urwid.WidgetWrap.__init__(self,columns)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
51
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
52 def append(self, widget):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
53 pile = self._w.widget_list[self.idx]
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
54 if isinstance(pile, urwid.Text):
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self._w.widget_list[self.idx] = urwid.Pile([widget])
149
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 144
diff changeset
56 if self.idx == 1:
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 144
diff changeset
57 self._w.set_focus(1)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
58 else:
610
c8c07c920e30 Primitivus: fixed xmlui/chat bad contents change
Goffi <goffi@goffi.org>
parents: 609
diff changeset
59 pile.contents.append((widget,('weight',getattr(self,'weight_'+str(self.idx)))))
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self.idx = (self.idx + 1) % 2
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
61
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
62 class InvalidXMLUI(Exception):
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
63 pass
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
64
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
65 class XMLUI(urwid.WidgetWrap):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
66
555
1d58758689e9 primitivus, wix: fixed bad defaults values for XMLUI class
Goffi <goffi@goffi.org>
parents: 480
diff changeset
67 def __init__(self, host, xml_data, title = None, options = None, misc = None):
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.host = host
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
69 self.title = title
555
1d58758689e9 primitivus, wix: fixed bad defaults values for XMLUI class
Goffi <goffi@goffi.org>
parents: 480
diff changeset
70 self.options = options or []
1d58758689e9 primitivus, wix: fixed bad defaults values for XMLUI class
Goffi <goffi@goffi.org>
parents: 480
diff changeset
71 self.misc = misc or {}
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
72 self.__dest = "window"
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self.ctrl_list = {} # usefull to access ctrl
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
74 widget = self.constructUI(xml_data)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
75 urwid.WidgetWrap.__init__(self,widget)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
76
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
77 def __parseElems(self, node, parent):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
78 """Parse elements inside a <layout> tags, and add them to the parent"""
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
79 for elem in node.childNodes:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
80 if elem.nodeName != "elem":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
81 message=_("Unmanaged tag")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
82 error(message)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
83 raise Exception(message)
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
84 id_ = elem.getAttribute("id")
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
85 name = elem.getAttribute("name")
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
86 type_ = elem.getAttribute("type")
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
87 value = elem.getAttribute("value") if elem.hasAttribute('value') else u''
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
88 if type_=="empty":
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
89 ctrl = urwid.Text('')
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
90 elif type_=="text":
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
91 try:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
92 value = elem.childNodes[0].wholeText
149
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 144
diff changeset
93 except IndexError:
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
94 warning (_("text node has no child !"))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
95 ctrl = urwid.Text(value)
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
96 elif type_=="label":
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
97 ctrl = urwid.Text(value+": ")
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
98 elif type_=="string":
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
99 ctrl = sat_widgets.AdvancedEdit(edit_text = value)
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
100 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
101 elif type_=="password":
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
102 ctrl = sat_widgets.Password(edit_text = value)
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
103 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
104 elif type_=="textbox":
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
105 ctrl = sat_widgets.AdvancedEdit(edit_text = value, multiline=True)
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
106 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
107 elif type_=="bool":
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 170
diff changeset
108 ctrl = urwid.CheckBox('', state = value=="true")
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
109 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
110 elif type_=="list":
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
111 style=[] if elem.getAttribute("multi")=='yes' else ['single']
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
112 ctrl = sat_widgets.List(options=[(option.getAttribute("value"), option.getAttribute("label")) for option in elem.getElementsByTagName("option")], style=style, on_change=self.onParamChange if self.type == "param" else None)
655
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
113 ctrl.selectValue(elem.getAttribute("value"))
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
114 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
115 elif type_=="button":
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 687
diff changeset
116 callback_id = elem.getAttribute("callback")
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
117 ctrl = sat_widgets.CustomButton(value, on_press=self.onButtonPress)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
118 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")])
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
119 elif type_=="advanced_list":
655
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
120 ctrl = sat_widgets.List(options=[getText(txt_elt) for txt_elt in elem.getElementsByTagName("text")], style=['can_select_none'], max_height=20, on_change=self.onParamChange)
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
121 ctrl.selectValue(elem.getAttribute("value"))
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
122 self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
123 else:
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
124 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type_) #FIXME !
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
125 raise NotImplementedError
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
126 if self.type == 'param':
655
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
127 if isinstance(ctrl, urwid.Edit) or isinstance(ctrl, urwid.CheckBox):
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
128 urwid.connect_signal(ctrl,'change',self.onParamChange)
655
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
129 elif isinstance(ctrl, sat_widgets.List):
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
130 # the GenericList member triggers the events, not List itself
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
131 # TODO: create a method GenericList.setParamData() for that,
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
132 # or later in onSaveParams do something like ctrl.getParent()
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
133 ctrl.genericList._param_category = self._current_category
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
134 ctrl.genericList._param_name = name
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
135 ctrl._param_category = self._current_category
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
136 ctrl._param_name = name
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
137 parent.append(ctrl)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
138
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
139 def __parseChilds(self, current, elem, wanted = ['layout'], data = None):
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
140 """Recursively parse childNodes of an elemen
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
141 @param current: widget container with 'append' method
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
142 @param elem: element from which childs will be parsed
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
143 @param wanted: list of tag names that can be present in the childs to be SàT XMLUI compliant"""
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
144 for node in elem.childNodes:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
145 if wanted and not node.nodeName in wanted:
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
146 raise InvalidXMLUI
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
147 if node.nodeName == "layout":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
148 type = node.getAttribute('type')
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
149 if type == "tabs":
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
150 tab_cont = sat_widgets.TabsContainer()
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
151 self.__parseChilds(current, node, ['category'], tab_cont)
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
152 current.append(tab_cont)
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
153 elif type == "vertical":
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
154 self.__parseElems(node, current)
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
155 elif type == "pairs":
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
156 pairs = Pairs()
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
157 self.__parseElems(node, pairs)
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
158 current.append(pairs)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
159 else:
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
160 warning(_("Unknown layout, using default one"))
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
161 self.__parseElems(node, current)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
162 elif node.nodeName == "category":
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
163 name = node.getAttribute('name')
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
164 label = node.getAttribute('label')
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
165 if not name or not isinstance(data,sat_widgets.TabsContainer):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
166 raise InvalidXMLUI
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
167 if self.type == 'param':
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
168 self._current_category = name #XXX: awful hack because params need category and we don't keep parent
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
169 tab_cont = data
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 170
diff changeset
170 listbox = tab_cont.addTab(label or name)
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
171 self.__parseChilds(listbox.body, node, ['layout'])
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
172 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
173 message=_("Unknown tag")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
174 error(message)
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
175 raise NotImplementedError
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
176
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
177 def constructUI(self, xml_data):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
178
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
179 ret_wid = urwid.ListBox(urwid.SimpleListWalker([]))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
180
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
181 cat_dom = minidom.parseString(xml_data.encode('utf-8'))
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
182 top=cat_dom.documentElement
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
183 self.type = top.getAttribute("type")
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
184 self.title = top.getAttribute("title") or self.title
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
185 self.session_id = top.getAttribute("session_id") or None
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 687
diff changeset
186 self.submit_id = top.getAttribute("submit") or None
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
187 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']:
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
188 raise InvalidXMLUI
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
189
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
190 if self.type == 'param':
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
191 self.param_changed = set()
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
192
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
193 self.__parseChilds(ret_wid.body, cat_dom.documentElement)
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
194
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
195 assert ret_wid.body
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
196
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
197 if isinstance(ret_wid.body[0],sat_widgets.TabsContainer):
167
6fd053c99421 Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents: 166
diff changeset
198 ret_wid = ret_wid.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
199
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
200
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
201 if self.type == 'form':
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
202 buttons = []
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
203 buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
204 if not 'NO_CANCEL' in self.options:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
205 buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
206 max_len = max([len(button.get_label()) for button in buttons])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
207 grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center')
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
208 ret_wid.body.append(grid_wid)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
209 elif self.type == 'param':
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
210 assert(isinstance(ret_wid,sat_widgets.TabsContainer))
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
211 buttons = []
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
212 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams))
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
213 buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow()))
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
214 max_len = max([button.getSize() for button in buttons])
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
215 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center')
167
6fd053c99421 Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents: 166
diff changeset
216 ret_wid.addFooter(grid_wid)
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
217 return ret_wid
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
218
687
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 655
diff changeset
219 def show(self, show_type='popup', valign='middle'):
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
220 """Show the constructed UI
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
221 @param show_type: how to show the UI:
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
222 - popup
687
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 655
diff changeset
223 - window
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 655
diff changeset
224 @param valign: vertical alignment when show_type is 'popup'.
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 655
diff changeset
225 Ignored when show_type is 'window'.
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 655
diff changeset
226 """
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
227 self.__dest = "popup"
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
228 decorated = sat_widgets.LabelLine(self, sat_widgets.SurroundedText(self.title or ''))
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
229 if show_type == 'popup':
687
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 655
diff changeset
230 self.host.showPopUp(decorated, valign=valign)
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
231 elif show_type == 'window':
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
232 self.host.addWindow(decorated)
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
233 else:
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
234 error(_('INTERNAL ERROR: Unmanaged show_type (%s)') % show_type)
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
235 assert(False)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
236 self.host.redraw()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
237
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
238
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
239 ##EVENTS##
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
240
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
241 def onButtonPress(self, button):
157
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
242 callback_id, fields = button.param_id
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 687
diff changeset
243 data = {}
157
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
244 for field in fields:
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
245 ctrl = self.ctrl_list[field]
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
246 if isinstance(ctrl['control'],sat_widgets.List):
655
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
247 data[field] = u'\t'.join(ctrl['control'].getSelectedValues())
157
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
248 else:
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
249 data[field] = ctrl['control'].getValue()
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
250
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 687
diff changeset
251 self.host.launchAction(callback_id, data, profile_key = self.host.profile)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
252
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 170
diff changeset
253 def onParamChange(self, widget, extra=None):
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
254 """Called when type is param and a widget to save is modified"""
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
255 assert(self.type == "param")
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
256 self.param_changed.add(widget)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
257
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
258 def onFormSubmitted(self, button):
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
259 selected_values = []
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
260 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
261 escaped = u"%s%s" % (SAT_FORM_PREFIX, ctrl_name)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
262 ctrl = self.ctrl_list[ctrl_name]
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 192
diff changeset
263 if isinstance(ctrl['control'], sat_widgets.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
264 selected_values.append((escaped, u'\t'.join([option.value for option in ctrl['control'].getSelectedValues()])))
192
879beacb8e16 Primitivus: major changes in SelectableText, menu can now be used with mouse, TabsContainer show wich tab is selected
Goffi <goffi@goffi.org>
parents: 183
diff changeset
265 elif isinstance(ctrl['control'], urwid.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
266 selected_values.append((escaped, "true" if ctrl['control'].get_state() else "false"))
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
267 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
268 selected_values.append((escaped, ctrl['control'].get_edit_text()))
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
269 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
270 raise NotImplementedError
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 687
diff changeset
271 elif 'callback' in self.misc: # FIXME: this part is not needed anymore
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
272 try:
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
273 self.misc['callback'](selected_values, submit_id=self.submit_id, *self.misc['callback_args'])
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
274 except KeyError:
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
275 self.misc['callback'](selected_values, submit_id=self.submit_id)
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 687
diff changeset
276 elif self.submit_id is not None:
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
277 data = dict(selected_values)
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
278 if self.session_id is not None:
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
279 data["session_id"] = self.session_id
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
280 self.host.launchAction(self.submit_id, data, profile_key=self.host.profile)
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
281
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
282 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
283 warning (_("The form data is not sent back, the type is not managed properly"))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
284 self.host.removePopUp()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
285
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
286 def onFormCancelled(self, button):
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
287 if self.__dest == 'window':
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
288 self.host.removeWindow()
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
289 else:
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
290 self.host.removePopUp()
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
291
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
292 def onSaveParams(self, button):
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
293 for ctrl in self.param_changed:
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 170
diff changeset
294 if isinstance(ctrl, urwid.CheckBox):
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 170
diff changeset
295 value = "true" if ctrl.get_state() else "false"
655
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
296 elif isinstance(ctrl, sat_widgets.GenericList):
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 641
diff changeset
297 value = u'\t'.join(ctrl.getSelectedValues())
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 170
diff changeset
298 else:
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 170
diff changeset
299 value = ctrl.get_edit_text()
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 632
diff changeset
300 self.host.bridge.setParam(ctrl._param_name, value, ctrl._param_category,
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 632
diff changeset
301 profile_key=self.host.profile)
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
302 self.host.removeWindow()