Mercurial > libervia-backend
annotate libervia/frontends/tools/xmlui.py @ 4318:27bb22eace65
tests (unit/email gateway): add test for XEP-0131 handling:
rel 451
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 Sep 2024 15:59:48 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
144
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 |
3479 | 5 # Copyright (C) 2009-2021 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 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
20 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
21 from libervia.backend.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
22 |
1087
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
23 log = getLogger(__name__) |
4074
26b7ed2817da
refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
24 from libervia.frontends.quick_frontend.constants import Const as C |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
25 from libervia.backend.core import exceptions |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
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
|
27 |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2668
diff
changeset
|
28 _class_map = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
29 CLASS_PANEL = "panel" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
30 CLASS_DIALOG = "dialog" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
31 CURRENT_LABEL = "current_label" |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
32 HIDDEN = "hidden" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
33 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
34 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
35 class InvalidXMLUI(Exception): |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
36 pass |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
37 |
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
|
38 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
39 class ClassNotRegistedError(Exception): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
40 pass |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
41 |
1740
681fe91abcc0
memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents:
1610
diff
changeset
|
42 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
43 # FIXME: this method is duplicated in frontends.tools.xmlui.get_text |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
44 def get_text(node): |
632
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
45 """Get child text nodes |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
46 @param node: dom Node |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
47 @return: joined unicode text of all nodes |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
48 |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
49 """ |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
50 data = [] |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
51 for child in node.childNodes: |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
52 if child.nodeType == child.TEXT_NODE: |
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
53 data.append(child.wholeText) |
3028 | 54 return "".join(data) |
632
06f44f797a1b
primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents:
610
diff
changeset
|
55 |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
632
diff
changeset
|
56 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
57 class Widget(object): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
58 """base Widget""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
59 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
60 pass |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
63 class EmptyWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
64 """Just a placeholder widget""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
65 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
66 pass |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
67 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
68 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
69 class TextWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
70 """Non interactive text""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
71 |
152
b1f1955d96b3
Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents:
149
diff
changeset
|
72 pass |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
74 |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
75 class LabelWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
76 """Non interactive text""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
77 |
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 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
81 class JidWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
82 """Jabber ID""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
83 |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
84 pass |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
85 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
86 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
87 class DividerWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
88 """Separator""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
89 |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
90 pass |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
91 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
92 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
93 class StringWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
94 """Input widget wich require a string |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
95 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
96 often called Edit in toolkits |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
97 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
98 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
99 pass |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
100 |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
101 |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
102 class JidInputWidget(Widget): |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
103 """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
|
104 |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
105 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
|
106 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
107 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
108 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
109 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
110 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
111 class PasswordWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
112 """Input widget with require a masked string""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
113 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
114 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
115 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
116 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
117 class TextBoxWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
118 """Input widget with require a long, possibly multilines string |
2783
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
119 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
120 often called TextArea in toolkits |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
121 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
122 |
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 |
2783
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
126 class XHTMLBoxWidget(Widget): |
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
127 """Input widget specialised in XHTML editing, |
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
128 |
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
129 a WYSIWYG or specialised editor is expected |
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
130 """ |
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
131 |
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
132 pass |
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
133 |
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
134 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
135 class BoolWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
136 """Input widget with require a boolean value |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
137 often called CheckBox in toolkits |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
138 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
139 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
140 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
141 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
142 |
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
|
143 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
|
144 """Input widget with require an integer""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
145 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
146 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
|
147 |
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
|
148 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
149 class ButtonWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
150 """A clickable widget""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
151 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
152 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
153 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
154 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
155 class ListWidget(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
156 """A widget able to show/choose one or several strings in a list""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
157 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
158 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
159 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
160 |
1478
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
161 class JidsListWidget(Widget): |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
162 """A widget able to show/choose one or several strings in a list""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
163 |
1478
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
164 pass |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
165 |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
166 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
167 class Container(Widget): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
168 """Widget which can contain other ones with a specific layout""" |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
169 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
170 @classmethod |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
171 def _xmlui_adapt(cls, instance): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
172 """Make cls as instance.__class__ |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
173 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
174 cls must inherit from original instance class |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
175 Usefull when you get a class from UI toolkit |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
176 """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
177 assert instance.__class__ in cls.__bases__ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
178 instance.__class__ = type(cls.__name__, cls.__bases__, dict(cls.__dict__)) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
179 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
180 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
181 class PairsContainer(Container): |
2361
5defafc8ede6
core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents:
2093
diff
changeset
|
182 """Widgets are disposed in rows of two (usually label/input)""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
183 |
2361
5defafc8ede6
core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents:
2093
diff
changeset
|
184 pass |
5defafc8ede6
core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents:
2093
diff
changeset
|
185 |
5defafc8ede6
core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents:
2093
diff
changeset
|
186 |
5defafc8ede6
core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents:
2093
diff
changeset
|
187 class LabelContainer(Container): |
5defafc8ede6
core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents:
2093
diff
changeset
|
188 """Widgets are associated with label or empty widget""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
189 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
190 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
191 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
192 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
193 class TabsContainer(Container): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
194 """A container which several other containers in tabs |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
195 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
196 Often called Notebook in toolkits |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
197 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
198 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
199 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
200 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
201 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
202 class VerticalContainer(Container): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
203 """Widgets are disposed vertically""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
204 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
205 pass |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
206 |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
207 |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
208 class AdvancedListContainer(Container): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
209 """Widgets are disposed in rows with advaned features""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
210 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
211 pass |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
212 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
213 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
214 class Dialog(object): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
215 """base dialog""" |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
216 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
217 def __init__(self, _xmlui_parent): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
218 self._xmlui_parent = _xmlui_parent |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
219 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
220 def _xmlui_validated(self, data=None): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
221 if data is None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
222 data = {} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
223 self._xmlui_set_data(C.XMLUI_STATUS_VALIDATED, data) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
224 self._xmlui_submit(data) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
225 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
226 def _xmlui_cancelled(self): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
227 data = {C.XMLUI_DATA_CANCELLED: C.BOOL_TRUE} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
228 self._xmlui_set_data(C.XMLUI_STATUS_CANCELLED, data) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
229 self._xmlui_submit(data) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
230 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
231 def _xmlui_submit(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
|
232 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
|
233 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
|
234 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
|
235 self._xmlui_parent.submit(data) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
236 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
237 def _xmlui_set_data(self, status, data): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
238 pass |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
239 |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
240 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
241 class MessageDialog(Dialog): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
242 """Dialog with a OK/Cancel type configuration""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
243 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
244 pass |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
245 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
246 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
247 class NoteDialog(Dialog): |
2036
db3bbbd745e4
frontends (xmlui): added a user_action attribute:
Goffi <goffi@goffi.org>
parents:
1985
diff
changeset
|
248 """Short message which doesn't need user confirmation to disappear""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
249 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
250 pass |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
251 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
252 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
253 class ConfirmDialog(Dialog): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
254 """Dialog with a OK/Cancel type configuration""" |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
255 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
256 def _xmlui_set_data(self, status, data): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
257 if status == C.XMLUI_STATUS_VALIDATED: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
258 data[C.XMLUI_DATA_ANSWER] = C.BOOL_TRUE |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
259 elif status == C.XMLUI_STATUS_CANCELLED: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
260 data[C.XMLUI_DATA_ANSWER] = C.BOOL_FALSE |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
261 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
262 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
263 class FileDialog(Dialog): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
264 """Dialog with a OK/Cancel type configuration""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
265 |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
266 pass |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
267 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
268 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
269 class XMLUIBase(object): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
270 """Base class to construct SàT XML User Interface |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
271 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
272 This class must not be instancied directly |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
273 """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
274 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
275 def __init__( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
276 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
277 host, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
278 parsed_dom, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
279 title=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
280 flags=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
281 callback=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
282 profile=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
283 ): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
284 """Initialise the XMLUI instance |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
285 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
286 @param host: %(doc_host)s |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
287 @param parsed_dom: main parsed dom |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
288 @param title: force the title, or use XMLUI one if None |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
289 @param flags: list of string which can be: |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
290 - NO_CANCEL: the UI can't be cancelled |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
291 - FROM_BACKEND: the UI come from backend (i.e. it's not the direct result of |
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
292 user operation) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
293 @param callback(callable, None): if not None, will be used with action_launch: |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
294 - if None is used, default behaviour will be used (closing the dialog and |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
295 calling host.action_manager) |
1489
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1486
diff
changeset
|
296 - if a callback is provided, it will be used instead, so you'll have to manage |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
297 dialog closing or new xmlui to display, or other action (you can call |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
298 host.action_manager) |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
299 The callback will have data, callback_id and profile as arguments |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
300 """ |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 self.host = host |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
302 top = parsed_dom.documentElement |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
303 self.session_id = top.getAttribute("session_id") or None |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
304 self.submit_id = top.getAttribute("submit") or None |
3028 | 305 self.xmlui_title = title or top.getAttribute("title") or "" |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
306 self.hidden = {} |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
307 if flags is None: |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
308 flags = [] |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
309 self.flags = flags |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
310 self.callback = callback or self._default_cb |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1220
diff
changeset
|
311 self.profile = profile |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
312 |
2036
db3bbbd745e4
frontends (xmlui): added a user_action attribute:
Goffi <goffi@goffi.org>
parents:
1985
diff
changeset
|
313 @property |
db3bbbd745e4
frontends (xmlui): added a user_action attribute:
Goffi <goffi@goffi.org>
parents:
1985
diff
changeset
|
314 def user_action(self): |
db3bbbd745e4
frontends (xmlui): added a user_action attribute:
Goffi <goffi@goffi.org>
parents:
1985
diff
changeset
|
315 return "FROM_BACKEND" not in self.flags |
db3bbbd745e4
frontends (xmlui): added a user_action attribute:
Goffi <goffi@goffi.org>
parents:
1985
diff
changeset
|
316 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
317 def _default_cb(self, data, cb_id, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
318 # TODO: when XMLUI updates will be managed, the _xmlui_close |
2597
9446f1ea9eac
core: discoFindByFeatures now return only available resources
Goffi <goffi@goffi.org>
parents:
2575
diff
changeset
|
319 # must be called only if there is no update |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
320 self._xmlui_close() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
321 self.host.action_manager(data, profile=profile) |
1489
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1486
diff
changeset
|
322 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
323 def _is_attr_set(self, name, node): |
2540
3e03de7691ce
frontends (xmlui): added whitelist argument:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
324 """Return widget boolean attribute status |
1085
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
325 |
7a39ae3950f7
frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
326 @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
|
327 @param node: Node instance |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
328 @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
|
329 """ |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
330 read_only = node.getAttribute(name) or C.BOOL_FALSE |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
331 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
|
332 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
333 def _get_child_node(self, node, name): |
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
|
334 """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
|
335 |
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
|
336 @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
|
337 @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
|
338 |
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
|
339 @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
|
340 """ |
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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
346 def submit(self, data): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
347 self._xmlui_close() |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
348 if self.submit_id is None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
349 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
|
350 if "session_id" in data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
351 raise ValueError( |
3028 | 352 "session_id must no be used in data, it is automaticaly filled with " |
353 "self.session_id if present" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
354 ) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
355 if self.session_id is not None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
356 data["session_id"] = self.session_id |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
357 self._xmlui_launch_action(self.submit_id, data) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
358 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
359 def _xmlui_launch_action(self, action_id, data): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
360 self.host.action_launch( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
361 action_id, data, callback=self.callback, profile=self.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
362 ) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
363 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
364 def _xmlui_close(self): |
1579
d5e332055d9f
quick_frontend, primitivus (xmlui): removed _xmluiClose from workflow were submit is triggered, as submit launch the callback which close the dialog itself + fixed dialogs _xmluiClose
Goffi <goffi@goffi.org>
parents:
1501
diff
changeset
|
365 """Close the window/popup/... where the constructor XMLUI is |
1489
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1486
diff
changeset
|
366 |
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1486
diff
changeset
|
367 this method must be overrided |
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1486
diff
changeset
|
368 """ |
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1486
diff
changeset
|
369 raise NotImplementedError |
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1486
diff
changeset
|
370 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
371 |
2376
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
372 class ValueGetter(object): |
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
373 """dict like object which return values of widgets""" |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
374 |
3474
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
375 # FIXME: widget which can keep multiple values are not handled |
2376
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
376 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
377 def __init__(self, widgets, attr="value"): |
2376
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
378 self.attr = attr |
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
379 self.widgets = widgets |
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
380 |
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
381 def __getitem__(self, name): |
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
382 return getattr(self.widgets[name], self.attr) |
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
383 |
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
384 def __getattr__(self, name): |
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
385 return self.__getitem__(name) |
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
386 |
2387
a59f2abd970e
frontends (xmlui): added ValueGetter.keys
Goffi <goffi@goffi.org>
parents:
2377
diff
changeset
|
387 def keys(self): |
3028 | 388 return list(self.widgets.keys()) |
2387
a59f2abd970e
frontends (xmlui): added ValueGetter.keys
Goffi <goffi@goffi.org>
parents:
2377
diff
changeset
|
389 |
3474
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
390 def items(self): |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
391 for name, widget in self.widgets.items(): |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
392 try: |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
393 value = widget.value |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
394 except AttributeError: |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
395 try: |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
396 value = list(widget.values) |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
397 except AttributeError: |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
398 continue |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
399 yield name, value |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
400 |
2376
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
401 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
402 class XMLUIPanel(XMLUIBase): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
403 """XMLUI Panel |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
404 |
2540
3e03de7691ce
frontends (xmlui): added whitelist argument:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
405 New frontends can inherit this class to easily implement XMLUI |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
406 @property widget_factory: factory to create frontend-specific widgets |
1610
1378ec04380f
primitivus (xmlui): fixed closing on popup panel "OK" button press
Goffi <goffi@goffi.org>
parents:
1608
diff
changeset
|
407 @property dialog_factory: factory to create frontend-specific dialogs |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
408 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
409 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
410 widget_factory = None |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
411 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
412 def __init__( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
413 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
414 host, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
415 parsed_dom, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
416 title=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
417 flags=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
418 callback=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
419 ignore=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
420 whitelist=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
421 profile=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
422 ): |
2376
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
423 """ |
2540
3e03de7691ce
frontends (xmlui): added whitelist argument:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
424 |
3e03de7691ce
frontends (xmlui): added whitelist argument:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
425 @param title(unicode, None): title of the |
2376
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
426 @property widgets(dict): widget name => widget map |
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
427 @property widget_value(ValueGetter): retrieve widget value from it's name |
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
428 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
429 super(XMLUIPanel, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
430 host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
431 ) |
2366
c7a7e650ac2f
frontends (xmlui): a dict of named widgets is kept, so they can be easily be retrieved
Goffi <goffi@goffi.org>
parents:
2361
diff
changeset
|
432 self.ctrl_list = {} # input widget, used mainly for forms |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
433 self.widgets = {} # allow to access any named widgets |
2376
825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
Goffi <goffi@goffi.org>
parents:
2366
diff
changeset
|
434 self.widget_value = ValueGetter(self.widgets) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
435 self._main_cont = None |
2419
c38c54c47e16
frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents:
2418
diff
changeset
|
436 if ignore is None: |
c38c54c47e16
frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents:
2418
diff
changeset
|
437 ignore = [] |
c38c54c47e16
frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents:
2418
diff
changeset
|
438 self._ignore = ignore |
2540
3e03de7691ce
frontends (xmlui): added whitelist argument:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
439 if whitelist is not None: |
3e03de7691ce
frontends (xmlui): added whitelist argument:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
440 if ignore: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
441 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
442 "ignore and whitelist must not be used at the same time" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
443 ) |
2540
3e03de7691ce
frontends (xmlui): added whitelist argument:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
444 self._whitelist = whitelist |
3e03de7691ce
frontends (xmlui): added whitelist argument:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
445 else: |
3e03de7691ce
frontends (xmlui): added whitelist argument:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
446 self._whitelist = None |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
447 self.construct_ui(parsed_dom) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
448 |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
449 @staticmethod |
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
450 def escape(name): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
451 """Return escaped name for forms""" |
3028 | 452 return "%s%s" % (C.SAT_FORM_PREFIX, name) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
453 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
454 @property |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
455 def main_cont(self): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
456 return self._main_cont |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
457 |
3474
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
458 @property |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
459 def values(self): |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
460 """Dict of all widgets values""" |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
461 return dict(self.widget_value.items()) |
1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
462 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
463 @main_cont.setter |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
464 def main_cont(self, value): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
465 if self._main_cont is not None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
466 raise ValueError(_("XMLUI can have only one main container")) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
467 self._main_cont = value |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
468 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
469 def _parse_childs( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
470 self, _xmlui_parent, current_node, wanted=("container",), data=None |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
471 ): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
472 """Recursively parse childNodes of an element |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
473 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
474 @param _xmlui_parent: widget container with '_xmlui_append' method |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
475 @param current_node: element from which childs will be parsed |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
476 @param wanted: list of tag names that can be present in the childs to be SàT XMLUI |
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
477 compliant |
2377
e50aee5caf33
frontends (xmlui): new _xmlui_for_name attribute:
Goffi <goffi@goffi.org>
parents:
2376
diff
changeset
|
478 @param data(None, dict): additionnal data which are needed in some cases |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
479 """ |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
480 for node in current_node.childNodes: |
2424
467ddb437a71
frontends (xmlui): fixed crash on advanced_list use:
Goffi <goffi@goffi.org>
parents:
2419
diff
changeset
|
481 if data is None: |
467ddb437a71
frontends (xmlui): fixed crash on advanced_list use:
Goffi <goffi@goffi.org>
parents:
2419
diff
changeset
|
482 data = {} |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 if wanted and not node.nodeName in wanted: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
484 raise InvalidXMLUI("Unexpected node: [%s]" % node.nodeName) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
485 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
486 if node.nodeName == "container": |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
487 type_ = node.getAttribute("type") |
2737
5c2ed8a5ae22
frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
488 if _xmlui_parent is self and type_ not in ("vertical", "tabs"): |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
489 # main container is not a VerticalContainer and we want one, |
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
490 # so we create one to wrap it |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
491 _xmlui_parent = self.widget_factory.createVerticalContainer(self) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
492 self.main_cont = _xmlui_parent |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
493 if type_ == "tabs": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
494 cont = self.widget_factory.createTabsContainer(_xmlui_parent) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
495 self._parse_childs(_xmlui_parent, node, ("tab",), {"tabs_cont": cont}) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
496 elif type_ == "vertical": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
497 cont = self.widget_factory.createVerticalContainer(_xmlui_parent) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
498 self._parse_childs(cont, node, ("widget", "container")) |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
499 elif type_ == "pairs": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
500 cont = self.widget_factory.createPairsContainer(_xmlui_parent) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
501 self._parse_childs(cont, node, ("widget", "container")) |
2361
5defafc8ede6
core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents:
2093
diff
changeset
|
502 elif type_ == "label": |
5defafc8ede6
core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents:
2093
diff
changeset
|
503 cont = self.widget_factory.createLabelContainer(_xmlui_parent) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
504 self._parse_childs( |
2995
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
505 # FIXME: the "None" value for CURRENT_LABEL doesn't seem |
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
506 # used or even useful, it should probably be removed |
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
507 # and all "is not None" tests for it should be removed too |
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
508 # to be checked for 0.8 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
509 cont, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
510 node, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
511 ("widget", "container"), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
512 {CURRENT_LABEL: None}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
513 ) |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
514 elif type_ == "advanced_list": |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
515 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
516 columns = int(node.getAttribute("columns")) |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
517 except (TypeError, ValueError): |
2540
3e03de7691ce
frontends (xmlui): added whitelist argument:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
518 raise exceptions.DataError("Invalid columns") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
519 selectable = node.getAttribute("selectable") or "no" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
520 auto_index = node.getAttribute("auto_index") == C.BOOL_TRUE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
521 data = {"index": 0} if auto_index else None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
522 cont = self.widget_factory.createAdvancedListContainer( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
523 _xmlui_parent, columns, selectable |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
524 ) |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
525 callback_id = node.getAttribute("callback") or None |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
526 if callback_id is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
527 if selectable == "no": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
528 raise ValueError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
529 "can't have selectable=='no' and callback_id at the same time" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
530 ) |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
531 cont._xmlui_callback_id = callback_id |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
532 cont._xmlui_on_select(self.on_adv_list_select) |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
533 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
534 self._parse_childs(cont, node, ("row",), data) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
535 else: |
1087
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
536 log.warning(_("Unknown container [%s], using default one") % type_) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
537 cont = self.widget_factory.createVerticalContainer(_xmlui_parent) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
538 self._parse_childs(cont, node, ("widget", "container")) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
539 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
540 xmluiAppend = _xmlui_parent._xmlui_append |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
541 except ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
542 AttributeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
543 TypeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
544 ): # 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
|
545 if _xmlui_parent is self: |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
546 self.main_cont = cont |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
547 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
548 raise Exception( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
549 _("Internal Error, container has not _xmlui_append method") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
550 ) |
2093
cbf3af02e941
frontends(xmlui): better handling of missing _xmluiAppend
Goffi <goffi@goffi.org>
parents:
2036
diff
changeset
|
551 else: |
cbf3af02e941
frontends(xmlui): better handling of missing _xmluiAppend
Goffi <goffi@goffi.org>
parents:
2036
diff
changeset
|
552 xmluiAppend(cont) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
553 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
554 elif node.nodeName == "tab": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
555 name = node.getAttribute("name") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
556 label = node.getAttribute("label") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
557 selected = C.bool(node.getAttribute("selected") or C.BOOL_FALSE) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
558 if not name or not "tabs_cont" in data: |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
559 raise InvalidXMLUI |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
560 if self.type == "param": |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
561 self._current_category = name # XXX: awful hack because params need category and we don't keep parent |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
562 tab_cont = data["tabs_cont"] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
563 new_tab = tab_cont._xmlui_add_tab(label or name, selected) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
564 self._parse_childs(new_tab, node, ("widget", "container")) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
565 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
566 elif node.nodeName == "row": |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
567 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
568 index = str(data["index"]) |
2377
e50aee5caf33
frontends (xmlui): new _xmlui_for_name attribute:
Goffi <goffi@goffi.org>
parents:
2376
diff
changeset
|
569 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
570 index = node.getAttribute("index") or None |
2377
e50aee5caf33
frontends (xmlui): new _xmlui_for_name attribute:
Goffi <goffi@goffi.org>
parents:
2376
diff
changeset
|
571 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
572 data["index"] += 1 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
573 _xmlui_parent._xmlui_add_row(index) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
574 self._parse_childs(_xmlui_parent, node, ("widget", "container")) |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
575 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
576 elif node.nodeName == "widget": |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
577 name = node.getAttribute("name") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
578 if name and ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
579 name in self._ignore |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
580 or self._whitelist is not None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
581 and name not in self._whitelist |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
582 ): |
2419
c38c54c47e16
frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents:
2418
diff
changeset
|
583 # current widget is ignored, but there may be already a label |
c38c54c47e16
frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents:
2418
diff
changeset
|
584 if CURRENT_LABEL in data: |
2995
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
585 curr_label = data.pop(CURRENT_LABEL) |
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
586 if curr_label is not None: |
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
587 # if so, we remove it from parent |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
588 _xmlui_parent._xmlui_remove(curr_label) |
2419
c38c54c47e16
frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents:
2418
diff
changeset
|
589 continue |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
590 type_ = node.getAttribute("type") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
591 value_elt = self._get_child_node(node, "value") |
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
|
592 if value_elt is not None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
593 value = get_text(value_elt) |
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
|
594 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
595 value = ( |
3028 | 596 node.getAttribute("value") if node.hasAttribute("value") else "" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
597 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
598 if type_ == "empty": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
599 ctrl = self.widget_factory.createEmptyWidget(_xmlui_parent) |
2418
69f979adb1d7
frotends(xmlui): fixed _xmlui_for_name attribute for labels
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
600 if CURRENT_LABEL in data: |
69f979adb1d7
frotends(xmlui): fixed _xmlui_for_name attribute for labels
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
601 data[CURRENT_LABEL] = None |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
602 elif type_ == "text": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
603 ctrl = self.widget_factory.createTextWidget(_xmlui_parent, value) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
604 elif type_ == "label": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
605 ctrl = self.widget_factory.createLabelWidget(_xmlui_parent, value) |
2418
69f979adb1d7
frotends(xmlui): fixed _xmlui_for_name attribute for labels
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
606 data[CURRENT_LABEL] = ctrl |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
607 elif type_ == "hidden": |
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
608 if name in self.hidden: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
609 raise exceptions.ConflictError( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
610 "Conflict on hidden value with " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
611 "name {name}".format(name=name) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
612 ) |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
613 self.hidden[name] = value |
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
614 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
615 elif type_ == "jid": |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
616 ctrl = self.widget_factory.createJidWidget(_xmlui_parent, value) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
617 elif type_ == "divider": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
618 style = node.getAttribute("style") or "line" |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
619 ctrl = self.widget_factory.createDividerWidget(_xmlui_parent, style) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
620 elif type_ == "string": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
621 ctrl = self.widget_factory.createStringWidget( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
622 _xmlui_parent, value, self._is_attr_set("read_only", node) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
623 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
624 self.ctrl_list[name] = {"type": type_, "control": ctrl} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
625 elif type_ == "jid_input": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
626 ctrl = self.widget_factory.createJidInputWidget( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
627 _xmlui_parent, value, self._is_attr_set("read_only", node) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
628 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
629 self.ctrl_list[name] = {"type": type_, "control": ctrl} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
630 elif type_ == "password": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
631 ctrl = self.widget_factory.createPasswordWidget( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
632 _xmlui_parent, value, self._is_attr_set("read_only", node) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
633 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
634 self.ctrl_list[name] = {"type": type_, "control": ctrl} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
635 elif type_ == "textbox": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
636 ctrl = self.widget_factory.createTextBoxWidget( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
637 _xmlui_parent, value, self._is_attr_set("read_only", node) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
638 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
639 self.ctrl_list[name] = {"type": type_, "control": ctrl} |
2783
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
640 elif type_ == "xhtmlbox": |
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
641 ctrl = self.widget_factory.createXHTMLBoxWidget( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
642 _xmlui_parent, value, self._is_attr_set("read_only", node) |
2783
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
643 ) |
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
644 self.ctrl_list[name] = {"type": type_, "control": ctrl} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
645 elif type_ == "bool": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
646 ctrl = self.widget_factory.createBoolWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
647 _xmlui_parent, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
648 value == C.BOOL_TRUE, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
649 self._is_attr_set("read_only", node), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
650 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
651 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
|
652 elif type_ == "int": |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
653 ctrl = self.widget_factory.createIntWidget( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
654 _xmlui_parent, value, self._is_attr_set("read_only", node) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
655 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
656 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
|
657 elif type_ == "list": |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
658 style = [] if node.getAttribute("multi") == "yes" else ["single"] |
3028 | 659 for attr in ("noselect", "extensible", "reducible", "inline"): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
660 if node.getAttribute(attr) == "yes": |
2397
7fff98d64ab5
core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents:
2387
diff
changeset
|
661 style.append(attr) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
662 _options = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
663 (option.getAttribute("value"), option.getAttribute("label")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
664 for option in node.getElementsByTagName("option") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
665 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
666 _selected = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
667 option.getAttribute("value") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
668 for option in node.getElementsByTagName("option") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
669 if option.getAttribute("selected") == C.BOOL_TRUE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
670 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
671 ctrl = self.widget_factory.createListWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
672 _xmlui_parent, _options, _selected, style |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
673 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
674 self.ctrl_list[name] = {"type": type_, "control": ctrl} |
1478
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
675 elif type_ == "jids_list": |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
676 style = [] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
677 jids = [get_text(jid_) for jid_ in node.getElementsByTagName("jid")] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
678 ctrl = self.widget_factory.createJidsListWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
679 _xmlui_parent, jids, style |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
680 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
681 self.ctrl_list[name] = {"type": type_, "control": ctrl} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
682 elif type_ == "button": |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
683 callback_id = node.getAttribute("callback") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
684 ctrl = self.widget_factory.createButtonWidget( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
685 _xmlui_parent, value, self.on_button_press |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
686 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
687 ctrl._xmlui_param_id = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
688 callback_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
689 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
690 field.getAttribute("name") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
691 for field in node.getElementsByTagName("field_back") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
692 ], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
693 ) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
694 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
695 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
696 _("FIXME FIXME FIXME: widget type [%s] is not implemented") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
697 % type_ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
698 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
699 raise NotImplementedError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
700 _("FIXME FIXME FIXME: type [%s] is not implemented") % type_ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
701 ) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
702 |
2366
c7a7e650ac2f
frontends (xmlui): a dict of named widgets is kept, so they can be easily be retrieved
Goffi <goffi@goffi.org>
parents:
2361
diff
changeset
|
703 if name: |
c7a7e650ac2f
frontends (xmlui): a dict of named widgets is kept, so they can be easily be retrieved
Goffi <goffi@goffi.org>
parents:
2361
diff
changeset
|
704 self.widgets[name] = ctrl |
c7a7e650ac2f
frontends (xmlui): a dict of named widgets is kept, so they can be easily be retrieved
Goffi <goffi@goffi.org>
parents:
2361
diff
changeset
|
705 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
706 if self.type == "param" and type_ not in ("text", "button"): |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
707 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
708 ctrl._xmlui_on_change(self.on_param_change) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
709 ctrl._param_category = self._current_category |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
710 except ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
711 AttributeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
712 TypeError, |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
713 ): # XXX: TypeError is here because pyjamas raise a TypeError instead |
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
714 # of an AttributeError |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
715 if not isinstance( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
716 ctrl, (EmptyWidget, TextWidget, LabelWidget, JidWidget) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
717 ): |
1087
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
718 log.warning(_("No change listener on [%s]") % ctrl) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
719 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
720 elif type_ != "text": |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
721 callback = node.getAttribute("internal_callback") or None |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
722 if callback: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
723 fields = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
724 field.getAttribute("name") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
725 for field in node.getElementsByTagName("internal_field") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
726 ] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
727 cb_data = self.get_internal_callback_data(callback, node) |
2377
e50aee5caf33
frontends (xmlui): new _xmlui_for_name attribute:
Goffi <goffi@goffi.org>
parents:
2376
diff
changeset
|
728 ctrl._xmlui_param_internal = (callback, fields, cb_data) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
729 if type_ == "button": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
730 ctrl._xmlui_on_click(self.on_change_internal) |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
731 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
732 ctrl._xmlui_on_change(self.on_change_internal) |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
733 |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
734 ctrl._xmlui_name = name |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
735 _xmlui_parent._xmlui_append(ctrl) |
2418
69f979adb1d7
frotends(xmlui): fixed _xmlui_for_name attribute for labels
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
736 if CURRENT_LABEL in data and not isinstance(ctrl, LabelWidget): |
2995
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
737 curr_label = data.pop(CURRENT_LABEL) |
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
738 if curr_label is not None: |
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
739 # this key is set in LabelContainer, when present |
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
740 # we can associate the label with the widget it is labelling |
5ecce65631a2
frontends (xmlui): fixed crash when CURRENT_LABEL is None:
Goffi <goffi@goffi.org>
parents:
2879
diff
changeset
|
741 curr_label._xmlui_for_name = name |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
742 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
743 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
744 raise NotImplementedError(_("Unknown tag [%s]") % node.nodeName) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
745 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
746 def construct_ui(self, parsed_dom, post_treat=None): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
747 """Actually construct the UI |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
748 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
749 @param parsed_dom: main parsed dom |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
750 @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
|
751 @return: constructed widget |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
752 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
753 top = parsed_dom.documentElement |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
754 self.type = top.getAttribute("type") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
755 if top.nodeName != "sat_xmlui" or not self.type in [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
756 "form", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
757 "param", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
758 "window", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
759 "popup", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
760 ]: |
152
b1f1955d96b3
Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents:
149
diff
changeset
|
761 raise InvalidXMLUI |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
762 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
763 if self.type == "param": |
166
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
162
diff
changeset
|
764 self.param_changed = set() |
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
162
diff
changeset
|
765 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
766 self._parse_childs(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
|
767 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
768 if post_treat is not None: |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
769 post_treat() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
770 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
771 def _xmlui_set_param(self, name, value, category): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
772 self.host.bridge.param_set(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
|
773 |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
774 ##EVENTS## |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
775 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
776 def on_param_change(self, ctrl): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
777 """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
|
778 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
779 @param ctrl: widget modified |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
780 """ |
1478
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
781 assert self.type == "param" |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
782 self.param_changed.add(ctrl) |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
783 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
784 def on_adv_list_select(self, ctrl): |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
785 data = {} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
786 widgets = ctrl._xmlui_get_selected_widgets() |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
787 for wid in widgets: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
788 try: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
789 name = self.escape(wid._xmlui_name) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
790 value = wid._xmlui_get_value() |
864
241f6baa6687
frontends: fix typos, do not use logging in the xmlui tools:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
791 data[name] = value |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
792 except ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
793 AttributeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
794 TypeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
795 ): # 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
|
796 pass |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
797 idx = ctrl._xmlui_get_selected_index() |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
798 if idx is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
799 data["index"] = idx |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
800 callback_id = ctrl._xmlui_callback_id |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
801 if callback_id is None: |
1087
b3b7a2863060
frontends (XMLUI): use of logging system instead of print
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
802 log.info(_("No callback_id found")) |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
803 return |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
804 self._xmlui_launch_action(callback_id, data) |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
805 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
806 def on_button_press(self, button): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
807 """Called when an XMLUI button is clicked |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
808 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
809 Launch the action associated to the button |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
810 @param button: the button clicked |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
811 """ |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
812 callback_id, fields = button._xmlui_param_id |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
813 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
|
814 return |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
687
diff
changeset
|
815 data = {} |
157
13888bdb72b6
primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents:
152
diff
changeset
|
816 for field in fields: |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
817 escaped = self.escape(field) |
157
13888bdb72b6
primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents:
152
diff
changeset
|
818 ctrl = self.ctrl_list[field] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
819 if isinstance(ctrl["control"], ListWidget): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
820 data[escaped] = "\t".join(ctrl["control"]._xmlui_get_selected_values()) |
157
13888bdb72b6
primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents:
152
diff
changeset
|
821 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
822 data[escaped] = ctrl["control"]._xmlui_get_value() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
823 self._xmlui_launch_action(callback_id, data) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
824 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
825 def on_change_internal(self, ctrl): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
826 """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
|
827 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
828 This is used to perform some UI actions without communicating with the backend. |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
829 See sat.tools.xml_tools.Widget.set_internal_callback for more details. |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
830 @param ctrl: widget modified |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
831 """ |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
832 action, fields, data = ctrl._xmlui_param_internal |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
833 if action not in ("copy", "move", "groups_of_contact"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
834 raise NotImplementedError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
835 _("FIXME: XMLUI internal action [%s] is not implemented") % action |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
836 ) |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
837 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
838 def copy_move(source, target): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
839 """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
|
840 if isinstance(target, ListWidget): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
841 if isinstance(source, ListWidget): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
842 values = source._xmlui_get_selected_values() |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
843 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
844 values = [source._xmlui_get_value()] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
845 if action == "move": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
846 source._xmlui_set_value("") |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
847 values = [value for value in values if value] |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
848 if values: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
849 target._xmlui_add_values(values, select=True) |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
850 else: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
851 if isinstance(source, ListWidget): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
852 value = ", ".join(source._xmlui_get_selected_values()) |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
853 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
854 value = source._xmlui_get_value() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
855 if action == "move": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
856 source._xmlui_set_value("") |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
857 target._xmlui_set_value(value) |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
858 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
859 def groups_of_contact(source, target): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
860 """Select in target the groups of the contact which is selected in source.""" |
1478
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
861 assert isinstance(source, ListWidget) |
90130847a0a8
frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
862 assert isinstance(target, ListWidget) |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
863 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
864 contact_jid_s = source._xmlui_get_selected_values()[0] |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
865 except IndexError: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
866 return |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
867 target._xmlui_select_values(data[contact_jid_s]) |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
868 pass |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
869 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
870 source = None |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
871 for field in fields: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
872 widget = self.ctrl_list[field]["control"] |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
873 if not source: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
874 source = widget |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
875 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
876 if action in ("copy", "move"): |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
877 copy_move(source, widget) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
878 elif action == "groups_of_contact": |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
879 groups_of_contact(source, widget) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
880 source = None |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
881 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
882 def get_internal_callback_data(self, action, node): |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
883 """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
|
884 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
885 @param action (string): a value from the one that can be passed to the |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
886 'callback' parameter of sat.tools.xml_tools.Widget.set_internal_callback |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
887 @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
|
888 """ |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
889 # 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
|
890 # 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
|
891 # extract any kind of data structure from the 'internal_data' element. |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
892 |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
893 try: # data is stored in the first 'internal_data' element of the node |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
894 data_elts = node.getElementsByTagName("internal_data")[0].childNodes |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
895 except IndexError: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
896 return None |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
897 data = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
898 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
899 action == "groups_of_contact" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
900 ): # return a dict(key: string, value: list[string]) |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
901 for elt in data_elts: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
902 jid_s = elt.getAttribute("name") |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
903 data[jid_s] = [] |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
904 for value_elt in elt.childNodes: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
905 data[jid_s].append(value_elt.getAttribute("name")) |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
906 return data |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
907 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
908 def on_form_submitted(self, ignore=None): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
909 """An XMLUI form has been submited |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
910 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
911 call the submit action associated with this form |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
912 """ |
760
73a0077f80cc
backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
759
diff
changeset
|
913 selected_values = [] |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
914 for ctrl_name in self.ctrl_list: |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
915 escaped = self.escape(ctrl_name) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
916 ctrl = self.ctrl_list[ctrl_name] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
917 if isinstance(ctrl["control"], ListWidget): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
918 selected_values.append( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
919 (escaped, "\t".join(ctrl["control"]._xmlui_get_selected_values())) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
920 ) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
921 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
922 selected_values.append((escaped, ctrl["control"]._xmlui_get_value())) |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
923 data = dict(selected_values) |
3028 | 924 for key, value in self.hidden.items(): |
2668
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
925 data[self.escape(key)] = value |
c274201cea94
core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
926 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
927 if self.submit_id is not None: |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
928 self.submit(data) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
929 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
930 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
931 _("The form data is not sent back, the type is not managed properly") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
932 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
933 self._xmlui_close() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
934 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
935 def on_form_cancelled(self, *__): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
936 """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
|
937 log.debug(_("Cancelling form")) |
1985
9ad1a06ed0f8
frontends (xmlui): cancelling form now trigger submit with {"cancelled": "true"} instead of being silently ignored
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
938 if self.submit_id is not None: |
9ad1a06ed0f8
frontends (xmlui): cancelling form now trigger submit with {"cancelled": "true"} instead of being silently ignored
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
939 data = {C.XMLUI_DATA_CANCELLED: C.BOOL_TRUE} |
9ad1a06ed0f8
frontends (xmlui): cancelling form now trigger submit with {"cancelled": "true"} instead of being silently ignored
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
940 self.submit(data) |
9ad1a06ed0f8
frontends (xmlui): cancelling form now trigger submit with {"cancelled": "true"} instead of being silently ignored
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
941 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
942 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
943 _("The form data is not sent back, the type is not managed properly") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
944 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
945 self._xmlui_close() |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
946 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
947 def on_save_params(self, ignore=None): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
948 """Params are saved, we send them to backend |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
949 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
950 self.type must be param |
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
951 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
952 assert self.type == "param" |
166
b318d2b58887
Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents:
162
diff
changeset
|
953 for ctrl in self.param_changed: |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
954 if isinstance(ctrl, ListWidget): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
955 value = "\t".join(ctrl._xmlui_get_selected_values()) |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
170
diff
changeset
|
956 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
957 value = ctrl._xmlui_get_value() |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
958 param_name = ctrl._xmlui_name.split(C.SAT_PARAM_SEPARATOR)[1] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
959 self._xmlui_set_param(param_name, value, ctrl._param_category) |
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
|
960 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
961 self._xmlui_close() |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
962 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
963 def show(self, *args, **kwargs): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
964 pass |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
965 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
966 |
3040 | 967 class AIOXMLUIPanel(XMLUIPanel): |
968 """Asyncio compatible version of XMLUIPanel""" | |
969 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
970 async def on_form_submitted(self, ignore=None): |
3040 | 971 """An XMLUI form has been submited |
972 | |
973 call the submit action associated with this form | |
974 """ | |
975 selected_values = [] | |
976 for ctrl_name in self.ctrl_list: | |
977 escaped = self.escape(ctrl_name) | |
978 ctrl = self.ctrl_list[ctrl_name] | |
979 if isinstance(ctrl["control"], ListWidget): | |
980 selected_values.append( | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
981 (escaped, "\t".join(ctrl["control"]._xmlui_get_selected_values())) |
3040 | 982 ) |
983 else: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
984 selected_values.append((escaped, ctrl["control"]._xmlui_get_value())) |
3040 | 985 data = dict(selected_values) |
986 for key, value in self.hidden.items(): | |
987 data[self.escape(key)] = value | |
988 | |
989 if self.submit_id is not None: | |
990 await self.submit(data) | |
991 else: | |
992 log.warning( | |
993 _("The form data is not sent back, the type is not managed properly") | |
994 ) | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
995 self._xmlui_close() |
3040 | 996 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
997 async def on_form_cancelled(self, *__): |
3040 | 998 """Called when a form is cancelled""" |
999 log.debug(_("Cancelling form")) | |
1000 if self.submit_id is not None: | |
1001 data = {C.XMLUI_DATA_CANCELLED: C.BOOL_TRUE} | |
1002 await self.submit(data) | |
1003 else: | |
1004 log.warning( | |
1005 _("The form data is not sent back, the type is not managed properly") | |
1006 ) | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1007 self._xmlui_close() |
3040 | 1008 |
1009 async def submit(self, data): | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1010 self._xmlui_close() |
3040 | 1011 if self.submit_id is None: |
1012 raise ValueError("Can't submit is self.submit_id is not set") | |
1013 if "session_id" in data: | |
1014 raise ValueError( | |
1015 "session_id must no be used in data, it is automaticaly filled with " | |
1016 "self.session_id if present" | |
1017 ) | |
1018 if self.session_id is not None: | |
1019 data["session_id"] = self.session_id | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1020 await self._xmlui_launch_action(self.submit_id, data) |
3040 | 1021 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1022 async def _xmlui_launch_action(self, action_id, data): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1023 await self.host.action_launch( |
3040 | 1024 action_id, data, callback=self.callback, profile=self.profile |
1025 ) | |
1026 | |
1027 | |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1028 class XMLUIDialog(XMLUIBase): |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1029 dialog_factory = None |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1030 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1031 def __init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1032 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1033 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1034 parsed_dom, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1035 title=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1036 flags=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1037 callback=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1038 ignore=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1039 whitelist=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1040 profile=C.PROF_KEY_NONE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1041 ): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1042 super(XMLUIDialog, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1043 host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1044 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1045 top = parsed_dom.documentElement |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1046 dlg_elt = self._get_child_node(top, "dialog") |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1047 if dlg_elt is None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1048 raise ValueError("Invalid XMLUI: no Dialog element found !") |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1049 dlg_type = dlg_elt.getAttribute("type") or C.XMLUI_DIALOG_MESSAGE |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1050 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1051 mess_elt = self._get_child_node(dlg_elt, C.XMLUI_DATA_MESS) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1052 message = get_text(mess_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1053 except ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1054 TypeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1055 AttributeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1056 ): # 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
|
1057 message = "" |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1058 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
|
1059 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1060 if dlg_type == C.XMLUI_DIALOG_MESSAGE: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1061 self.dlg = self.dialog_factory.createMessageDialog( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1062 self, self.xmlui_title, message, level |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1063 ) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1064 elif dlg_type == C.XMLUI_DIALOG_NOTE: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1065 self.dlg = self.dialog_factory.createNoteDialog( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1066 self, self.xmlui_title, message, level |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1067 ) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1068 elif dlg_type == C.XMLUI_DIALOG_CONFIRM: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1069 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1070 buttons_elt = self._get_child_node(dlg_elt, "buttons") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1071 buttons_set = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1072 buttons_elt.getAttribute("set") or C.XMLUI_DATA_BTNS_SET_DEFAULT |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1073 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1074 except ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1075 TypeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1076 AttributeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1077 ): # 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
|
1078 buttons_set = C.XMLUI_DATA_BTNS_SET_DEFAULT |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1079 self.dlg = self.dialog_factory.createConfirmDialog( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1080 self, self.xmlui_title, message, level, buttons_set |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1081 ) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1082 elif dlg_type == C.XMLUI_DIALOG_FILE: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1083 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1084 file_elt = self._get_child_node(dlg_elt, "file") |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1085 filetype = file_elt.getAttribute("type") or C.XMLUI_DATA_FILETYPE_DEFAULT |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1086 except ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1087 TypeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1088 AttributeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1089 ): # 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
|
1090 filetype = C.XMLUI_DATA_FILETYPE_DEFAULT |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1091 self.dlg = self.dialog_factory.createFileDialog( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1092 self, self.xmlui_title, message, level, filetype |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1093 ) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1094 else: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1095 raise ValueError("Unknown dialog type [%s]" % dlg_type) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1096 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1097 def show(self): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1098 self.dlg._xmlui_show() |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1099 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1100 def _xmlui_close(self): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1101 self.dlg._xmlui_close() |
1579
d5e332055d9f
quick_frontend, primitivus (xmlui): removed _xmluiClose from workflow were submit is triggered, as submit launch the callback which close the dialog itself + fixed dialogs _xmluiClose
Goffi <goffi@goffi.org>
parents:
1501
diff
changeset
|
1102 |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1103 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1104 def register_class(type_, class_): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1105 """Register the class to use with the factory |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1106 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1107 @param type_: one of: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1108 CLASS_PANEL: classical XMLUI interface |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1109 CLASS_DIALOG: XMLUI dialog |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1110 @param class_: the class to use to instanciate given type |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1111 """ |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2668
diff
changeset
|
1112 # TODO: remove this method, as there are seme use cases where different XMLUI |
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2668
diff
changeset
|
1113 # classes can be used in the same frontend, so a global value is not good |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1114 assert type_ in (CLASS_PANEL, CLASS_DIALOG) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1115 log.warning( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1116 "register_class for XMLUI is deprecated, please use partial with " |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1117 "xmlui.create and class_map instead" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1118 ) |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2668
diff
changeset
|
1119 if type_ in _class_map: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1120 log.debug( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1121 _("XMLUI class already registered for {type_}, ignoring").format(type_=type_) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1122 ) |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2668
diff
changeset
|
1123 return |
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2668
diff
changeset
|
1124 |
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2668
diff
changeset
|
1125 _class_map[type_] = class_ |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1126 |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1127 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1128 def create( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1129 host, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1130 xml_data, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1131 title=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1132 flags=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1133 dom_parse=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1134 dom_free=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1135 callback=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1136 ignore=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1137 whitelist=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1138 class_map=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1139 profile=C.PROF_KEY_NONE, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1140 ): |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1141 """ |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1142 @param dom_parse: methode equivalent to minidom.parseString (but which must manage unicode), or None to use default one |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1143 @param dom_free: method used to free the parsed DOM |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1144 @param ignore(list[unicode], None): name of widgets to ignore |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1145 widgets with name in this list and their label will be ignored |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1146 @param whitelist(list[unicode], None): name of widgets to keep |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1147 when not None, only widgets in this list and their label will be kept |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
1148 mutually exclusive with ignore |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1149 """ |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2668
diff
changeset
|
1150 if class_map is None: |
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2668
diff
changeset
|
1151 class_map = _class_map |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1152 if dom_parse is None: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1153 from xml.dom import minidom |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1154 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1155 dom_parse = lambda xml_data: minidom.parseString(xml_data.encode("utf-8")) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1156 dom_free = lambda parsed_dom: parsed_dom.unlink() |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1157 else: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1158 dom_parse = dom_parse |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1159 dom_free = dom_free or (lambda parsed_dom: None) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1160 parsed_dom = dom_parse(xml_data) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1161 top = parsed_dom.documentElement |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1162 ui_type = top.getAttribute("type") |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1163 try: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1164 if ui_type != C.XMLUI_DIALOG: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1165 cls = class_map[CLASS_PANEL] |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1166 else: |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1167 cls = class_map[CLASS_DIALOG] |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1168 except KeyError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1169 raise ClassNotRegistedError( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1170 _("You must register classes with register_class before creating a XMLUI") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1171 ) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1172 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1173 xmlui = cls( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1174 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1175 parsed_dom, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1176 title=title, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1177 flags=flags, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1178 callback=callback, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1179 ignore=ignore, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1180 whitelist=whitelist, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1181 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1182 ) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1183 dom_free(parsed_dom) |
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
1184 return xmlui |