Mercurial > libervia-backend
annotate frontends/src/primitivus/xmlui.py @ 796:46aa5ada61bf
core, frontends: XMLUI refactoring:
- now there is a base XMLUI class. Frontends inherits from this class, and add their specific widgets/containers/behaviour
- wix: param.py has been removed, as the same behaviour has been reimplemented through XMLUI
- removed "misc" argument in XMLUI.__init__
- severals things are broken (gateway, directory search), following patches will fix them
- core: elements names in xml_tools.dataForm2XMLUI now use a construction with category_name/param_name to avoid name conflicts (could happen with 2 parameters of the same name in differents categories).
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 04 Feb 2014 18:02:35 +0100 |
parents | bfabeedbf32e |
children | 9007bb133009 |
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 | 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 | 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 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
25 from sat_frontends.tools import xmlui |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
26 |
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 class PrimitivusEvents(object): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
29 """ Used to manage change event of Primitivus widgets """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
30 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
31 def _change_callback(self, ctrl, *args, **kwargs): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
32 """" Call xmlui callback and ignore any extra argument """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
33 args[-1](ctrl) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
34 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
35 def _xmluiOnChange(self, callback): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
36 """ Call callback with widget as only argument """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
37 urwid.connect_signal(self, 'change', self._change_callback, callback) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
38 |
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 class PrimitivusEmptyWidget(xmlui.EmptyWidget, urwid.Text): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
41 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
42 def __init__(self, parent): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
43 urwid.Text.__init__(self, '') |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
44 |
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 class PrimitivusTextWidget(xmlui.TextWidget, urwid.Text): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
47 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
48 def __init__(self, parent, value): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
49 urwid.Text.__init__(self, value) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
50 |
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 class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
53 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
54 def __init__(self, parent, value): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
55 sat_widgets.AdvancedEdit.__init__(self, edit_text=value) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
56 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
57 def _xmluiGetValue(self): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
58 return self.get_edit_text() |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
59 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
60 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
61 class PrimitivusPasswordWidget(xmlui.PasswordWidget, sat_widgets.Password, PrimitivusEvents): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
62 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
63 def __init__(self, parent, value): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
64 sat_widgets.Password.__init__(self, edit_text=value) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
65 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
66 def _xmluiGetValue(self): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
67 return self.get_edit_text() |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 |
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
|
69 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
70 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
|
71 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
72 def __init__(self, parent, value): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
73 sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
74 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
75 def _xmluiGetValue(self): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
76 return self.getValue() |
632
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
77 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
78 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
79 class PrimitivusBoolWidget(xmlui.BoolWidget, urwid.CheckBox, PrimitivusEvents): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
80 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
81 def __init__(self, parent, state): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
82 urwid.CheckBox.__init__(self, '', state = state) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
83 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
84 def _xmluiGetValue(self): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
85 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
|
86 |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
632
diff
changeset
|
87 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
88 class PrimitivusButtonWidget(xmlui.ButtonWidget, sat_widgets.CustomButton, PrimitivusEvents): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
89 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
90 def __init__(self, parent, value, click_callback): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
91 sat_widgets.CustomButton.__init__(self, value, on_press=click_callback) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
92 |
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 class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
95 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
96 def __init__(self, parent, options, flags): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
97 sat_widgets.List.__init__(self, options=options, style=flags) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
98 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
99 def _xmluiSelectValue(self, value): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
100 return self.selectValue(value) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
102 def _xmluiGetSelectedValues(self): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
103 return [option.value for option in self.getSelectedValues()] |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
104 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
105 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
106 class PrimitivusAdvancedListWidget(PrimitivusListWidget, PrimitivusEvents): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
107 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
108 def __init__(self, parent, options, flags): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
109 sat_widgets.List.__init__(self, options=options, style=flags, max_height=20) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
110 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
111 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
112 class PrimitivusPairsContainer(xmlui.PairsContainer, urwid.WidgetWrap): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
113 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
114 def __init__(self, parent, weight_0='1', weight_1='1'): |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 self.idx = 0 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 self.weight_0 = weight_0 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 self.weight_1 = weight_1 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 columns = urwid.Columns([urwid.Text(''), urwid.Text('')]) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 #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
|
120 urwid.WidgetWrap.__init__(self,columns) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
122 def _xmluiAppend(self, widget): |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 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
|
124 if isinstance(pile, urwid.Text): |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 self._w.widget_list[self.idx] = urwid.Pile([widget]) |
149 | 126 if self.idx == 1: |
127 self._w.set_focus(1) | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 else: |
610
c8c07c920e30
Primitivus: fixed xmlui/chat bad contents change
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
129 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
|
130 self.idx = (self.idx + 1) % 2 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
131 |
796
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 class PrimitivusTabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer): |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
135 def __init__(self, parent): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
136 sat_widgets.TabsContainer.__init__(self) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
137 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
138 def _xmluiAppend(self, widget): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
139 self.body.append(widget) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
140 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
141 def _xmluiAddTab(self, label): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
142 list_box = super(PrimitivusTabsContainer, self).addTab(label) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
143 if hasattr(PrimitivusVerticalContainer, "_PrimitivusVerticalContainer__super"): # workaround for Urwid's metaclass baviour |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
144 del PrimitivusVerticalContainer._PrimitivusVerticalContainer__super |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
145 PrimitivusVerticalContainer._xmluiAdapt(list_box) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
146 return list_box |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
147 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
148 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
149 class PrimitivusVerticalContainer(xmlui.VerticalContainer, urwid.ListBox): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
150 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
152 def __init__(self, parent): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
153 urwid.ListBox.__init__(self, urwid.SimpleListWalker([])) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
154 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
155 def _xmluiAppend(self, widget): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
156 self.body.append(widget) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
157 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
158 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
159 class WidgetFactory(object): |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
161 def __getattr__(self, attr): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
162 if attr.startswith("create"): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
163 return 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 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
164 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
165 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
166 class XMLUI(xmlui.XMLUI, urwid.WidgetWrap): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
167 widget_factory = WidgetFactory() |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
168 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
169 def __init__(self, host, xml_data, title = None, flags = None): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
170 self._dest = "window" |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
171 xmlui.XMLUI.__init__(self, host, xml_data, title, flags) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 def constructUI(self, xml_data): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
174 def postTreat(ret_wid): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
175 assert ret_wid.body |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
176 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
177 if isinstance(ret_wid.body[0],sat_widgets.TabsContainer): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
178 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
|
179 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
180 if self.type == 'form': |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
181 buttons = [] |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
182 buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted)) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
183 if not 'NO_CANCEL' in self.flags: |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
184 buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled)) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
185 max_len = max([len(button.get_label()) for button in buttons]) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
186 grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center') |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
187 ret_wid.body.append(grid_wid) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
188 elif self.type == 'param': |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
189 assert(isinstance(ret_wid,sat_widgets.TabsContainer)) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
190 buttons = [] |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
191 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams)) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
192 buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow())) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
193 max_len = max([button.getSize() for button in buttons]) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
194 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center') |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
195 ret_wid.addFooter(grid_wid) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
196 return ret_wid |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
197 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
198 widget = super(XMLUI, self).constructUI(xml_data, postTreat) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
199 urwid.WidgetWrap.__init__(self, widget) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 |
687
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
655
diff
changeset
|
201 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
|
202 """Show the constructed UI |
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
203 @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
|
204 - popup |
687
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
655
diff
changeset
|
205 - window |
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
655
diff
changeset
|
206 @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
|
207 Ignored when show_type is 'window'. |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
208 |
687
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
655
diff
changeset
|
209 """ |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
210 self._dest = "popup" |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
211 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
|
212 if show_type == 'popup': |
687
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
655
diff
changeset
|
213 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
|
214 elif show_type == 'window': |
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
215 self.host.addWindow(decorated) |
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
216 else: |
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
217 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
|
218 assert(False) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 self.host.redraw() |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
222 def _xmluiClose(self): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
223 if self._dest == 'window': |
170
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
224 self.host.removeWindow() |
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
225 else: |
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
226 self.host.removePopUp() |