Mercurial > libervia-backend
annotate frontends/src/primitivus/xmlui.py @ 1501:cb1b0fe10415
frontends (xmlui): fixed a bug in xmlui resulting in a bad dialog creation (parameters were lost, including profile)
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 27 Aug 2015 17:59:01 +0200 |
parents | a77217511afd |
children | 8c071bc359c9 |
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 |
1396 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 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 |
976
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
22 import copy |
1185
6184779544c7
Primitivus (xmlui): fixed window closing on save params + removed now unused onConfigureRoom in Chat
Goffi <goffi@goffi.org>
parents:
1106
diff
changeset
|
23 from sat.core import exceptions |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
24 from urwid_satext import sat_widgets |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
25 from urwid_satext import files_management |
1010
73a0b7f94674
primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents:
976
diff
changeset
|
26 from sat.core.log import getLogger |
73a0b7f94674
primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents:
976
diff
changeset
|
27 log = getLogger(__name__) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
28 from sat_frontends.primitivus.constants import Const as C |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
29 from sat_frontends.primitivus.widget import PrimitivusWidget |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
30 from sat_frontends.tools import xmlui |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
31 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
32 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
33 class PrimitivusEvents(object): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
34 """ Used to manage change event of Primitivus widgets """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
35 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
36 def _event_callback(self, ctrl, *args, **kwargs): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
37 """" Call xmlui callback and ignore any extra argument """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
38 args[-1](ctrl) |
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 def _xmluiOnChange(self, callback): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
41 """ Call callback with widget as only argument """ |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
42 urwid.connect_signal(self, 'change', self._event_callback, callback) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
43 |
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 class PrimitivusEmptyWidget(xmlui.EmptyWidget, urwid.Text): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
46 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
47 def __init__(self, _xmlui_parent): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
48 urwid.Text.__init__(self, '') |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
49 |
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 class PrimitivusTextWidget(xmlui.TextWidget, urwid.Text): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
52 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
53 def __init__(self, _xmlui_parent, value, read_only=False): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
54 urwid.Text.__init__(self, value) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
55 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
56 |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
57 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
|
58 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
59 def __init__(self, _xmlui_parent, value): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
60 super(PrimitivusLabelWidget, self).__init__(_xmlui_parent, value+": ") |
804
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 PrimitivusJidWidget(xmlui.JidWidget, PrimitivusTextWidget): |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
64 pass |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
65 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
66 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
67 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
|
68 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
69 def __init__(self, _xmlui_parent, style='line'): |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
70 if style == 'line': |
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 == 'dot': |
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 == 'dash': |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
75 div_char = u'-' |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
76 elif style == 'plain': |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
77 div_char = u'█' |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
78 elif style == 'blank': |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
79 div_char = ' ' |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
80 else: |
1010
73a0b7f94674
primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents:
976
diff
changeset
|
81 log.warning(_("Unknown div_char")) |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
82 div_char = u'─' |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
83 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
84 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
|
85 |
976
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
86 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
87 class PrimitivusStringWidget(xmlui.StringWidget, sat_widgets.AdvancedEdit, PrimitivusEvents): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
88 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
89 def __init__(self, _xmlui_parent, value, read_only=False): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
90 sat_widgets.AdvancedEdit.__init__(self, edit_text=value) |
1085
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
91 self.read_only = read_only |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
92 |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
93 def selectable(self): |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
94 if self.read_only: |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
95 return False |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
96 return super(PrimitivusStringWidget, self).selectable() |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
97 |
976
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
98 def _xmluiSetValue(self, value): |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
99 self.set_edit_text(value) |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
100 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
101 def _xmluiGetValue(self): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
102 return self.get_edit_text() |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
103 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
104 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
105 class PrimitivusJidInputWidget(xmlui.JidInputWidget, PrimitivusStringWidget): |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
106 pass |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
107 |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
108 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
109 class PrimitivusPasswordWidget(xmlui.PasswordWidget, sat_widgets.Password, PrimitivusEvents): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
110 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
111 def __init__(self, _xmlui_parent, value, read_only=False): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
112 sat_widgets.Password.__init__(self, edit_text=value) |
1085
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
113 self.read_only = read_only |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
114 |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
115 def selectable(self): |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
116 if self.read_only: |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
117 return False |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
118 return super(PrimitivusPasswordWidget, self).selectable() |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
119 |
976
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
120 def _xmluiSetValue(self, value): |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
121 self.set_edit_text(value) |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
122 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
123 def _xmluiGetValue(self): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
124 return self.get_edit_text() |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 |
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
|
126 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
127 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
|
128 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
129 def __init__(self, _xmlui_parent, value, read_only=False): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
130 sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True) |
1085
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
131 self.read_only = read_only |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
132 |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
133 def selectable(self): |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
134 if self.read_only: |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
135 return False |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
136 return super(PrimitivusTextBoxWidget, self).selectable() |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
137 |
976
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
138 def _xmluiSetValue(self, value): |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
139 self.set_edit_text(value) |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
140 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
141 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
|
142 return self.get_edit_text() |
632
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
143 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
144 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
145 class PrimitivusBoolWidget(xmlui.BoolWidget, urwid.CheckBox, PrimitivusEvents): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
146 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
147 def __init__(self, _xmlui_parent, state, read_only=False): |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
912
diff
changeset
|
148 urwid.CheckBox.__init__(self, '', state=state) |
1085
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
149 self.read_only = read_only |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
150 |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
151 def selectable(self): |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
152 if self.read_only: |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
153 return False |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
1070
diff
changeset
|
154 return super(PrimitivusBoolWidget, self).selectable() |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
155 |
976
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
156 def _xmluiSetValue(self, value): |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
157 self.set_state(value == "true") |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
158 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
159 def _xmluiGetValue(self): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
160 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
|
161 |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
632
diff
changeset
|
162 |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
163 class PrimitivusIntWidget(xmlui.IntWidget, sat_widgets.AdvancedEdit, PrimitivusEvents): |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
164 |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
165 def __init__(self, _xmlui_parent, value, read_only=False): |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
166 sat_widgets.AdvancedEdit.__init__(self, edit_text=value) |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
167 self.read_only = read_only |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
168 |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
169 def selectable(self): |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
170 if self.read_only: |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
171 return False |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
172 return super(PrimitivusIntWidget, self).selectable() |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
173 |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
174 def _xmluiSetValue(self, value): |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
175 self.set_edit_text(value) |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
176 |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
177 def _xmluiGetValue(self): |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
178 return self.get_edit_text() |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
179 |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1185
diff
changeset
|
180 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
181 class PrimitivusButtonWidget(xmlui.ButtonWidget, sat_widgets.CustomButton, PrimitivusEvents): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
182 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
183 def __init__(self, _xmlui_parent, value, click_callback): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
184 sat_widgets.CustomButton.__init__(self, value, on_press=click_callback) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
185 |
976
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
186 def _xmluiOnClick(self, callback): |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
187 urwid.connect_signal(self, 'click', callback) |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
188 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
189 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
190 class PrimitivusListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
191 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
192 def __init__(self, _xmlui_parent, options, selected, flags): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
193 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
|
194 self._xmluiSelectValues(selected) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
195 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
196 def _xmluiSelectValue(self, value): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
197 return self.selectValue(value) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
912
diff
changeset
|
199 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
|
200 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
|
201 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
202 def _xmluiGetSelectedValues(self): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
203 return [option.value for option in self.getSelectedValues()] |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
204 |
976
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
205 def _xmluiAddValues(self, values, select=True): |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
206 current_values = self.getAllValues() |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
207 new_values = copy.deepcopy(current_values) |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
208 for value in values: |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
209 if value not in current_values: |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
210 new_values.append(value) |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
211 if select: |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
212 selected = self._xmluiGetSelectedValues() |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
213 self.changeValues(new_values) |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
214 if select: |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
215 for value in values: |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
216 if value not in selected: |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
217 selected.append(value) |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
218 self._xmluiSelectValues(selected) |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
219 |
1478
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
220 class PrimitivusJidsListWidget(xmlui.ListWidget, sat_widgets.List, PrimitivusEvents): |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
221 |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
222 def __init__(self, _xmlui_parent, jids, styles): |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
223 sat_widgets.List.__init__(self, options=jids+[''], # the empty field is here to add new jids if needed |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
224 option_type=lambda txt, align: sat_widgets.AdvancedEdit(edit_text=txt, align=align), |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
225 on_change=self._onChange) |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
226 self.delete=0 |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
227 |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
228 def _onChange(self, list_widget, jid_widget=None, text=None): |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
229 if jid_widget is not None: |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
230 if jid_widget != list_widget.contents[-1] and not text: |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
231 # if a field is empty, we delete the line (except for the last line) |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
232 list_widget.contents.remove(jid_widget) |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
233 elif jid_widget == list_widget.contents[-1] and text: |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
234 # we always want an empty field as last value to be able to add jids |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
235 list_widget.contents.append(sat_widgets.AdvancedEdit()) |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
236 |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
237 def _xmluiGetSelectedValues(self): |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
238 # XXX: there is not selection in this list, so we return all non empty values |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
239 return [jid_ for jid_ in self.getAllValues() if jid_] |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
240 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
241 |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
242 class PrimitivusAdvancedListContainer(xmlui.AdvancedListContainer, sat_widgets.TableContainer, PrimitivusEvents): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
243 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
244 def __init__(self, _xmlui_parent, columns, selectable='no'): |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
245 options = {'ADAPT':()} |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
246 if selectable != 'no': |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
247 options['HIGHLIGHT'] = () |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
248 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
|
249 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
250 def _xmluiAppend(self, widget): |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
251 self.addWidget(widget) |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
252 |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
253 def _xmluiAddRow(self, idx): |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
254 self.setRowIndex(idx) |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
255 |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
256 def _xmluiGetSelectedWidgets(self): |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
257 return self.getSelectedWidgets() |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
258 |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
259 def _xmluiGetSelectedIndex(self): |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
260 return self.getSelectedIndex() |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
261 |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
262 def _xmluiOnSelect(self, callback): |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
263 """ Call callback with widget as only argument """ |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
264 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
|
265 |
976
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
266 |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
267 class PrimitivusPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer): |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
268 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
269 def __init__(self, _xmlui_parent): |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
270 options = {'ADAPT':(0,), 'HIGHLIGHT':(0,)} |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
271 if self._xmlui_main.type == 'param': |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
272 options['FOCUS_ATTR'] = 'param_selected' |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
273 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
|
274 |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
275 def _xmluiAppend(self, widget): |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
276 if isinstance(widget, PrimitivusEmptyWidget): |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
277 # 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
|
278 widget = urwid.AttrMap(widget, 'default') |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
279 self.addWidget(widget) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
280 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
281 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
282 class PrimitivusTabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer): |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
284 def __init__(self, _xmlui_parent): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
285 sat_widgets.TabsContainer.__init__(self) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
286 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
287 def _xmluiAppend(self, widget): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
288 self.body.append(widget) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
289 |
1486
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1478
diff
changeset
|
290 def _xmluiAddTab(self, label, selected): |
912
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
291 tab = PrimitivusVerticalContainer(None) |
1486
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1478
diff
changeset
|
292 self.addTab(label, tab, selected) |
912
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
293 return tab |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
294 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
295 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
296 class PrimitivusVerticalContainer(xmlui.VerticalContainer, urwid.ListBox): |
912
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
297 BOX_HEIGHT = 5 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
298 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
299 def __init__(self, _xmlui_parent): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
300 urwid.ListBox.__init__(self, urwid.SimpleListWalker([])) |
912
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
301 self._last_size = None |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
302 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
303 def _xmluiAppend(self, widget): |
912
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
304 if 'flow' not in widget.sizing(): |
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
305 widget = urwid.BoxAdapter(widget, self.BOX_HEIGHT) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
306 self.body.append(widget) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
307 |
912
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
308 def render(self, size, focus=False): |
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
309 if size != self._last_size: |
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
310 (maxcol, maxrow) = size |
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
311 if self.body: |
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
312 widget = self.body[0] |
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
313 if isinstance(widget, urwid.BoxAdapter): |
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
314 widget.height = maxrow |
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
315 self._last_size = size |
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
316 return super(PrimitivusVerticalContainer, self).render(size, focus) |
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
317 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
318 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
319 ### Dialogs ### |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
320 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
321 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
322 class PrimitivusDialog(object): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
323 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
324 def __init__(self, _xmlui_parent): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
325 self.host = _xmlui_parent.host |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
326 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
327 def _xmluiShow(self): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
328 self.host.showPopUp(self) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
329 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
330 def _xmluiClose(self): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
331 self.host.removePopUp() |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
332 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
333 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
334 class PrimitivusMessageDialog(PrimitivusDialog, xmlui.MessageDialog, sat_widgets.Alert): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
335 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
336 def __init__(self, _xmlui_parent, title, message, level): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
337 PrimitivusDialog.__init__(self, _xmlui_parent) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
338 xmlui.MessageDialog.__init__(self, _xmlui_parent) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
339 sat_widgets.Alert.__init__(self, title, message, ok_cb=lambda dummy: self._xmluiValidated()) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
340 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
341 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
342 class PrimitivusNoteDialog(xmlui.NoteDialog, PrimitivusMessageDialog): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
343 # TODO: separate NoteDialog |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
344 pass |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
345 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
346 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
347 class PrimitivusConfirmDialog(PrimitivusDialog, xmlui.ConfirmDialog, sat_widgets.ConfirmDialog): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
348 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
349 def __init__(self, _xmlui_parent, title, message, level, buttons_set): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
350 PrimitivusDialog.__init__(self, _xmlui_parent) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
351 xmlui.ConfirmDialog.__init__(self, _xmlui_parent) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
352 sat_widgets.ConfirmDialog.__init__(self, title, message, no_cb=lambda dummy: self._xmluiCancelled(), yes_cb=lambda dummy: self._xmluiValidated()) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
353 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
354 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
355 class PrimitivusFileDialog(PrimitivusDialog, xmlui.FileDialog, files_management.FileDialog): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
356 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
357 def __init__(self, _xmlui_parent, title, message, level, filetype): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
358 # TODO: message is not managed yet |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
359 PrimitivusDialog.__init__(self, _xmlui_parent) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
360 xmlui.FileDialog.__init__(self, _xmlui_parent) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
361 style = [] |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
362 if filetype == C.XMLUI_DATA_FILETYPE_DIR: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
363 style.append('dir') |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
364 files_management.FileDialog.__init__(self, ok_cb=lambda path: self._xmluiValidated({'path': path}), cancel_cb=lambda dummy: self._xmluiCancelled(), title=title) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
365 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
366 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
367 class GenericFactory(object): |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
369 def __getattr__(self, attr): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
370 if attr.startswith("create"): |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
371 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 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
372 return cls |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
373 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
374 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
375 class WidgetFactory(GenericFactory): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
376 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
377 def __getattr__(self, attr): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
378 if attr.startswith("create"): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
379 cls = GenericFactory.__getattr__(self, attr) |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
380 cls._xmlui_main = self._xmlui_main |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
381 return cls |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
382 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
383 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
384 class XMLUIPanel(xmlui.XMLUIPanel, PrimitivusWidget): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
385 widget_factory = WidgetFactory() |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
386 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
387 def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
388 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
|
389 self._dest = None |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
390 xmlui.XMLUIPanel.__init__(self, host, parsed_xml, title, flags, callback, profile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
391 PrimitivusWidget.__init__(self, self.main_cont, self.xmlui_title) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
393 def constructUI(self, parsed_dom): |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
394 def postTreat(): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
395 assert self.main_cont.body |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
396 |
976
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
397 if self.type in ('form', 'popup'): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
398 buttons = [] |
976
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
399 if self.type == 'form': |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
400 buttons.append(urwid.Button(_('Submit'), self.onFormSubmitted)) |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
401 if not 'NO_CANCEL' in self.flags: |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
402 buttons.append(urwid.Button(_('Cancel'), self.onFormCancelled)) |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
403 else: |
68faf7d77a42
frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
404 buttons.append(urwid.Button(_('OK'), lambda dummy: self._xmluiClose())) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
405 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
|
406 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
|
407 self.main_cont.body.append(grid_wid) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
408 elif self.type == 'param': |
912
b70fb2ac5997
primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
409 tabs_cont = self.main_cont.body[0].base_widget |
1478
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
410 assert isinstance(tabs_cont,sat_widgets.TabsContainer) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
411 buttons = [] |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
412 buttons.append(sat_widgets.CustomButton(_('Save'),self.onSaveParams)) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
413 buttons.append(sat_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow())) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
414 max_len = max([button.getSize() for button in buttons]) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
415 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
|
416 tabs_cont.addFooter(grid_wid) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
417 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
418 xmlui.XMLUIPanel.constructUI(self, parsed_dom, postTreat) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
419 urwid.WidgetWrap.__init__(self, self.main_cont) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
421 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
|
422 """Show the constructed UI |
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
423 @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
|
424 - 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
|
425 - 'popup' |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
426 - 'window' |
687
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
655
diff
changeset
|
427 @param valign: vertical alignment when show_type is 'popup'. |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
428 Ignored when show_type is 'window'. |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
429 |
687
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
655
diff
changeset
|
430 """ |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
431 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
|
432 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
|
433 show_type = 'window' |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
434 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
|
435 show_type = 'popup' |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
436 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
437 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
|
438 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
|
439 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
440 self._dest = show_type |
170
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
441 if show_type == 'popup': |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
442 self.host.showPopUp(self, valign=valign) |
170
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
443 elif show_type == 'window': |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
444 self.host.newWidget(self) |
170
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
445 else: |
1478
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
446 assert False |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
447 self.host.redraw() |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
448 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
449 def _xmluiClose(self): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
450 if self._dest == 'window': |
170
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
451 self.host.removeWindow() |
1185
6184779544c7
Primitivus (xmlui): fixed window closing on save params + removed now unused onConfigureRoom in Chat
Goffi <goffi@goffi.org>
parents:
1106
diff
changeset
|
452 elif self._dest == 'popup': |
6184779544c7
Primitivus (xmlui): fixed window closing on save params + removed now unused onConfigureRoom in Chat
Goffi <goffi@goffi.org>
parents:
1106
diff
changeset
|
453 self.host.removePopUp() |
170
2ea8dab08160
Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents:
167
diff
changeset
|
454 else: |
1185
6184779544c7
Primitivus (xmlui): fixed window closing on save params + removed now unused onConfigureRoom in Chat
Goffi <goffi@goffi.org>
parents:
1106
diff
changeset
|
455 raise exceptions.InternalError("self._dest unknown, are you sure you have called XMLUI.show ?") |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
456 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
457 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
458 class XMLUIDialog(xmlui.XMLUIDialog): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
459 dialog_factory = GenericFactory() |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
460 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
461 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
462 xmlui.registerClass(xmlui.CLASS_PANEL, XMLUIPanel) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
463 xmlui.registerClass(xmlui.CLASS_DIALOG, XMLUIDialog) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
464 create = xmlui.create |