Mercurial > libervia-backend
annotate libervia/cli/xmlui_manager.py @ 4165:81faa85c9cfa
template: add a `bare_jid` filter
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 28 Nov 2023 17:41:49 +0100 |
parents | 47401850dec6 |
children |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
2408 | 3 |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
4 # Libervia CLI |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
2408 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
3040 | 20 from functools import partial |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
21 from libervia.backend.core.log import getLogger |
4074
26b7ed2817da
refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
22 from libervia.frontends.tools import xmlui as xmlui_base |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
23 from libervia.cli.constants import Const as C |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
24 from libervia.backend.tools.common.ansi import ANSI as A |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
25 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
26 from libervia.backend.tools.common import data_format |
3040 | 27 |
28 log = getLogger(__name__) | |
2408 | 29 |
30 # workflow constants | |
31 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
32 SUBMIT = "SUBMIT" # submit form |
2408 | 33 |
34 | |
35 ## Widgets ## | |
36 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
37 |
2408 | 38 class Base(object): |
39 """Base for Widget and Container""" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
40 |
2408 | 41 type = None |
42 _root = None | |
43 | |
44 def __init__(self, xmlui_parent): | |
45 self.xmlui_parent = xmlui_parent | |
46 self.host = self.xmlui_parent.host | |
47 | |
48 @property | |
49 def root(self): | |
50 """retrieve main XMLUI parent class""" | |
51 if self._root is not None: | |
52 return self._root | |
53 root = self | |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
54 while not isinstance(root, xmlui_base.XMLUIBase): |
2408 | 55 root = root.xmlui_parent |
56 self._root = root | |
57 return root | |
58 | |
59 def disp(self, *args, **kwargs): | |
60 self.host.disp(*args, **kwargs) | |
61 | |
62 | |
63 class Widget(Base): | |
3028 | 64 category = "widget" |
2408 | 65 enabled = True |
66 | |
67 @property | |
68 def name(self): | |
69 return self._xmlui_name | |
70 | |
3040 | 71 async def show(self): |
2408 | 72 """display current widget |
73 | |
74 must be overriden by subclasses | |
75 """ | |
76 raise NotImplementedError(self.__class__) | |
77 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
78 def verbose_name(self, elems=None, value=None): |
2408 | 79 """add name in color to the elements |
80 | |
81 helper method to display name which can then be used to automate commands | |
82 elems is only modified if verbosity is > 0 | |
83 @param elems(list[unicode], None): elements to display | |
84 None to display name directly | |
85 @param value(unicode, None): value to show | |
86 use self.name if None | |
87 """ | |
88 if value is None: | |
89 value = self.name | |
90 if self.host.verbosity: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
91 to_disp = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 A.FG_MAGENTA, |
3028 | 93 " " if elems else "", |
94 "({})".format(value), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 A.RESET, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 ] |
2408 | 97 if elems is None: |
98 self.host.disp(A.color(*to_disp)) | |
99 else: | |
100 elems.extend(to_disp) | |
101 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 |
2408 | 103 class ValueWidget(Widget): |
104 def __init__(self, xmlui_parent, value): | |
105 super(ValueWidget, self).__init__(xmlui_parent) | |
106 self.value = value | |
107 | |
108 @property | |
109 def values(self): | |
110 return [self.value] | |
111 | |
112 | |
113 class InputWidget(ValueWidget): | |
114 def __init__(self, xmlui_parent, value, read_only=False): | |
115 super(InputWidget, self).__init__(xmlui_parent, value) | |
116 self.read_only = read_only | |
117 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
118 def _xmlui_get_value(self): |
2408 | 119 return self.value |
120 | |
121 | |
122 class OptionsWidget(Widget): | |
123 def __init__(self, xmlui_parent, options, selected, style): | |
124 super(OptionsWidget, self).__init__(xmlui_parent) | |
125 self.options = options | |
126 self.selected = selected | |
127 self.style = style | |
128 | |
129 @property | |
130 def values(self): | |
131 return self.selected | |
132 | |
133 @values.setter | |
134 def values(self, values): | |
135 self.selected = values | |
136 | |
137 @property | |
138 def value(self): | |
139 return self.selected[0] | |
140 | |
141 @value.setter | |
142 def value(self, value): | |
143 self.selected = [value] | |
144 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
145 def _xmlui_select_value(self, value): |
2408 | 146 self.value = value |
147 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
148 def _xmlui_select_values(self, values): |
2408 | 149 self.values = values |
150 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
151 def _xmlui_get_selected_values(self): |
2408 | 152 return self.values |
153 | |
154 @property | |
155 def labels(self): | |
156 """return only labels from self.items""" | |
157 for value, label in self.items: | |
158 yield label | |
159 | |
160 @property | |
161 def items(self): | |
162 """return suitable items, according to style""" | |
163 no_select = self.no_select | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
164 for value, label in self.options: |
2408 | 165 if no_select or value in self.selected: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
166 yield value, label |
2408 | 167 |
168 @property | |
169 def inline(self): | |
3028 | 170 return "inline" in self.style |
2408 | 171 |
172 @property | |
173 def no_select(self): | |
3028 | 174 return "noselect" in self.style |
2408 | 175 |
176 | |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
177 class EmptyWidget(xmlui_base.EmptyWidget, Widget): |
2739
e8dc00f612fb
jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
178 def __init__(self, xmlui_parent): |
e8dc00f612fb
jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
179 Widget.__init__(self, xmlui_parent) |
e8dc00f612fb
jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
180 |
3040 | 181 async def show(self): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
182 self.host.disp("") |
2408 | 183 |
184 | |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
185 class TextWidget(xmlui_base.TextWidget, ValueWidget): |
3028 | 186 type = "text" |
2408 | 187 |
3040 | 188 async def show(self): |
2408 | 189 self.host.disp(self.value) |
190 | |
191 | |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
192 class LabelWidget(xmlui_base.LabelWidget, ValueWidget): |
3028 | 193 type = "label" |
2408 | 194 |
195 @property | |
196 def for_name(self): | |
197 try: | |
198 return self._xmlui_for_name | |
199 except AttributeError: | |
200 return None | |
201 | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
202 async def show(self, end="\n", ansi=""): |
2408 | 203 """show label |
204 | |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
205 @param end(str): same as for [LiberviaCli.disp] |
2408 | 206 @param ansi(unicode): ansi escape code to print before label |
207 """ | |
3407
2f0be2b7de68
jp: replace `no_lf` argument by `end` in `disp` (same as in `print`)
Goffi <goffi@goffi.org>
parents:
3212
diff
changeset
|
208 self.disp(A.color(ansi, self.value), end=end) |
2408 | 209 |
210 | |
2739
e8dc00f612fb
jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
211 class JidWidget(xmlui_base.JidWidget, TextWidget): |
3028 | 212 type = "jid" |
2739
e8dc00f612fb
jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
213 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
214 |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
215 class StringWidget(xmlui_base.StringWidget, InputWidget): |
3028 | 216 type = "string" |
2408 | 217 |
3040 | 218 async def show(self): |
2961
620bbcec884c
jp (xmlui): check root read_only status in addition to widget one
Goffi <goffi@goffi.org>
parents:
2960
diff
changeset
|
219 if self.read_only or self.root.read_only: |
2408 | 220 self.disp(self.value) |
221 else: | |
222 elems = [] | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
223 self.verbose_name(elems) |
2408 | 224 if self.value: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
225 elems.append(_("(enter: {value})").format(value=self.value)) |
3028 | 226 elems.extend([C.A_HEADER, "> "]) |
3040 | 227 value = await self.host.ainput(A.color(*elems)) |
2408 | 228 if value: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
229 # TODO: empty value should be possible |
2408 | 230 # an escape key should be used for default instead of enter with empty value |
231 self.value = value | |
232 | |
233 | |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
234 class JidInputWidget(xmlui_base.JidInputWidget, StringWidget): |
3028 | 235 type = "jid_input" |
2408 | 236 |
237 | |
3748 | 238 class PasswordWidget(xmlui_base.PasswordWidget, StringWidget): |
239 type = "password" | |
240 | |
241 | |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
242 class TextBoxWidget(xmlui_base.TextWidget, StringWidget): |
3028 | 243 type = "textbox" |
2939
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
244 # TODO: use a more advanced input method |
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
245 |
3040 | 246 async def show(self): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
247 self.verbose_name() |
2961
620bbcec884c
jp (xmlui): check root read_only status in addition to widget one
Goffi <goffi@goffi.org>
parents:
2960
diff
changeset
|
248 if self.read_only or self.root.read_only: |
2939
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
249 self.disp(self.value) |
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
250 else: |
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
251 if self.value: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
252 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
253 A.color(C.A_HEADER, "↓ current value ↓\n", A.FG_CYAN, self.value, "") |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
254 ) |
2939
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
255 |
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
256 values = [] |
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
257 while True: |
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
258 try: |
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
259 if not values: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
260 line = await self.host.ainput( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
261 A.color(C.A_HEADER, "[Ctrl-D to finish]> ") |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
262 ) |
2939
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
263 else: |
3040 | 264 line = await self.host.ainput() |
2939
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
265 values.append(line) |
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
266 except EOFError: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
267 break |
2939
18a98a541f7a
jp (xmlui manager): basic handling of multi-lines text in TextBoxWidget
Goffi <goffi@goffi.org>
parents:
2783
diff
changeset
|
268 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
269 self.value = "\n".join(values).rstrip() |
2408 | 270 |
271 | |
2783
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
272 class XHTMLBoxWidget(xmlui_base.XHTMLBoxWidget, StringWidget): |
3028 | 273 type = "xhtmlbox" |
2783
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
274 |
3040 | 275 async def show(self): |
2783
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
276 # FIXME: we use bridge in a blocking way as permitted by python-dbus |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
277 # this only for now to make it simpler, it must be refactored to use async |
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
278 # when libervia-cli will be fully async (expected for 0.8) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
279 self.value = await self.host.bridge.syntax_convert( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
280 self.value, C.SYNTAX_XHTML, "markdown", False, self.host.profile |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
281 ) |
3040 | 282 await super(XHTMLBoxWidget, self).show() |
2783
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
283 |
442ab697f831
frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
284 |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
285 class ListWidget(xmlui_base.ListWidget, OptionsWidget): |
3028 | 286 type = "list" |
2408 | 287 # TODO: handle flags, notably multi |
288 | |
3040 | 289 async def show(self): |
2541
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
290 if self.root.values_only: |
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
291 for value in self.values: |
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
292 self.disp(self.value) |
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
293 return |
2408 | 294 if not self.options: |
295 return | |
296 | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
297 # list display |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
298 self.verbose_name() |
2408 | 299 |
300 for idx, (value, label) in enumerate(self.options): | |
301 elems = [] | |
2541
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
302 if not self.root.read_only: |
3028 | 303 elems.extend([C.A_SUBHEADER, str(idx), A.RESET, ": "]) |
2408 | 304 elems.append(label) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
305 self.verbose_name(elems, value) |
2408 | 306 self.disp(A.color(*elems)) |
307 | |
2541
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
308 if self.root.read_only: |
2408 | 309 return |
310 | |
311 if len(self.options) == 1: | |
312 # we have only one option, no need to ask | |
313 self.value = self.options[0][0] | |
314 return | |
315 | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
316 # we ask use to choose an option |
2408 | 317 choice = None |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
318 limit_max = len(self.options) - 1 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
319 while choice is None or choice < 0 or choice > limit_max: |
3040 | 320 choice = await self.host.ainput( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
321 A.color( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
322 C.A_HEADER, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
323 _("your choice (0-{limit_max}): ").format(limit_max=limit_max), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
324 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
325 ) |
2408 | 326 try: |
327 choice = int(choice) | |
328 except ValueError: | |
329 choice = None | |
330 self.value = self.options[choice][0] | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
331 self.disp("") |
2408 | 332 |
333 | |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
334 class BoolWidget(xmlui_base.BoolWidget, InputWidget): |
3028 | 335 type = "bool" |
2408 | 336 |
3040 | 337 async def show(self): |
3028 | 338 disp_true = A.color(A.FG_GREEN, "TRUE") |
339 disp_false = A.color(A.FG_RED, "FALSE") | |
2961
620bbcec884c
jp (xmlui): check root read_only status in addition to widget one
Goffi <goffi@goffi.org>
parents:
2960
diff
changeset
|
340 if self.read_only or self.root.read_only: |
2408 | 341 self.disp(disp_true if self.value else disp_false) |
342 else: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
343 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
344 A.color( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
345 C.A_HEADER, "0: ", disp_false, A.RESET, " *" if not self.value else "" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
346 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
347 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
348 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
349 A.color(C.A_HEADER, "1: ", disp_true, A.RESET, " *" if self.value else "") |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
350 ) |
2408 | 351 choice = None |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
352 while choice not in ("0", "1"): |
3028 | 353 elems = [C.A_HEADER, _("your choice (0,1): ")] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
354 self.verbose_name(elems) |
3040 | 355 choice = await self.host.ainput(A.color(*elems)) |
2408 | 356 self.value = bool(int(choice)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
357 self.disp("") |
2408 | 358 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
359 def _xmlui_get_value(self): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
360 return C.bool_const(self.value) |
2408 | 361 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
362 ## Containers ## |
2408 | 363 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
364 |
2408 | 365 class Container(Base): |
3028 | 366 category = "container" |
2408 | 367 |
368 def __init__(self, xmlui_parent): | |
369 super(Container, self).__init__(xmlui_parent) | |
370 self.children = [] | |
371 | |
372 def __iter__(self): | |
373 return iter(self.children) | |
374 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
375 def _xmlui_append(self, widget): |
2408 | 376 self.children.append(widget) |
377 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
378 def _xmlui_remove(self, widget): |
2541
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
379 self.children.remove(widget) |
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
380 |
3040 | 381 async def show(self): |
2408 | 382 for child in self.children: |
3040 | 383 await child.show() |
2408 | 384 |
385 | |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
386 class VerticalContainer(xmlui_base.VerticalContainer, Container): |
3028 | 387 type = "vertical" |
2408 | 388 |
389 | |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
390 class PairsContainer(xmlui_base.PairsContainer, Container): |
3028 | 391 type = "pairs" |
2408 | 392 |
393 | |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
394 class LabelContainer(xmlui_base.PairsContainer, Container): |
3028 | 395 type = "label" |
2408 | 396 |
3040 | 397 async def show(self): |
2408 | 398 for child in self.children: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
399 end = "\n" |
2408 | 400 # we check linked widget type |
401 # to see if we want the label on the same line or not | |
3028 | 402 if child.type == "label": |
2408 | 403 for_name = child.for_name |
2739
e8dc00f612fb
jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
404 if for_name: |
2408 | 405 for_widget = self.root.widgets[for_name] |
406 wid_type = for_widget.type | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
407 if self.root.values_only or wid_type in ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
408 "text", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
409 "string", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
410 "jid_input", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
411 ): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
412 end = " " |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
413 elif wid_type == "bool" and for_widget.read_only: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
414 end = " " |
3407
2f0be2b7de68
jp: replace `no_lf` argument by `end` in `disp` (same as in `print`)
Goffi <goffi@goffi.org>
parents:
3212
diff
changeset
|
415 await child.show(end=end, ansi=A.FG_CYAN) |
2408 | 416 else: |
3040 | 417 await child.show() |
2408 | 418 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
419 ## Dialogs ## |
2408 | 420 |
421 | |
422 class Dialog(object): | |
423 def __init__(self, xmlui_parent): | |
424 self.xmlui_parent = xmlui_parent | |
425 self.host = self.xmlui_parent.host | |
426 | |
427 def disp(self, *args, **kwargs): | |
428 self.host.disp(*args, **kwargs) | |
429 | |
3040 | 430 async def show(self): |
2408 | 431 """display current dialog |
432 | |
433 must be overriden by subclasses | |
434 """ | |
435 raise NotImplementedError(self.__class__) | |
436 | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
437 |
3040 | 438 class MessageDialog(xmlui_base.MessageDialog, Dialog): |
439 def __init__(self, xmlui_parent, title, message, level): | |
440 Dialog.__init__(self, xmlui_parent) | |
441 xmlui_base.MessageDialog.__init__(self, xmlui_parent) | |
442 self.title, self.message, self.level = title, message, level | |
443 | |
444 async def show(self): | |
445 # TODO: handle level | |
446 if self.title: | |
447 self.disp(A.color(C.A_HEADER, self.title)) | |
448 self.disp(self.message) | |
449 | |
2408 | 450 |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
451 class NoteDialog(xmlui_base.NoteDialog, Dialog): |
2739
e8dc00f612fb
jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
452 def __init__(self, xmlui_parent, title, message, level): |
e8dc00f612fb
jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
453 Dialog.__init__(self, xmlui_parent) |
e8dc00f612fb
jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
454 xmlui_base.NoteDialog.__init__(self, xmlui_parent) |
2408 | 455 self.title, self.message, self.level = title, message, level |
456 | |
3040 | 457 async def show(self): |
3093
d909473a76cc
jp (xmlui_manager): use level for notes:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
458 # TODO: handle title |
d909473a76cc
jp (xmlui_manager): use level for notes:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
459 error = self.level in (C.XMLUI_DATA_LVL_WARNING, C.XMLUI_DATA_LVL_ERROR) |
d909473a76cc
jp (xmlui_manager): use level for notes:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
460 if self.level == C.XMLUI_DATA_LVL_WARNING: |
d909473a76cc
jp (xmlui_manager): use level for notes:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
461 msg = A.color(C.A_WARNING, self.message) |
d909473a76cc
jp (xmlui_manager): use level for notes:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
462 elif self.level == C.XMLUI_DATA_LVL_ERROR: |
d909473a76cc
jp (xmlui_manager): use level for notes:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
463 msg = A.color(C.A_FAILURE, self.message) |
d909473a76cc
jp (xmlui_manager): use level for notes:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
464 else: |
d909473a76cc
jp (xmlui_manager): use level for notes:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
465 msg = self.message |
d909473a76cc
jp (xmlui_manager): use level for notes:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
466 self.disp(msg, error=error) |
3040 | 467 |
468 | |
469 class ConfirmDialog(xmlui_base.ConfirmDialog, Dialog): | |
470 def __init__(self, xmlui_parent, title, message, level, buttons_set): | |
471 Dialog.__init__(self, xmlui_parent) | |
472 xmlui_base.ConfirmDialog.__init__(self, xmlui_parent) | |
473 self.title, self.message, self.level, self.buttons_set = ( | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
474 title, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
475 message, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
476 level, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
477 buttons_set, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
478 ) |
3040 | 479 |
480 async def show(self): | |
481 # TODO: handle buttons_set and level | |
482 self.disp(self.message) | |
483 if self.title: | |
484 self.disp(A.color(C.A_HEADER, self.title)) | |
485 input_ = None | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
486 while input_ not in ("y", "n"): |
3040 | 487 input_ = await self.host.ainput(f"{self.message} (y/n)? ") |
488 input_ = input_.lower() | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
489 if input_ == "y": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
490 self._xmlui_validated() |
3040 | 491 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
492 self._xmlui_cancelled() |
3040 | 493 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
494 ## Factory ## |
2408 | 495 |
496 | |
497 class WidgetFactory(object): | |
498 def __getattr__(self, attr): | |
499 if attr.startswith("create"): | |
500 cls = globals()[attr[6:]] | |
501 return cls | |
502 | |
503 | |
3040 | 504 class XMLUIPanel(xmlui_base.AIOXMLUIPanel): |
2408 | 505 widget_factory = WidgetFactory() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
506 _actions = 0 # use to keep track of bridge's action_launch calls |
2541
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
507 read_only = False |
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
508 values_only = False |
2408 | 509 workflow = None |
510 _submit_cb = None | |
511 | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
512 def __init__( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
513 self, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
514 host, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
515 parsed_dom, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
516 title=None, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
517 flags=None, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
518 callback=None, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
519 ignore=None, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
520 whitelist=None, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
521 profile=None, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
522 ): |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
523 xmlui_base.XMLUIPanel.__init__( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
524 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
525 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
526 parsed_dom, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
527 title=title, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
528 flags=flags, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
529 ignore=ignore, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
530 whitelist=whitelist, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
531 profile=host.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
532 ) |
2408 | 533 self.submitted = False |
534 | |
535 @property | |
536 def command(self): | |
537 return self.host.command | |
538 | |
3212
89d97776fd34
jp (xmlui): added missing `disp` method in XMLUIPanel
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
539 def disp(self, *args, **kwargs): |
89d97776fd34
jp (xmlui): added missing `disp` method in XMLUIPanel
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
540 self.host.disp(*args, **kwargs) |
89d97776fd34
jp (xmlui): added missing `disp` method in XMLUIPanel
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
541 |
3040 | 542 async def show(self, workflow=None, read_only=False, values_only=False): |
2408 | 543 """display the panel |
544 | |
545 @param workflow(list, None): command to execute if not None | |
546 put here for convenience, the main workflow is the class attribute | |
547 (because workflow can continue in subclasses) | |
548 command are a list of consts or lists: | |
549 - SUBMIT is the only constant so far, it submits the XMLUI | |
550 - list must contain widget name/widget value to fill | |
2541
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
551 @param read_only(bool): if True, don't request values |
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
552 @param values_only(bool): if True, only show select values (imply read_only) |
2408 | 553 """ |
2541
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
554 self.read_only = read_only |
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
555 self.values_only = values_only |
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
556 if self.values_only: |
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
557 self.read_only = True |
2408 | 558 if workflow: |
559 XMLUIPanel.workflow = workflow | |
560 if XMLUIPanel.workflow: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
561 await self.run_workflow() |
2408 | 562 else: |
3040 | 563 await self.main_cont.show() |
2408 | 564 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
565 async def run_workflow(self): |
2408 | 566 """loop into workflow commands and execute commands |
567 | |
568 SUBMIT will interrupt workflow (which will be continue on callback) | |
569 @param workflow(list): same as [show] | |
570 """ | |
571 workflow = XMLUIPanel.workflow | |
572 while True: | |
573 try: | |
574 cmd = workflow.pop(0) | |
575 except IndexError: | |
576 break | |
577 if cmd == SUBMIT: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
578 await self.on_form_submitted() |
2408 | 579 self.submit_id = None # avoid double submit |
580 return | |
581 elif isinstance(cmd, list): | |
582 name, value = cmd | |
2412
7641bef56dcd
jp (xmlui): fixed workflow when value is for a BoolWidget
Goffi <goffi@goffi.org>
parents:
2410
diff
changeset
|
583 widget = self.widgets[name] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
584 if widget.type == "bool": |
2412
7641bef56dcd
jp (xmlui): fixed workflow when value is for a BoolWidget
Goffi <goffi@goffi.org>
parents:
2410
diff
changeset
|
585 value = C.bool(value) |
7641bef56dcd
jp (xmlui): fixed workflow when value is for a BoolWidget
Goffi <goffi@goffi.org>
parents:
2410
diff
changeset
|
586 widget.value = value |
3040 | 587 await self.show() |
2408 | 588 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
589 async def submit_form(self, callback=None): |
2408 | 590 XMLUIPanel._submit_cb = callback |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
591 await self.on_form_submitted() |
2408 | 592 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
593 async def on_form_submitted(self, ignore=None): |
3040 | 594 # self.submitted is a Q&D workaround to avoid |
2408 | 595 # double submit when a workflow is set |
596 if self.submitted: | |
597 return | |
598 self.submitted = True | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
599 await super(XMLUIPanel, self).on_form_submitted(ignore) |
2408 | 600 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
601 def _xmlui_close(self): |
2408 | 602 pass |
603 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
604 async def _launch_action_cb(self, data): |
2408 | 605 XMLUIPanel._actions -= 1 |
606 assert XMLUIPanel._actions >= 0 | |
3028 | 607 if "xmlui" in data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
608 xmlui_raw = data["xmlui"] |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
609 xmlui = create(self.host, xmlui_raw) |
3040 | 610 await xmlui.show() |
2408 | 611 if xmlui.submit_id: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
612 await xmlui.on_form_submitted() |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
613 # TODO: handle data other than XMLUI |
2408 | 614 if not XMLUIPanel._actions: |
615 if self._submit_cb is None: | |
616 self.host.quit() | |
617 else: | |
618 self._submit_cb() | |
619 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
620 async def _xmlui_launch_action(self, action_id, data): |
2408 | 621 XMLUIPanel._actions += 1 |
3040 | 622 try: |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
623 data = data_format.deserialise( |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
624 await self.host.bridge.action_launch( |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
625 action_id, |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
626 data_format.serialise(data), |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
627 self.profile, |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
628 ) |
3040 | 629 ) |
630 except Exception as e: | |
631 self.disp(f"can't launch XMLUI action: {e}", error=True) | |
632 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
633 else: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
634 await self._launch_action_cb(data) |
2408 | 635 |
636 | |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
637 class XMLUIDialog(xmlui_base.XMLUIDialog): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
638 type = "dialog" |
2408 | 639 dialog_factory = WidgetFactory() |
2541
65695b9343d3
jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
640 read_only = False |
2408 | 641 |
3040 | 642 async def show(self, __=None): |
643 await self.dlg.show() | |
2408 | 644 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3748
diff
changeset
|
645 def _xmlui_close(self): |
2408 | 646 pass |
647 | |
648 | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
649 create = partial( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
650 xmlui_base.create, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
651 class_map={xmlui_base.CLASS_PANEL: XMLUIPanel, xmlui_base.CLASS_DIALOG: XMLUIDialog}, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
652 ) |