annotate sat_frontends/jp/xmlui_manager.py @ 2739:e8dc00f612fb

jp (xmlui): JidWidget + small improvments: - JidWidget is now handled basically using TextWidget. - EmptyWidget display an empty line. - BoolWidget display current value with an asterisk when write is allowed. - fixed an bug in LabelContainer when for_name was not specified.
author Goffi <goffi@goffi.org>
date Wed, 02 Jan 2019 18:50:47 +0100
parents bdb8276fd2da
children 378188abe941
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # JP: a SàT frontend
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2419
diff changeset
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
21
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 log = getLogger(__name__)
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
23 from sat_frontends.tools import xmlui as xmlui_base
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat_frontends.jp.constants import Const as C
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.tools.common.ansi import ANSI as A
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.core.i18n import _
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from functools import partial
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 # workflow constants
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
31 SUBMIT = "SUBMIT" # submit form
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 ## Widgets ##
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 class Base(object):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 """Base for Widget and Container"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 type = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 _root = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 def __init__(self, xmlui_parent):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.xmlui_parent = xmlui_parent
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.host = self.xmlui_parent.host
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def root(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 """retrieve main XMLUI parent class"""
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 if self._root is not None:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 return self._root
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 root = self
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
53 while not isinstance(root, xmlui_base.XMLUIBase):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 root = root.xmlui_parent
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self._root = root
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 return root
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 def disp(self, *args, **kwargs):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.host.disp(*args, **kwargs)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 class Widget(Base):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 category = u"widget"
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 enabled = True
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 def name(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 return self._xmlui_name
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 """display current widget
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
72
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 must be overriden by subclasses
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 """
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 raise NotImplementedError(self.__class__)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 def verboseName(self, elems=None, value=None):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 """add name in color to the elements
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 helper method to display name which can then be used to automate commands
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 elems is only modified if verbosity is > 0
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 @param elems(list[unicode], None): elements to display
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 None to display name directly
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 @param value(unicode, None): value to show
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 use self.name if None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 """
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 if value is None:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 value = self.name
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 if self.host.verbosity:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 to_disp = [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 A.FG_MAGENTA,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 u" " if elems else u"",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 u"({})".format(value),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 A.RESET,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 ]
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 if elems is None:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 self.host.disp(A.color(*to_disp))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 else:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 elems.extend(to_disp)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
100
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 class ValueWidget(Widget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 def __init__(self, xmlui_parent, value):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 super(ValueWidget, self).__init__(xmlui_parent)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.value = value
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 def values(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 return [self.value]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 class InputWidget(ValueWidget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 def __init__(self, xmlui_parent, value, read_only=False):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 super(InputWidget, self).__init__(xmlui_parent, value)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 self.read_only = read_only
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 def _xmluiGetValue(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 return self.value
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 class OptionsWidget(Widget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 def __init__(self, xmlui_parent, options, selected, style):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 super(OptionsWidget, self).__init__(xmlui_parent)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 self.options = options
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 self.selected = selected
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self.style = style
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 def values(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 return self.selected
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 @values.setter
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 def values(self, values):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 self.selected = values
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 def value(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 return self.selected[0]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
139
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 @value.setter
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 def value(self, value):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 self.selected = [value]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
143
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 def _xmluiSelectValue(self, value):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 self.value = value
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
146
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 def _xmluiSelectValues(self, values):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 self.values = values
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
149
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 def _xmluiGetSelectedValues(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 return self.values
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
152
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 def labels(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 """return only labels from self.items"""
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 for value, label in self.items:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 yield label
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
158
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 def items(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 """return suitable items, according to style"""
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 no_select = self.no_select
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 for value, label in self.options:
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 if no_select or value in self.selected:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
165 yield value, label
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
166
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 def inline(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 return u"inline" in self.style
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 def no_select(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 return u"noselect" in self.style
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
174
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
175
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
176 class EmptyWidget(xmlui_base.EmptyWidget, Widget):
2739
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
177
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
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
181 def show(self):
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
182 self.host.disp(u'')
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
183
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 type = u"text"
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
187
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 self.host.disp(self.value)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
190
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
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):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 type = u"label"
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
194
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 def for_name(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 try:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 return self._xmlui_for_name
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 except AttributeError:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 return None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
201
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
202 def show(self, no_lf=False, ansi=u""):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 """show label
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
204
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 @param no_lf(bool): same as for [JP.disp]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 @param ansi(unicode): ansi escape code to print before label
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 """
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 self.disp(A.color(ansi, self.value), no_lf=no_lf)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
209
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
210
2739
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
211 class JidWidget(xmlui_base.JidWidget, TextWidget):
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
212 type = u"jid"
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
213
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
214 class StringWidget(xmlui_base.StringWidget, InputWidget):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 type = u"string"
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
216
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 if self.read_only:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 self.disp(self.value)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 else:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 elems = []
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 self.verboseName(elems)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 if self.value:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
224 elems.append(_(u"(enter: {default})").format(default=self.value))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
225 elems.extend([C.A_HEADER, u"> "])
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 value = raw_input(A.color(*elems))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 if value:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
228 #  TODO: empty value should be possible
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 # an escape key should be used for default instead of enter with empty value
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 self.value = value
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
231
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
232
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
233 class JidInputWidget(xmlui_base.JidInputWidget, StringWidget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
234 type = u"jid_input"
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
235
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
236
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
237 class TextBoxWidget(xmlui_base.TextWidget, StringWidget):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 type = u"textbox"
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
239
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
240
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
241 class ListWidget(xmlui_base.ListWidget, OptionsWidget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
242 type = u"list"
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 # TODO: handle flags, notably multi
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
244
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 def show(self):
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
246 if self.root.values_only:
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
247 for value in self.values:
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
248 self.disp(self.value)
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
249 return
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 if not self.options:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 return
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
252
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 # list display
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 self.verboseName()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
255
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 for idx, (value, label) in enumerate(self.options):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 elems = []
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
258 if not self.root.read_only:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
259 elems.extend([C.A_SUBHEADER, unicode(idx), A.RESET, u": "])
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 elems.append(label)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 self.verboseName(elems, value)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 self.disp(A.color(*elems))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
263
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
264 if self.root.read_only:
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 return
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
266
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 if len(self.options) == 1:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 # we have only one option, no need to ask
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 self.value = self.options[0][0]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 return
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
271
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
272 #  we ask use to choose an option
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 choice = None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
274 limit_max = len(self.options) - 1
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
275 while choice is None or choice < 0 or choice > limit_max:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
276 choice = raw_input(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
277 A.color(C.A_HEADER, _(u"your choice (0-{max}): ").format(max=limit_max))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
278 )
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 try:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 choice = int(choice)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 except ValueError:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
282 choice = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 self.value = self.options[choice][0]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
284 self.disp("")
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
285
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
286
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
287 class BoolWidget(xmlui_base.BoolWidget, InputWidget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
288 type = u"bool"
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
289
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 def show(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
291 disp_true = A.color(A.FG_GREEN, u"TRUE")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
292 disp_false = A.color(A.FG_RED, u"FALSE")
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 if self.read_only:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 self.disp(disp_true if self.value else disp_false)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 else:
2739
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
296 self.disp(A.color(C.A_HEADER, u"0: ",
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
297 disp_false, A.RESET,
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
298 u" *" if not self.value else u""))
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
299 self.disp(A.color(C.A_HEADER, u"1: ",
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
300 disp_true, A.RESET,
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
301 u" *" if self.value else u""))
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 choice = None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
303 while choice not in ("0", "1"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
304 elems = [C.A_HEADER, _(u"your choice (0,1): ")]
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 self.verboseName(elems)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 choice = raw_input(A.color(*elems))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 self.value = bool(int(choice))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
308 self.disp("")
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
309
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 def _xmluiGetValue(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 return C.boolConst(self.value)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
312
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
313
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 ## Containers ##
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
315
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
316
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 class Container(Base):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
318 category = u"container"
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
319
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 def __init__(self, xmlui_parent):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 super(Container, self).__init__(xmlui_parent)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 self.children = []
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
323
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 def __iter__(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 return iter(self.children)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
326
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 def _xmluiAppend(self, widget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
328 self.children.append(widget)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
329
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
330 def _xmluiRemove(self, widget):
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
331 self.children.remove(widget)
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
332
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
333 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
334 for child in self.children:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
335 child.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
336
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
337
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
338 class VerticalContainer(xmlui_base.VerticalContainer, Container):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
339 type = u"vertical"
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
340
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
341
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
342 class PairsContainer(xmlui_base.PairsContainer, Container):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
343 type = u"pairs"
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
344
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
345
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
346 class LabelContainer(xmlui_base.PairsContainer, Container):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
347 type = u"label"
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
348
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 for child in self.children:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 no_lf = False
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 # we check linked widget type
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 # to see if we want the label on the same line or not
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
354 if child.type == u"label":
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 for_name = child.for_name
2739
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
356 if for_name:
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 for_widget = self.root.widgets[for_name]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 wid_type = for_widget.type
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
359 if self.root.values_only or wid_type in (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
360 "text",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
361 "string",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
362 "jid_input",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
363 ):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 no_lf = True
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
365 elif wid_type == "bool" and for_widget.read_only:
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 no_lf = True
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 child.show(no_lf=no_lf, ansi=A.FG_CYAN)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 else:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
369 child.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
370
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
371
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 ## Dialogs ##
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
373
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
374
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 class Dialog(object):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
376 def __init__(self, xmlui_parent):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 self.xmlui_parent = xmlui_parent
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 self.host = self.xmlui_parent.host
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
379
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
380 def disp(self, *args, **kwargs):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
381 self.host.disp(*args, **kwargs)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
382
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
383 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
384 """display current dialog
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
385
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
386 must be overriden by subclasses
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 """
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
388 raise NotImplementedError(self.__class__)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
389
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
390
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
391 class NoteDialog(xmlui_base.NoteDialog, Dialog):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
392 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
393 # TODO: handle title and level
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
394 self.disp(self.message)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
395
2739
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
396 def __init__(self, xmlui_parent, title, message, level):
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
397 Dialog.__init__(self, xmlui_parent)
e8dc00f612fb jp (xmlui): JidWidget + small improvments:
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
398 xmlui_base.NoteDialog.__init__(self, xmlui_parent)
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
399 self.title, self.message, self.level = title, message, level
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
400
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
401
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
402 ## Factory ##
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
403
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
404
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
405 class WidgetFactory(object):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
406 def __getattr__(self, attr):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
407 if attr.startswith("create"):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
408 cls = globals()[attr[6:]]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
409 return cls
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
410
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
411
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
412 class XMLUIPanel(xmlui_base.XMLUIPanel):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
413 widget_factory = WidgetFactory()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
414 _actions = 0 # use to keep track of bridge's launchAction calls
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
415 read_only = False
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
416 values_only = False
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
417 workflow = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
418 _submit_cb = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
419
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
420 def __init__(self, host, parsed_dom, title=None, flags=None, callback=None,
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
421 ignore=None, whitelist=None, profile=None):
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
422 xmlui_base.XMLUIPanel.__init__(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
423 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
424 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
425 parsed_dom,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
426 title=title,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
427 flags=flags,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
428 ignore=ignore,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
429 whitelist=whitelist,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
430 profile=host.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
431 )
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
432 self.submitted = False
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
433
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
434 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
435 def command(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
436 return self.host.command
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
437
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
438 def show(self, workflow=None, read_only=False, values_only=False):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
439 """display the panel
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
440
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
441 @param workflow(list, None): command to execute if not None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
442 put here for convenience, the main workflow is the class attribute
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
443 (because workflow can continue in subclasses)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
444 command are a list of consts or lists:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
445 - SUBMIT is the only constant so far, it submits the XMLUI
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
446 - 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
447 @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
448 @param values_only(bool): if True, only show select values (imply read_only)
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
449 """
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
450 self.read_only = read_only
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
451 self.values_only = values_only
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
452 if self.values_only:
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
453 self.read_only = True
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
454 if workflow:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
455 XMLUIPanel.workflow = workflow
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
456 if XMLUIPanel.workflow:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
457 self.runWorkflow()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
458 else:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
459 self.main_cont.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
460
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
461 def runWorkflow(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
462 """loop into workflow commands and execute commands
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
463
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
464 SUBMIT will interrupt workflow (which will be continue on callback)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
465 @param workflow(list): same as [show]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
466 """
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
467 workflow = XMLUIPanel.workflow
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
468 while True:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
469 try:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
470 cmd = workflow.pop(0)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
471 except IndexError:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
472 break
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
473 if cmd == SUBMIT:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
474 self.onFormSubmitted()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
475 self.submit_id = None # avoid double submit
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
476 return
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
477 elif isinstance(cmd, list):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
478 name, value = cmd
2412
7641bef56dcd jp (xmlui): fixed workflow when value is for a BoolWidget
Goffi <goffi@goffi.org>
parents: 2410
diff changeset
479 widget = self.widgets[name]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
480 if widget.type == "bool":
2412
7641bef56dcd jp (xmlui): fixed workflow when value is for a BoolWidget
Goffi <goffi@goffi.org>
parents: 2410
diff changeset
481 value = C.bool(value)
7641bef56dcd jp (xmlui): fixed workflow when value is for a BoolWidget
Goffi <goffi@goffi.org>
parents: 2410
diff changeset
482 widget.value = value
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
483 self.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
484
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
485 def submitForm(self, callback=None):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
486 XMLUIPanel._submit_cb = callback
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
487 self.onFormSubmitted()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
488
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
489 def onFormSubmitted(self, ignore=None):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
490 #  self.submitted is a Q&D workaround to avoid
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
491 # double submit when a workflow is set
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
492 if self.submitted:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
493 return
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
494 self.submitted = True
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
495 super(XMLUIPanel, self).onFormSubmitted(ignore)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
496
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
497 def _xmluiClose(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
498 pass
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
499
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
500 def _launchActionCb(self, data):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
501 XMLUIPanel._actions -= 1
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
502 assert XMLUIPanel._actions >= 0
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
503 if u"xmlui" in data:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
504 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
505 xmlui = create(self.host, xmlui_raw)
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
506 xmlui.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
507 if xmlui.submit_id:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
508 xmlui.onFormSubmitted()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
509 # TODO: handle data other than XMLUI
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
510 if not XMLUIPanel._actions:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
511 if self._submit_cb is None:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
512 self.host.quit()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
513 else:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
514 self._submit_cb()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
515
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
516 def _xmluiLaunchAction(self, action_id, data):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
517 XMLUIPanel._actions += 1
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
518 self.host.bridge.launchAction(
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
519 action_id,
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
520 data,
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
521 self.profile,
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
522 callback=self._launchActionCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
523 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
524 self.command.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
525 msg=_(u"can't launch XMLUI action: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
526 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
527 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
528 )
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
529
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
530
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
531 class XMLUIDialog(xmlui_base.XMLUIDialog):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
532 type = "dialog"
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
533 dialog_factory = WidgetFactory()
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
534 read_only = False
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
535
2410
40e6e779a253 jp (xmlui): XMLUIDialog.show has now a dummy argument, so workflow arguments can be put there
Goffi <goffi@goffi.org>
parents: 2408
diff changeset
536 def show(self, dummy=None):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
537 self.dlg.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
538
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
539 def _xmluiClose(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
540 pass
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
541
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
542
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
543 create = partial(xmlui_base.create, class_map={
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
544 xmlui_base.CLASS_PANEL: XMLUIPanel,
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
545 xmlui_base.CLASS_DIALOG: XMLUIDialog})