Mercurial > libervia-backend
annotate frontends/src/tools/xmlui.py @ 1473:675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 18 Aug 2015 10:35:44 +0200 |
parents | 069ad98b360d |
children | 90130847a0a8 |
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 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
4 # SàT frontend tools |
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 _ |
1087
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
21 from sat.core.log import getLogger |
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
22 log = getLogger(__name__) |
1327
89dc29afe01c
frontends: merge sat_frontends.constants to sat_frontends.quick_frontend.constants
souliane <souliane@mailoo.org>
parents:
1290
diff
changeset
|
23 from sat_frontends.quick_frontend.constants import Const as C |
864
241f6baa6687
frontends: fix typos, do not use logging in the xmlui tools:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
24 from sat.core.exceptions import DataError |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
762
aed7d99276b8
core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents:
760
diff
changeset
|
26 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
27 class_map = {} |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
28 CLASS_PANEL = 'panel' |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
29 CLASS_DIALOG = 'dialog' |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
30 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
31 class InvalidXMLUI(Exception): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
32 pass |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
33 |
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
|
34 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
35 class ClassNotRegistedError(Exception): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
36 pass |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
37 |
632
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
38 def getText(node): |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
39 """Get child text nodes |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
40 @param node: dom Node |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
41 @return: joined unicode text of all nodes |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
42 |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
43 """ |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
44 data = [] |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
45 for child in node.childNodes: |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
46 if child.nodeType == child.TEXT_NODE: |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
47 data.append(child.wholeText) |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
48 return u"".join(data) |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
49 |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
632
diff
changeset
|
50 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
51 class Widget(object): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
52 """base Widget""" |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
53 pass |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
56 class EmptyWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
57 """Just a placeholder widget""" |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
58 pass |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
59 |
796
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 TextWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
62 """Non interactive text""" |
152
b1f1955d96b3
Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents:
149
diff
changeset
|
63 pass |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
65 |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
66 class LabelWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
67 """Non interactive text""" |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
68 pass |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
69 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
70 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
71 class JidWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
72 """Jabber ID""" |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
73 pass |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
74 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
75 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
76 class DividerWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
77 """Separator""" |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
78 pass |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
79 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
80 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
81 class StringWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
82 """Input widget wich require a string |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
83 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
84 often called Edit in toolkits |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
85 """ |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
86 pass |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
87 |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
88 |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
89 class JidInputWidget(Widget): |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
90 """Input widget wich require a string |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
91 |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
92 often called Edit in toolkits |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
93 """ |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
94 pass |
796
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 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
97 class PasswordWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
98 """Input widget with require a masked string""" |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
99 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
100 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
101 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
102 class TextBoxWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
103 """Input widget with require a long, possibly multilines string |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
104 often called TextArea in toolkits |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
105 """ |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
106 pass |
796
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 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
109 class BoolWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
110 """Input widget with require a boolean value |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
111 often called CheckBox in toolkits |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
112 """ |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
113 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
114 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
115 |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1109
diff
changeset
|
116 class IntWidget(Widget): |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1109
diff
changeset
|
117 """Input widget with require an integer""" |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
118 pass |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1109
diff
changeset
|
119 |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1109
diff
changeset
|
120 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
121 class ButtonWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
122 """A clickable widget""" |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
123 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
124 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
125 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
126 class ListWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
127 """A widget able to show/choose one or several strings in a list""" |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
128 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
129 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
130 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
131 class Container(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
132 """Widget which can contain other ones with a specific layout""" |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
133 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
134 @classmethod |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
135 def _xmluiAdapt(cls, instance): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
136 """Make cls as instance.__class__ |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
137 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
138 cls must inherit from original instance class |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
139 Usefull when you get a class from UI toolkit |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
140 """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
141 assert instance.__class__ in cls.__bases__ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
142 instance.__class__ = type(cls.__name__, cls.__bases__, dict(cls.__dict__)) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
143 |
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 PairsContainer(Container): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
146 """Widgets are disposed in rows of two (usually label/input) """ |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
147 pass |
796
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 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
150 class TabsContainer(Container): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
151 """A container which several other containers in tabs |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
152 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
153 Often called Notebook in toolkits |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
154 """ |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
155 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
156 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
157 class VerticalContainer(Container): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
158 """Widgets are disposed vertically""" |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
159 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
160 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
161 |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
162 class AdvancedListContainer(Container): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
163 """Widgets are disposed in rows with advaned features""" |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
164 pass |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
165 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
166 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
167 class Dialog(object): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
168 """base dialog""" |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
169 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
170 def __init__(self, _xmlui_parent): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
171 self._xmlui_parent = _xmlui_parent |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
172 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
173 def _xmluiValidated(self, data=None): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
174 if data is None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
175 data = {} |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
176 self._xmluiSetData(C.XMLUI_STATUS_VALIDATED, data) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
177 self._xmluiSubmit(data) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
178 self._xmluiClose() |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
179 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
180 def _xmluiCancelled(self): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
181 data = {C.XMLUI_DATA_CANCELLED: C.BOOL_TRUE} |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
182 self._xmluiSetData(C.XMLUI_STATUS_CANCELLED, data) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
183 self._xmluiSubmit(data) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
184 self._xmluiClose() |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
185 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
186 def _xmluiSubmit(self, data): |
1109
0a448c947038
frontends: dialog don't crash anymore is no submit_id is given (submit does nothing in this case)
Goffi <goffi@goffi.org>
parents:
1106
diff
changeset
|
187 if self._xmlui_parent.submit_id is None: |
0a448c947038
frontends: dialog don't crash anymore is no submit_id is given (submit does nothing in this case)
Goffi <goffi@goffi.org>
parents:
1106
diff
changeset
|
188 log.debug(_("Nothing to submit")) |
0a448c947038
frontends: dialog don't crash anymore is no submit_id is given (submit does nothing in this case)
Goffi <goffi@goffi.org>
parents:
1106
diff
changeset
|
189 else: |
0a448c947038
frontends: dialog don't crash anymore is no submit_id is given (submit does nothing in this case)
Goffi <goffi@goffi.org>
parents:
1106
diff
changeset
|
190 self._xmlui_parent.submit(data) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
191 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
192 def _xmluiSetData(self, status, data): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
193 pass |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
194 |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
195 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
196 class MessageDialog(Dialog): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
197 """Dialog with a OK/Cancel type configuration""" |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
198 pass |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
199 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
200 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
201 class NoteDialog(Dialog): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
202 """Dialog with a OK/Cancel type configuration""" |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
203 pass |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
204 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
205 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
206 class ConfirmDialog(Dialog): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
207 """Dialog with a OK/Cancel type configuration""" |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
208 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
209 def _xmluiSetData(self, status, data): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
210 if status == C.XMLUI_STATUS_VALIDATED: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
211 data[C.XMLUI_DATA_ANSWER] = C.BOOL_TRUE |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
212 elif status == C.XMLUI_STATUS_CANCELLED: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
213 data[C.XMLUI_DATA_ANSWER] = C.BOOL_FALSE |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
214 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
215 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
216 class FileDialog(Dialog): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
217 """Dialog with a OK/Cancel type configuration""" |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
218 pass |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
219 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
220 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
221 class XMLUIBase(object): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
222 """Base class to construct SàT XML User Interface |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
223 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
224 This class must not be instancied directly |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
225 """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
226 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
227 def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
228 """Initialise the XMLUI instance |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
229 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
230 @param host: %(doc_host)s |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
231 @param parsed_dom: main parsed dom |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
232 @param title: force the title, or use XMLUI one if None |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
233 @param flags: list of string which can be: |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
234 - NO_CANCEL: the UI can't be cancelled |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
235 @param callback: if present, will be used with launchAction |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
236 """ |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 self.host = host |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
238 top=parsed_dom.documentElement |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
239 self.session_id = top.getAttribute("session_id") or None |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
240 self.submit_id = top.getAttribute("submit") or None |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
241 self.xmlui_title = title or top.getAttribute("title") or u"" |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
242 if flags is None: |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
243 flags = [] |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
244 self.flags = flags |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
245 self.callback = callback |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
246 self.profile = profile |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
247 |
1085
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
248 def _isAttrSet(self, name, node): |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
249 """Returnw widget boolean attribute status |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
250 |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
251 @param name: name of the attribute (e.g. "read_only") |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
252 @param node: Node instance |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
253 @return (bool): True if widget's attribute is set (C.BOOL_TRUE) |
1085
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
254 """ |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
255 read_only = node.getAttribute(name) or C.BOOL_FALSE |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
256 return read_only.lower().strip() == C.BOOL_TRUE |
1085
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
257 |
1086
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
258 def _getChildNode(self, node, name): |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
259 """Return the first child node with the given name |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
260 |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
261 @param node: Node instance |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
262 @param name: name of the wanted node |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
263 |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
264 @return: The found element or None |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
265 """ |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
266 for child in node.childNodes: |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
267 if child.nodeName == name: |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
268 return child |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
269 return None |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
270 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
271 def submit(self, data): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
272 if self.submit_id is None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
273 raise ValueError("Can't submit is self.submit_id is not set") |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
274 if "session_id" in data: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
275 raise ValueError("session_id must no be used in data, it is automaticaly filled with self.session_id if present") |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
276 if self.session_id is not None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
277 data["session_id"] = self.session_id |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
278 self._xmluiLaunchAction(self.submit_id, data) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
279 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
280 def _xmluiLaunchAction(self, action_id, data): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
281 self.host.launchAction(action_id, data, callback=self.callback, profile=self.profile) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
282 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
283 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
284 class XMLUIPanel(XMLUIBase): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
285 """XMLUI Panel |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
286 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
287 New frontends can inherite this class to easily implement XMLUI |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
288 @property widget_factory: factory to create frontend-specific widgets |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
289 @proporety dialog_factory: factory to create frontend-specific dialogs |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
290 """ |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
291 widget_factory = None |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
292 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
293 def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
294 super(XMLUIPanel, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
295 self.ctrl_list = {} # usefull to access ctrl |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
296 self._main_cont = None |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
297 self.constructUI(parsed_dom) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
298 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
299 def escape(self, name): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
300 """Return escaped name for forms""" |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
301 return u"%s%s" % (C.SAT_FORM_PREFIX, name) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
302 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
303 @property |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
304 def main_cont(self): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
305 return self._main_cont |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
306 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
307 @main_cont.setter |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
308 def main_cont(self, value): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
309 if self._main_cont is not None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
310 raise ValueError(_("XMLUI can have only one main container")) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
311 self._main_cont = value |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
312 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
313 def _parseChilds(self, _xmlui_parent, current_node, wanted = ('container',), data = None): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
314 """Recursively parse childNodes of an element |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
315 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
316 @param _xmlui_parent: widget container with '_xmluiAppend' method |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
317 @param current_node: element from which childs will be parsed |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
318 @param wanted: list of tag names that can be present in the childs to be SàT XMLUI compliant |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
319 @param data: additionnal data which are needed in some cases |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
320 """ |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
321 for node in current_node.childNodes: |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 if wanted and not node.nodeName in wanted: |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
323 raise InvalidXMLUI('Unexpected node: [%s]' % node.nodeName) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
324 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
325 if node.nodeName == "container": |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
326 type_ = node.getAttribute('type') |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
327 if _xmlui_parent is self and type_ != 'vertical': |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
328 # main container is not a VerticalContainer and we want one, so we create one to wrap it |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
329 _xmlui_parent = self.widget_factory.createVerticalContainer(self) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
330 self.main_cont = _xmlui_parent |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
331 if type_ == "tabs": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
332 cont = self.widget_factory.createTabsContainer(_xmlui_parent) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
333 self._parseChilds(_xmlui_parent, node, ('tab',), cont) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
334 elif type_ == "vertical": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
335 cont = self.widget_factory.createVerticalContainer(_xmlui_parent) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
336 self._parseChilds(cont, node, ('widget', 'container')) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
337 elif type_ == "pairs": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
338 cont = self.widget_factory.createPairsContainer(_xmlui_parent) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
339 self._parseChilds(cont, node, ('widget', 'container')) |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
340 elif type_ == "advanced_list": |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
341 try: |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
342 columns = int(node.getAttribute('columns')) |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
343 except (TypeError, ValueError): |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
344 raise DataError("Invalid columns") |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
345 selectable = node.getAttribute('selectable') or 'no' |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
346 auto_index = node.getAttribute('auto_index') == C.BOOL_TRUE |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
347 data = {'index': 0} if auto_index else None |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
348 cont = self.widget_factory.createAdvancedListContainer(_xmlui_parent, columns, selectable) |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
349 callback_id = node.getAttribute("callback") or None |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
350 if callback_id is not None: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
351 if selectable == 'no': |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
352 raise ValueError("can't have selectable=='no' and callback_id at the same time") |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
353 cont._xmlui_callback_id = callback_id |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
354 cont._xmluiOnSelect(self.onAdvListSelect) |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
355 |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
356 self._parseChilds(cont, node, ('row',), data) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 else: |
1087
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
358 log.warning(_("Unknown container [%s], using default one") % type_) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
359 cont = self.widget_factory.createVerticalContainer(_xmlui_parent) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
360 self._parseChilds(cont, node, ('widget', 'container')) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
361 try: |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
362 _xmlui_parent._xmluiAppend(cont) |
808
d035c662b357
frontends: some modifications to ease the the use of the new sat_frontends.tools.xmlui.XMLUI class in Libervia
Goffi <goffi@goffi.org>
parents:
805
diff
changeset
|
363 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
364 if _xmlui_parent is self: |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
365 self.main_cont = cont |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
366 else: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
367 raise Exception(_("Internal Error, container has not _xmluiAppend method")) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
368 |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
369 elif node.nodeName == 'tab': |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
370 name = node.getAttribute('name') |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
371 label = node.getAttribute('label') |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
372 if not name or not isinstance(data, TabsContainer): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
373 raise InvalidXMLUI |
166
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
162
diff
changeset
|
374 if self.type == 'param': |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
162
diff
changeset
|
375 self._current_category = name #XXX: awful hack because params need category and we don't keep parent |
152
b1f1955d96b3
Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents:
149
diff
changeset
|
376 tab_cont = data |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
377 new_tab = tab_cont._xmluiAddTab(label or name) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
378 self._parseChilds(new_tab, node, ('widget', 'container')) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
379 |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
380 elif node.nodeName == 'row': |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
381 try: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
382 index = str(data['index']) |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
383 data['index'] += 1 |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
384 except TypeError: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
385 index = node.getAttribute('index') or None |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
386 _xmlui_parent._xmluiAddRow(index) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
387 self._parseChilds(_xmlui_parent, node, ('widget', 'container')) |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
388 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
389 elif node.nodeName == "widget": |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
390 name = node.getAttribute("name") |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
391 type_ = node.getAttribute("type") |
1086
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
392 value_elt = self._getChildNode(node, "value") |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
393 if value_elt is not None: |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
394 value = getText(value_elt) |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
395 else: |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1085
diff
changeset
|
396 value = node.getAttribute("value") if node.hasAttribute('value') else u'' |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
397 if type_=="empty": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
398 ctrl = self.widget_factory.createEmptyWidget(_xmlui_parent) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
399 elif type_=="text": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
400 ctrl = self.widget_factory.createTextWidget(_xmlui_parent, value) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
401 elif type_=="label": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
402 ctrl = self.widget_factory.createLabelWidget(_xmlui_parent, value) |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
403 elif type_=="jid": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
404 ctrl = self.widget_factory.createJidWidget(_xmlui_parent, value) |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
405 elif type_=="divider": |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
406 style = node.getAttribute("style") or 'line' |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
407 ctrl = self.widget_factory.createDividerWidget(_xmlui_parent, style) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
408 elif type_=="string": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
409 ctrl = self.widget_factory.createStringWidget(_xmlui_parent, value, self._isAttrSet("read_only", node)) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
410 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
411 elif type_=="jid_input": |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
412 ctrl = self.widget_factory.createJidInputWidget(_xmlui_parent, value, self._isAttrSet("read_only", node)) |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
413 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
414 elif type_=="password": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
415 ctrl = self.widget_factory.createPasswordWidget(_xmlui_parent, value, self._isAttrSet("read_only", node)) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
416 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
417 elif type_=="textbox": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
418 ctrl = self.widget_factory.createTextBoxWidget(_xmlui_parent, value, self._isAttrSet("read_only", node)) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
419 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
420 elif type_=="bool": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
421 ctrl = self.widget_factory.createBoolWidget(_xmlui_parent, value==C.BOOL_TRUE, self._isAttrSet("read_only", node)) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
422 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1109
diff
changeset
|
423 elif type_ == "int": |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1109
diff
changeset
|
424 ctrl = self.widget_factory.createIntWidget(_xmlui_parent, value, self._isAttrSet("read_only", node)) |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1109
diff
changeset
|
425 self.ctrl_list[name] = ({'type':type_, 'control':ctrl}) |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
865
diff
changeset
|
426 elif type_ == "list": |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
865
diff
changeset
|
427 style = [] if node.getAttribute("multi") == 'yes' else ['single'] |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
428 _options = [(option.getAttribute("value"), option.getAttribute("label")) for option in node.getElementsByTagName("option")] |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
429 _selected = [option.getAttribute("value") for option in node.getElementsByTagName("option") if option.getAttribute('selected') == C.BOOL_TRUE] |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
430 ctrl = self.widget_factory.createListWidget(_xmlui_parent, _options, _selected, style) |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
865
diff
changeset
|
431 self.ctrl_list[name] = ({'type': type_, 'control': ctrl}) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
432 elif type_=="button": |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
433 callback_id = node.getAttribute("callback") |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
434 ctrl = self.widget_factory.createButtonWidget(_xmlui_parent, value, self.onButtonPress) |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
865
diff
changeset
|
435 ctrl._xmlui_param_id = (callback_id, [field.getAttribute('name') for field in node.getElementsByTagName("field_back")]) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
436 else: |
1087
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
437 log.error(_("FIXME FIXME FIXME: widget type [%s] is not implemented") % type_) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
438 raise NotImplementedError(_("FIXME FIXME FIXME: type [%s] is not implemented") % type_) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
439 |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
440 if self.type == 'param' and type_ not in ('text', 'button'): |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
441 try: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
442 ctrl._xmluiOnChange(self.onParamChange) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
443 ctrl._param_category = self._current_category |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
444 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError |
808
d035c662b357
frontends: some modifications to ease the the use of the new sat_frontends.tools.xmlui.XMLUI class in Libervia
Goffi <goffi@goffi.org>
parents:
805
diff
changeset
|
445 if not isinstance(ctrl, (EmptyWidget, TextWidget, LabelWidget, JidWidget)): |
1087
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
446 log.warning(_("No change listener on [%s]") % ctrl) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
447 |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
448 if type_ != 'text': |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
449 callback = node.getAttribute("internal_callback") or None |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
450 if callback: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
451 fields = [field.getAttribute('name') for field in node.getElementsByTagName("internal_field")] |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
452 data = self.getInternalCallbackData(callback, node) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
453 ctrl._xmlui_param_internal = (callback, fields, data) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
454 if type_ == 'button': |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
455 ctrl._xmluiOnClick(self.onChangeInternal) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
456 else: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
457 ctrl._xmluiOnChange(self.onChangeInternal) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
458 |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
459 ctrl._xmlui_name = name |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
460 _xmlui_parent._xmluiAppend(ctrl) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
461 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
462 else: |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
463 raise NotImplementedError(_('Unknown tag [%s]') % node.nodeName) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
464 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
465 def constructUI(self, parsed_dom, post_treat=None): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
466 """Actually construct the UI |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
467 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
468 @param parsed_dom: main parsed dom |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
469 @param post_treat: frontend specific treatments to do once the UI is constructed |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
470 @return: constructed widget |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
471 """ |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
472 top=parsed_dom.documentElement |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 self.type = top.getAttribute("type") |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
474 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window', 'popup']: |
152
b1f1955d96b3
Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents:
149
diff
changeset
|
475 raise InvalidXMLUI |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 |
166
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
162
diff
changeset
|
477 if self.type == 'param': |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
162
diff
changeset
|
478 self.param_changed = set() |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
162
diff
changeset
|
479 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
480 self._parseChilds(self, parsed_dom.documentElement) |
152
b1f1955d96b3
Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents:
149
diff
changeset
|
481 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
482 if post_treat is not None: |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
483 post_treat() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
484 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
485 def _xmluiClose(self): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
486 """Close the window/popup/... where the constructeur XMLUI is |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
487 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
488 this method must be overrided |
687
af0d08a84cc6
primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents:
655
diff
changeset
|
489 """ |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
490 raise NotImplementedError |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 |
808
d035c662b357
frontends: some modifications to ease the the use of the new sat_frontends.tools.xmlui.XMLUI class in Libervia
Goffi <goffi@goffi.org>
parents:
805
diff
changeset
|
492 def _xmluiSetParam(self, name, value, category): |
1346
35f99c90b736
frontends (XMLUI): fixes wrong argument name
souliane <souliane@mailoo.org>
parents:
1327
diff
changeset
|
493 self.host.bridge.setParam(name, value, category, profile_key=self.profile) |
808
d035c662b357
frontends: some modifications to ease the the use of the new sat_frontends.tools.xmlui.XMLUI class in Libervia
Goffi <goffi@goffi.org>
parents:
805
diff
changeset
|
494 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
495 ##EVENTS## |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
496 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
497 def onParamChange(self, ctrl): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
498 """Called when type is param and a widget to save is modified |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
499 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
500 @param ctrl: widget modified |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
501 """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
502 assert(self.type == "param") |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
503 self.param_changed.add(ctrl) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
504 |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
505 def onAdvListSelect(self, ctrl): |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
506 data = {} |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
507 widgets = ctrl._xmluiGetSelectedWidgets() |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
508 for wid in widgets: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
509 try: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
510 name = self.escape(wid._xmlui_name) |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
511 value = wid._xmluiGetValue() |
864
241f6baa6687
frontends: fix typos, do not use logging in the xmlui tools:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
512 data[name] = value |
808
d035c662b357
frontends: some modifications to ease the the use of the new sat_frontends.tools.xmlui.XMLUI class in Libervia
Goffi <goffi@goffi.org>
parents:
805
diff
changeset
|
513 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
514 pass |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
515 idx = ctrl._xmluiGetSelectedIndex() |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
516 if idx is not None: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
517 data['index'] = idx |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
518 callback_id = ctrl._xmlui_callback_id |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
519 if callback_id is None: |
1087
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
520 log.info(_("No callback_id found")) |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
521 return |
808
d035c662b357
frontends: some modifications to ease the the use of the new sat_frontends.tools.xmlui.XMLUI class in Libervia
Goffi <goffi@goffi.org>
parents:
805
diff
changeset
|
522 self._xmluiLaunchAction(callback_id, data) |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
523 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
524 def onButtonPress(self, button): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
525 """Called when an XMLUI button is clicked |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
526 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
527 Launch the action associated to the button |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
528 @param button: the button clicked |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
529 """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
530 callback_id, fields = button._xmlui_param_id |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
531 if not callback_id: # the button is probably bound to an internal action |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
532 return |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
687
diff
changeset
|
533 data = {} |
157
13888bdb72b6
primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents:
152
diff
changeset
|
534 for field in fields: |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
535 escaped = self.escape(field) |
157
13888bdb72b6
primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents:
152
diff
changeset
|
536 ctrl = self.ctrl_list[field] |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
537 if isinstance(ctrl['control'], ListWidget): |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
865
diff
changeset
|
538 data[escaped] = u'\t'.join(ctrl['control']._xmluiGetSelectedValues()) |
157
13888bdb72b6
primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents:
152
diff
changeset
|
539 else: |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
540 data[escaped] = ctrl['control']._xmluiGetValue() |
808
d035c662b357
frontends: some modifications to ease the the use of the new sat_frontends.tools.xmlui.XMLUI class in Libervia
Goffi <goffi@goffi.org>
parents:
805
diff
changeset
|
541 self._xmluiLaunchAction(callback_id, data) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
542 |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
543 def onChangeInternal(self, ctrl): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
544 """Called when a widget that has been bound to an internal callback is changed. |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
545 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
546 This is used to perform some UI actions without communicating with the backend. |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
547 See sat.tools.xml_tools.Widget.setInternalCallback for more details. |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
548 @param ctrl: widget modified |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
549 """ |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
550 action, fields, data = ctrl._xmlui_param_internal |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
551 if action not in ('copy', 'move', 'groups_of_contact'): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
552 raise NotImplementedError(_("FIXME: XMLUI internal action [%s] is not implemented") % action) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
553 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
554 def copy_move(source, target): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
555 """Depending of 'action' value, copy or move from source to target.""" |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
556 if isinstance(target, ListWidget): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
557 if isinstance(source, ListWidget): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
558 values = source._xmluiGetSelectedValues() |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
559 else: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
560 values = [source._xmluiGetValue()] |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
561 if action == 'move': |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
562 source._xmluiSetValue('') |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
563 values = [value for value in values if value] |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
564 if values: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
565 target._xmluiAddValues(values, select=True) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
566 else: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
567 if isinstance(source, ListWidget): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
568 value = u', '.join(source._xmluiGetSelectedValues()) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
569 else: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
570 value = source._xmluiGetValue() |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
571 if action == 'move': |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
572 source._xmluiSetValue('') |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
573 target._xmluiSetValue(value) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
574 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
575 def groups_of_contact(source, target): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
576 """Select in target the groups of the contact which is selected in source.""" |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
577 assert(isinstance(source, ListWidget)) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
578 assert(isinstance(target, ListWidget)) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
579 try: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
580 contact_jid_s = source._xmluiGetSelectedValues()[0] |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
581 except IndexError: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
582 return |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
583 target._xmluiSelectValues(data[contact_jid_s]) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
584 pass |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
585 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
586 source = None |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
587 for field in fields: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
588 widget = self.ctrl_list[field]['control'] |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
589 if not source: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
590 source = widget |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
591 continue |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
592 if action in ('copy', 'move'): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
593 copy_move(source, widget) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
594 elif action == 'groups_of_contact': |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
595 groups_of_contact(source, widget) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
596 source = None |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
597 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
598 def getInternalCallbackData(self, action, node): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
599 """Retrieve from node the data needed to perform given action. |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
600 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
601 @param action (string): a value from the one that can be passed to the |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
602 'callback' parameter of sat.tools.xml_tools.Widget.setInternalCallback |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
603 @param node (DOM Element): the node of the widget that triggers the callback |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
604 """ |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
605 # TODO: it would be better to not have a specific way to retrieve |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
606 # data for each action, but instead to have a generic method to |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
607 # extract any kind of data structure from the 'internal_data' element. |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
608 |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
609 try: # data is stored in the first 'internal_data' element of the node |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
610 data_elts = node.getElementsByTagName('internal_data')[0].childNodes |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
611 except IndexError: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
612 return None |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
613 data = {} |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
614 if action == 'groups_of_contact': # return a dict(key: string, value: list[string]) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
615 for elt in data_elts: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
616 jid_s = elt.getAttribute('name') |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
617 data[jid_s] = [] |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
618 for value_elt in elt.childNodes: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
619 data[jid_s].append(value_elt.getAttribute('name')) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
620 return data |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
621 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
622 def onFormSubmitted(self, ignore=None): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
623 """An XMLUI form has been submited |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
624 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
625 call the submit action associated with this form |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
626 """ |
760
73a0077f80cc
backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
759
diff
changeset
|
627 selected_values = [] |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
628 for ctrl_name in self.ctrl_list: |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
629 escaped = self.escape(ctrl_name) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
630 ctrl = self.ctrl_list[ctrl_name] |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
631 if isinstance(ctrl['control'], ListWidget): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
632 selected_values.append((escaped, u'\t'.join(ctrl['control']._xmluiGetSelectedValues()))) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
633 else: |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
634 selected_values.append((escaped, ctrl['control']._xmluiGetValue())) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
635 if self.submit_id is not None: |
760
73a0077f80cc
backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
759
diff
changeset
|
636 data = dict(selected_values) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
637 self.submit(data) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
638 else: |
1087
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
639 log.warning(_("The form data is not sent back, the type is not managed properly")) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
640 self._xmluiClose() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
641 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
642 def onFormCancelled(self, ignore=None): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
643 """Called when a form is cancelled""" |
1087
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
644 log.debug(_("Cancelling form")) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
645 self._xmluiClose() |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
646 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
647 def onSaveParams(self, ignore=None): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
648 """Params are saved, we send them to backend |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
649 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
650 self.type must be param |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
651 """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
652 assert(self.type == 'param') |
166
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
162
diff
changeset
|
653 for ctrl in self.param_changed: |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
654 if isinstance(ctrl, ListWidget): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
655 value = u'\t'.join(ctrl._xmluiGetSelectedValues()) |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
170
diff
changeset
|
656 else: |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
657 value = ctrl._xmluiGetValue() |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
658 param_name = ctrl._xmlui_name.split(C.SAT_PARAM_SEPARATOR)[1] |
808
d035c662b357
frontends: some modifications to ease the the use of the new sat_frontends.tools.xmlui.XMLUI class in Libervia
Goffi <goffi@goffi.org>
parents:
805
diff
changeset
|
659 self._xmluiSetParam(param_name, value, ctrl._param_category) |
d035c662b357
frontends: some modifications to ease the the use of the new sat_frontends.tools.xmlui.XMLUI class in Libervia
Goffi <goffi@goffi.org>
parents:
805
diff
changeset
|
660 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
661 self._xmluiClose() |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
662 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
663 def show(self, *args, **kwargs): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
664 pass |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
665 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
666 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
667 class XMLUIDialog(XMLUIBase): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
668 dialog_factory = None |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
669 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
670 def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
671 super(XMLUIDialog, self).__init__(host, parsed_dom, title=None, flags=None, callback=callback, profile=C.PROF_KEY_NONE) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
672 top=parsed_dom.documentElement |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
673 dlg_elt = self._getChildNode(top, "dialog") |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
674 if dlg_elt is None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
675 raise ValueError("Invalid XMLUI: no Dialog element found !") |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
676 dlg_type = dlg_elt.getAttribute("type") or C.XMLUI_DIALOG_MESSAGE |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
677 try: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
678 mess_elt = self._getChildNode(dlg_elt, C.XMLUI_DATA_MESS) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
679 message = getText(mess_elt) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
680 except (TypeError, AttributeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
681 message = "" |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
682 level = dlg_elt.getAttribute(C.XMLUI_DATA_LVL) or C.XMLUI_DATA_LVL_INFO |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
683 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
684 if dlg_type == C.XMLUI_DIALOG_MESSAGE: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
685 self.dlg = self.dialog_factory.createMessageDialog(self, self.xmlui_title, message, level) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
686 elif dlg_type == C.XMLUI_DIALOG_NOTE: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
687 self.dlg = self.dialog_factory.createNoteDialog(self, self.xmlui_title, message, level) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
688 elif dlg_type == C.XMLUI_DIALOG_CONFIRM: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
689 try: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
690 buttons_elt = self._getChildNode(dlg_elt, "buttons") |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
691 buttons_set = buttons_elt.getAttribute("set") or C.XMLUI_DATA_BTNS_SET_DEFAULT |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
692 except (TypeError, AttributeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
693 buttons_set = C.XMLUI_DATA_BTNS_SET_DEFAULT |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
694 self.dlg = self.dialog_factory.createConfirmDialog(self, self.xmlui_title, message, level, buttons_set) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
695 elif dlg_type == C.XMLUI_DIALOG_FILE: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
696 try: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
697 file_elt = self._getChildNode(dlg_elt, "file") |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
698 filetype = file_elt.getAttribute("type") or C.XMLUI_DATA_FILETYPE_DEFAULT |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
699 except (TypeError, AttributeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
700 filetype = C.XMLUI_DATA_FILETYPE_DEFAULT |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
701 self.dlg = self.dialog_factory.createFileDialog(self, self.xmlui_title, message, level, filetype) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
702 else: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
703 raise ValueError("Unknown dialog type [%s]" % dlg_type) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
704 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
705 def show(self): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
706 self.dlg._xmluiShow() |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
707 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
708 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
709 def registerClass(type_, class_): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
710 """Register the class to use with the factory |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
711 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
712 @param type_: one of: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
713 CLASS_PANEL: classical XMLUI interface |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
714 CLASS_DIALOG: XMLUI dialog |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
715 @param class_: the class to use to instanciate given type |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
716 """ |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
717 assert type_ in (CLASS_PANEL, CLASS_DIALOG) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
718 class_map[type_] = class_ |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
719 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
720 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
721 def create(host, xml_data, title=None, flags=None, dom_parse=None, dom_free=None, callback=None, profile=C.PROF_KEY_NONE): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
722 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
723 @param dom_parse: methode equivalent to minidom.parseString (but which must manage unicode), or None to use default one |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
724 @param dom_free: method used to free the parsed DOM |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
725 """ |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
726 if dom_parse is None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
727 from xml.dom import minidom |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
728 dom_parse = lambda xml_data: minidom.parseString(xml_data.encode('utf-8')) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
729 dom_free = lambda parsed_dom: parsed_dom.unlink() |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
730 else: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
731 dom_parse = dom_parse |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
732 dom_free = dom_free or (lambda parsed_dom: None) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
733 parsed_dom = dom_parse(xml_data) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
734 top=parsed_dom.documentElement |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
735 ui_type = top.getAttribute("type") |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
736 try: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
737 if ui_type != C.XMLUI_DIALOG: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
738 cls = class_map[CLASS_PANEL] |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
739 else: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
740 cls = class_map[CLASS_DIALOG] |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
741 except KeyError: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
742 raise ClassNotRegistedError(_("You must register classes with registerClass before creating a XMLUI")) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
743 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
744 xmlui = cls(host, parsed_dom, title, flags, callback, profile) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
745 dom_free(parsed_dom) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
746 return xmlui |