annotate frontends/src/primitivus/xmlui.py @ 976:68faf7d77a42

frontends (xmlui): add setter methods + fixes: - add _xmluiSetValue for all widgets + _xmluiAddValues for ListWidget - fix popup dialog OK button + _xmluiOnClick for ButtonWidget
author souliane <souliane@mailoo.org>
date Thu, 03 Apr 2014 14:49:05 +0200
parents b37b1d183ac3
children 73a0b7f94674
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
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 805
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 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
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
22 import copy
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
23 from urwid_satext import sat_widgets
162
ae50b53ff868 misc Tarot fixes
Goffi <goffi@goffi.org>
parents: 157
diff changeset
24 from logging import debug, info, warning, error
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from xml.dom import minidom
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
26 from sat_frontends.tools import xmlui
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
27
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
28
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
29 class PrimitivusEvents(object):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
30 """ Used to manage change event of Primitivus widgets """
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
31
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
32 def _event_callback(self, ctrl, *args, **ktkwargs):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
33 """" Call xmlui callback and ignore any extra argument """
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
34 args[-1](ctrl)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
35
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
36 def _xmluiOnChange(self, callback):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
37 """ Call callback with widget as only argument """
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
38 urwid.connect_signal(self, 'change', self._event_callback, callback)
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
39
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
40
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
41 class PrimitivusEmptyWidget(xmlui.EmptyWidget, urwid.Text):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
42
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
43 def __init__(self, parent):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
44 urwid.Text.__init__(self, '')
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
45
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
46
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
47 class PrimitivusTextWidget(xmlui.TextWidget, urwid.Text):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
48
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
49 def __init__(self, parent, value):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
50 urwid.Text.__init__(self, value)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
51
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
52
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
53 class PrimitivusLabelWidget(xmlui.LabelWidget, PrimitivusTextWidget):
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
54
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
55 def __init__(self, parent, value):
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
56 super(PrimitivusLabelWidget, self).__init__(parent, value+": ")
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
57
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
58
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
59 class PrimitivusJidWidget(xmlui.JidWidget, PrimitivusTextWidget):
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
60 pass
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
61
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
62
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
63 class PrimitivusDividerWidget(xmlui.DividerWidget, urwid.Divider):
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
64
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
65 def __init__(self, parent, style='line'):
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
66 if style == 'line':
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
67 div_char = u'─'
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
68 elif style == 'dot':
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
69 div_char = u'·'
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
70 elif style == 'dash':
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
71 div_char = u'-'
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
72 elif style == 'plain':
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
73 div_char = u'█'
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
74 elif style == 'blank':
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
75 div_char = ' '
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
76 else:
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
77 warning(_("Unknown div_char"))
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
78 div_char = u'─'
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
79
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
80 urwid.Divider.__init__(self, div_char)
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
81
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
82
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
83 class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
84
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
85 def __init__(self, parent, value):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
86 sat_widgets.AdvancedEdit.__init__(self, edit_text=value)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
87
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
88 def _xmluiSetValue(self, value):
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
89 self.set_edit_text(value)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
90
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
91 def _xmluiGetValue(self):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
92 return self.get_edit_text()
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
93
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
94
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
95 class PrimitivusPasswordWidget(xmlui.PasswordWidget, sat_widgets.Password, PrimitivusEvents):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
96
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
97 def __init__(self, parent, value):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
98 sat_widgets.Password.__init__(self, edit_text=value)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
99
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
100 def _xmluiSetValue(self, value):
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
101 self.set_edit_text(value)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
102
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
103 def _xmluiGetValue(self):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
104 return self.get_edit_text()
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
105
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
106
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
107 class PrimitivusTextBoxWidget(xmlui.TextBoxWidget, sat_widgets.AdvancedEdit, PrimitivusEvents):
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
108
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
109 def __init__(self, parent, value):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
110 sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
111
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
112 def _xmluiSetValue(self, value):
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
113 self.set_edit_text(value)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
114
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
115 def _xmluiGetValue(self):
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 912
diff changeset
116 return self.get_edit_text()
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
117
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
118
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
119 class PrimitivusBoolWidget(xmlui.BoolWidget, urwid.CheckBox, PrimitivusEvents):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
120
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
121 def __init__(self, parent, state):
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 912
diff changeset
122 urwid.CheckBox.__init__(self, '', state=state)
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
123
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
124 def _xmluiSetValue(self, value):
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
125 self.set_state(value == "true")
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
126
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
127 def _xmluiGetValue(self):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
128 return "true" if self.get_state() else "false"
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
129
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 632
diff changeset
130
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
131 class PrimitivusButtonWidget(xmlui.ButtonWidget, sat_widgets.CustomButton, PrimitivusEvents):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
132
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
133 def __init__(self, parent, value, click_callback):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
134 sat_widgets.CustomButton.__init__(self, value, on_press=click_callback)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
135
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
136 def _xmluiOnClick(self, callback):
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
137 urwid.connect_signal(self, 'click', callback)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
138
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
139
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
140 class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
141
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 912
diff changeset
142 def __init__(self, parent, options, selected, flags):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
143 sat_widgets.List.__init__(self, options=options, style=flags)
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 912
diff changeset
144 self._xmluiSelectValues(selected)
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
145
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
146 def _xmluiSelectValue(self, value):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
147 return self.selectValue(value)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
148
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 912
diff changeset
149 def _xmluiSelectValues(self, values):
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 912
diff changeset
150 return self.selectValues(values)
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 912
diff changeset
151
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
152 def _xmluiGetSelectedValues(self):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
153 return [option.value for option in self.getSelectedValues()]
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
154
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
155 def _xmluiAddValues(self, values, select=True):
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
156 current_values = self.getAllValues()
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
157 new_values = copy.deepcopy(current_values)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
158 for value in values:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
159 if value not in current_values:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
160 new_values.append(value)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
161 if select:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
162 selected = self._xmluiGetSelectedValues()
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
163 self.changeValues(new_values)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
164 if select:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
165 for value in values:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
166 if value not in selected:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
167 selected.append(value)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
168 self._xmluiSelectValues(selected)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
169
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
170
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
171 class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
172
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
173 def __init__(self, parent, columns, selectable='no'):
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
174 options = {'ADAPT':()}
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
175 if selectable != 'no':
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
176 options['HIGHLIGHT'] = ()
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
177 sat_widgets.TableContainer.__init__(self, columns=columns, options=options, row_selectable = selectable!='no')
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
178
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
179 def _xmluiAppend(self, widget):
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
180 self.addWidget(widget)
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
181
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
182 def _xmluiAddRow(self, idx):
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
183 self.setRowIndex(idx)
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
184
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
185 def _xmluiGetSelectedWidgets(self):
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
186 return self.getSelectedWidgets()
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
187
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
188 def _xmluiGetSelectedIndex(self):
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
189 return self.getSelectedIndex()
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
190
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
191 def _xmluiOnSelect(self, callback):
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
192 """ Call callback with widget as only argument """
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
193 urwid.connect_signal(self, 'click', self._event_callback, callback)
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
194
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
195
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
196 class PrimitivusPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer):
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
197
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
198 def __init__(self, parent):
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
199 options = {'ADAPT':(0,), 'HIGHLIGHT':(0,)}
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
200 if self._xmlui_main.type == 'param':
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
201 options['FOCUS_ATTR'] = 'param_selected'
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
202 sat_widgets.TableContainer.__init__(self, columns=2, options=options)
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
203
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
204 def _xmluiAppend(self, widget):
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
205 if isinstance(widget, PrimitivusEmptyWidget):
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
206 # we don't want highlight on empty widgets
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
207 widget = urwid.AttrMap(widget, 'default')
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
208 self.addWidget(widget)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
209
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
210
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
211 class PrimitivusTabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer):
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
212
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
213 def __init__(self, parent):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
214 sat_widgets.TabsContainer.__init__(self)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
215
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
216 def _xmluiAppend(self, widget):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
217 self.body.append(widget)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
218
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
219 def _xmluiAddTab(self, label):
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
220 tab = PrimitivusVerticalContainer(None)
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
221 self.addTab(label, tab)
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
222 return tab
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
223
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
224
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
225 class PrimitivusVerticalContainer(xmlui.VerticalContainer, urwid.ListBox):
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
226 BOX_HEIGHT = 5
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
227
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
228 def __init__(self, parent):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
229 urwid.ListBox.__init__(self, urwid.SimpleListWalker([]))
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
230 self._last_size = None
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
231
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
232 def _xmluiAppend(self, widget):
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
233 if 'flow' not in widget.sizing():
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
234 widget = urwid.BoxAdapter(widget, self.BOX_HEIGHT)
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
235 self.body.append(widget)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
236
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
237 def render(self, size, focus=False):
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
238 if size != self._last_size:
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
239 (maxcol, maxrow) = size
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
240 if self.body:
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
241 widget = self.body[0]
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
242 if isinstance(widget, urwid.BoxAdapter):
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
243 widget.height = maxrow
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
244 self._last_size = size
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
245 return super(PrimitivusVerticalContainer, self).render(size, focus)
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
246
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
247
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
248 class WidgetFactory(object):
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
249
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
250 def __getattr__(self, attr):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
251 if attr.startswith("create"):
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
252 cls = globals()["Primitivus" + attr[6:]] # XXX: we prefix with "Primitivus" to work around an Urwid bug, WidgetMeta in Urwid don't manage multiple inheritance with same names
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
253 cls._xmlui_main = self._xmlui_main
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
254 return cls
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
255
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
256 class XMLUI(xmlui.XMLUI, urwid.WidgetWrap):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
257 widget_factory = WidgetFactory()
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
258
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
259 def __init__(self, host, xml_data, title = None, flags = None):
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
260 self.widget_factory._xmlui_main = self
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
261 self._dest = None
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
262 xmlui.XMLUI.__init__(self, host, xml_data, title, flags)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 796
diff changeset
263 urwid.WidgetWrap.__init__(self, self.main_cont)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
264
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
265 def constructUI(self, xml_data):
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 796
diff changeset
266 def postTreat():
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 796
diff changeset
267 assert self.main_cont.body
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
268
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
269 if self.type in ('form', 'popup'):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
270 buttons = []
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
271 if self.type == 'form':
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
272 buttons.append(urwid.Button(_('Submit'), self.onFormSubmitted))
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
273 if not 'NO_CANCEL' in self.flags:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
274 buttons.append(urwid.Button(_('Cancel'), self.onFormCancelled))
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
275 else:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
276 buttons.append(urwid.Button(_('OK'), lambda dummy: self._xmluiClose()))
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
277 max_len = max([len(button.get_label()) for button in buttons])
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
278 grid_wid = urwid.GridFlow(buttons, max_len + 4, 1, 0, 'center')
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 796
diff changeset
279 self.main_cont.body.append(grid_wid)
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
280 elif self.type == 'param':
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
281 tabs_cont = self.main_cont.body[0].base_widget
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
282 assert(isinstance(tabs_cont,sat_widgets.TabsContainer))
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
283 buttons = []
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
284 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams))
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
285 buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow()))
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
286 max_len = max([button.getSize() for button in buttons])
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
287 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center')
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
288 tabs_cont.addFooter(grid_wid)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
289
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 796
diff changeset
290 super(XMLUI, self).constructUI(xml_data, postTreat)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 796
diff changeset
291 urwid.WidgetWrap.__init__(self, self.main_cont)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
292
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
293 def show(self, show_type=None, valign='middle'):
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
294 """Show the constructed UI
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
295 @param show_type: how to show the UI:
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
296 - None (follow XMLUI's recommendation)
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
297 - 'popup'
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
298 - 'window'
687
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 655
diff changeset
299 @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
300 Ignored when show_type is 'window'.
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
301
687
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 655
diff changeset
302 """
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
303 if show_type is None:
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
304 if self.type in ('window', 'param'):
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
305 show_type = 'window'
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
306 elif self.type in ('popup', 'form'):
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
307 show_type = 'popup'
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
308
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
309 if show_type not in ('popup', 'window'):
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
310 raise ValueError('Invalid show_type [%s]' % show_type)
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
311
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
312 self._dest = show_type
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
313 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
314 if show_type == 'popup':
687
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 655
diff changeset
315 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
316 elif show_type == 'window':
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
317 self.host.addWindow(decorated)
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
318 else:
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
319 assert(False)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
320 self.host.redraw()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
321
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
322
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
323 def _xmluiClose(self):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
324 if self._dest == 'window':
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
325 self.host.removeWindow()
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
326 else:
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
327 self.host.removePopUp()