annotate sat_frontends/jp/xmlui_manager.py @ 2562:26edcf3a30eb

core, setup: huge cleaning: - moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention - move twisted directory to root - removed all hacks from setup.py, and added missing dependencies, it is now clean - use https URL for website in setup.py - removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed - renamed sat.sh to sat and fixed its installation - added python_requires to specify Python version needed - replaced glib2reactor which use deprecated code by gtk3reactor sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author Goffi <goffi@goffi.org>
date Mon, 02 Apr 2018 19:44:50 +0200
parents frontends/src/jp/xmlui_manager.py@65695b9343d3
children 56f94936df1e
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
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 log = getLogger(__name__)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat_frontends.tools import xmlui as xmlui_manager
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat_frontends.jp.constants import Const as C
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.tools.common.ansi import ANSI as A
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core.i18n import _
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from functools import partial
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 # workflow constants
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 SUBMIT = 'SUBMIT' # submit form
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
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
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 class Base(object):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 """Base for Widget and Container"""
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 type = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 _root = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 def __init__(self, xmlui_parent):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 self.xmlui_parent = xmlui_parent
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 self.host = self.xmlui_parent.host
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 def root(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 """retrieve main XMLUI parent class"""
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 if self._root is not None:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 return self._root
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 root = self
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 while not isinstance(root, xmlui_manager.XMLUIBase):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 root = root.xmlui_parent
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self._root = root
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 return root
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 def disp(self, *args, **kwargs):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.host.disp(*args, **kwargs)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 class Widget(Base):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 category = u'widget'
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 enabled = True
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 def name(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 return self._xmlui_name
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 """display current widget
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 must be overriden by subclasses
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 raise NotImplementedError(self.__class__)
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 def verboseName(self, elems=None, value=None):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 """add name in color to the elements
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 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
79 elems is only modified if verbosity is > 0
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 @param elems(list[unicode], None): elements to display
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 None to display name directly
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 @param value(unicode, None): value to show
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 use self.name if None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 """
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 if value is None:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 value = self.name
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 if self.host.verbosity:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 to_disp = [A.FG_MAGENTA,
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 u' ' if elems else u'',
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 u'({})'.format(value), A.RESET]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 if elems is None:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self.host.disp(A.color(*to_disp))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 else:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 elems.extend(to_disp)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 class ValueWidget(Widget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 def __init__(self, xmlui_parent, value):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 super(ValueWidget, self).__init__(xmlui_parent)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 self.value = value
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
101
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 def values(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 return [self.value]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
105
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 class InputWidget(ValueWidget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 def __init__(self, xmlui_parent, value, read_only=False):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 super(InputWidget, self).__init__(xmlui_parent, value)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 self.read_only = read_only
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 def _xmluiGetValue(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 return self.value
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115
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 class OptionsWidget(Widget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
118
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 def __init__(self, xmlui_parent, options, selected, style):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 super(OptionsWidget, self).__init__(xmlui_parent)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 self.options = options
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 self.selected = selected
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 self.style = style
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 def values(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 return self.selected
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 @values.setter
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 def values(self, values):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 self.selected = values
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 def value(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 return self.selected[0]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 @value.setter
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 def value(self, value):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 self.selected = [value]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
140
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 def _xmluiSelectValue(self, value):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 self.value = 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 _xmluiSelectValues(self, values):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 self.values = values
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 _xmluiGetSelectedValues(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 return self.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 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 def labels(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 """return only labels from self.items"""
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 for value, label in self.items:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 yield label
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
155
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 def items(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 """return suitable items, according to style"""
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 no_select = self.no_select
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 for value,label in self.options:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 if no_select or value in self.selected:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 yield value,label
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
163
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 def inline(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 return u'inline' in self.style
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
167
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 def no_select(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 return u'noselect' in self.style
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
171
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
172
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 class EmptyWidget(xmlui_manager.EmptyWidget, Widget):
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 def __init__(self, _xmlui_parent):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 Widget.__init__(self)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
177
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
178
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 class TextWidget(xmlui_manager.TextWidget, ValueWidget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 type = u"text"
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
181
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 self.host.disp(self.value)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
184
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
185
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 class LabelWidget(xmlui_manager.LabelWidget, ValueWidget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 type = u"label"
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
188
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 def for_name(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 try:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 return self._xmlui_for_name
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 except AttributeError:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 return None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
195
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 def show(self, no_lf=False, ansi=u''):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 """show label
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
198
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 @param no_lf(bool): same as for [JP.disp]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 @param ansi(unicode): ansi escape code to print before label
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 """
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 self.disp(A.color(ansi, self.value), no_lf=no_lf)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
203
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 class StringWidget(xmlui_manager.StringWidget, InputWidget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 type = u"string"
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 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 if self.read_only:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 self.disp(self.value)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 else:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 elems = []
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 self.verboseName(elems)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 if self.value:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 elems.append(_(u'(enter: {default})').format(default=self.value))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 elems.extend([C.A_HEADER, u'> '])
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 value = raw_input(A.color(*elems))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 if value:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 # TODO: empty value should be possible
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 # 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
221 self.value = value
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
222
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
223
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
224
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 class JidInputWidget(xmlui_manager.JidInputWidget, StringWidget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 type = u'jid_input'
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
227
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
228
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 class TextBoxWidget(xmlui_manager.TextWidget, StringWidget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 type = u"textbox"
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
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 class ListWidget(xmlui_manager.ListWidget, OptionsWidget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 type = u'list'
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 # TODO: handle flags, notably multi
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
236
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 def show(self):
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
238 if self.root.values_only:
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
239 for value in self.values:
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
240 self.disp(self.value)
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
241 return
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 if not self.options:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 return
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 # list display
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 self.verboseName()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
247
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 for idx, (value, label) in enumerate(self.options):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 elems = []
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
250 if not self.root.read_only:
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 elems.extend([C.A_SUBHEADER, unicode(idx), A.RESET, u': '])
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 elems.append(label)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 self.verboseName(elems, value)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 self.disp(A.color(*elems))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
255
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
256 if self.root.read_only:
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 return
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
258
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 if len(self.options) == 1:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 # we have only one option, no need to ask
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 self.value = self.options[0][0]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 return
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
263
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 # we ask use to choose an option
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 choice = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 limit_max = len(self.options)-1
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 while choice is None or choice<0 or choice>limit_max:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 choice = raw_input(A.color(C.A_HEADER, _(u'your choice (0-{max}): ').format(max=limit_max)))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 try:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 choice = int(choice)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 except ValueError:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 choice = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 self.value = self.options[choice][0]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 self.disp('')
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
275
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
276
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 class BoolWidget(xmlui_manager.BoolWidget, InputWidget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 type = u'bool'
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
279
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 disp_true = A.color(A.FG_GREEN, u'TRUE')
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
282 disp_false = A.color(A.FG_RED,u'FALSE')
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 if self.read_only:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
284 self.disp(disp_true if self.value else disp_false)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
285 else:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 self.disp(A.color(C.A_HEADER, u'0: ', disp_false))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 self.disp(A.color(C.A_HEADER, u'1: ', disp_true))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 choice = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 while choice not in ('0', '1'):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 elems = [C.A_HEADER, _(u'your choice (0,1): ')]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 self.verboseName(elems)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 choice = raw_input(A.color(*elems))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 self.value = bool(int(choice))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 self.disp('')
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
295
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 def _xmluiGetValue(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 return C.boolConst(self.value)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
298
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
299 ## Containers ##
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
300
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 class Container(Base):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 category = u'container'
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
303
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 def __init__(self, xmlui_parent):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 super(Container, self).__init__(xmlui_parent)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 self.children = []
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
307
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 def __iter__(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 return iter(self.children)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
310
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 def _xmluiAppend(self, widget):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 self.children.append(widget)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
313
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
314 def _xmluiRemove(self, widget):
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
315 self.children.remove(widget)
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
316
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 for child in self.children:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 child.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
320
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
321
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 class VerticalContainer(xmlui_manager.VerticalContainer, Container):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
323 type = u'vertical'
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
324
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
325
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 class PairsContainer(xmlui_manager.PairsContainer, Container):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 type = u'pairs'
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
328
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
329
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 class LabelContainer(xmlui_manager.PairsContainer, Container):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
331 type = u'label'
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
332
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 no_lf = False
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 # we check linked widget type
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 # to see if we want the label on the same line or not
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 if child.type == u'label':
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 for_name = child.for_name
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 if for_name is not None:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 for_widget = self.root.widgets[for_name]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 wid_type = for_widget.type
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
343 if self.root.values_only or wid_type in ('text', 'string', 'jid_input'):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 no_lf = True
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 elif wid_type == 'bool' and for_widget.read_only:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 no_lf = True
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 child.show(no_lf=no_lf, ansi=A.FG_CYAN)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 else:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 child.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
350
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 ## Dialogs ##
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
352
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
353
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 class Dialog(object):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
355
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
356 def __init__(self, xmlui_parent):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 self.xmlui_parent = xmlui_parent
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 self.host = self.xmlui_parent.host
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
359
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 def disp(self, *args, **kwargs):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
361 self.host.disp(*args, **kwargs)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
362
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 """display current dialog
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
365
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 must be overriden by subclasses
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 """
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 raise NotImplementedError(self.__class__)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
369
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
370
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 class NoteDialog(xmlui_manager.NoteDialog, Dialog):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
372
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
373 def show(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
374 # TODO: handle title and level
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 self.disp(self.message)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
376
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 def __init__(self, _xmlui_parent, title, message, level):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 Dialog.__init__(self, _xmlui_parent)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
379 xmlui_manager.NoteDialog.__init__(self, _xmlui_parent)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
380 self.title, self.message, self.level = title, message, level
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
381
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
382 ## Factory ##
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
383
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
384
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
385 class WidgetFactory(object):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
386
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 def __getattr__(self, attr):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
388 if attr.startswith("create"):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
389 cls = globals()[attr[6:]]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
390 return cls
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
391
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
392
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
393 class XMLUIPanel(xmlui_manager.XMLUIPanel):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
394 widget_factory = WidgetFactory()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
395 _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
396 read_only = False
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
397 values_only = False
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
398 workflow = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
399 _submit_cb = None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
400
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
401 def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, ignore=None, whitelist=None, profile=None):
2419
c38c54c47e16 frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
402 xmlui_manager.XMLUIPanel.__init__(self,
c38c54c47e16 frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
403 host,
c38c54c47e16 frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
404 parsed_dom,
c38c54c47e16 frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
405 title = title,
c38c54c47e16 frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
406 flags = flags,
c38c54c47e16 frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
407 ignore = ignore,
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
408 whitelist = whitelist,
2419
c38c54c47e16 frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
409 profile=host.profile)
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
410 self.submitted = False
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
411
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
412 @property
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
413 def command(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
414 return self.host.command
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
415
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
416 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
417 """display the panel
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
418
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
419 @param workflow(list, None): command to execute if not None
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
420 put here for convenience, the main workflow is the class attribute
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
421 (because workflow can continue in subclasses)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
422 command are a list of consts or lists:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
423 - SUBMIT is the only constant so far, it submits the XMLUI
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
424 - 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
425 @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
426 @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
427 """
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
428 self.read_only = read_only
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
429 self.values_only = values_only
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
430 if self.values_only:
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
431 self.read_only = True
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
432 if workflow:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
433 XMLUIPanel.workflow = workflow
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
434 if XMLUIPanel.workflow:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
435 self.runWorkflow()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
436 else:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
437 self.main_cont.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
438
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
439 def runWorkflow(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
440 """loop into workflow commands and execute commands
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
441
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
442 SUBMIT will interrupt workflow (which will be continue on callback)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
443 @param workflow(list): same as [show]
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
444 """
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
445 workflow = XMLUIPanel.workflow
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
446 while True:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
447 try:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
448 cmd = workflow.pop(0)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
449 except IndexError:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
450 break
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
451 if cmd == SUBMIT:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
452 self.onFormSubmitted()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
453 self.submit_id = None # avoid double submit
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
454 return
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
455 elif isinstance(cmd, list):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
456 name, value = cmd
2412
7641bef56dcd jp (xmlui): fixed workflow when value is for a BoolWidget
Goffi <goffi@goffi.org>
parents: 2410
diff changeset
457 widget = self.widgets[name]
7641bef56dcd jp (xmlui): fixed workflow when value is for a BoolWidget
Goffi <goffi@goffi.org>
parents: 2410
diff changeset
458 if widget.type == 'bool':
7641bef56dcd jp (xmlui): fixed workflow when value is for a BoolWidget
Goffi <goffi@goffi.org>
parents: 2410
diff changeset
459 value = C.bool(value)
7641bef56dcd jp (xmlui): fixed workflow when value is for a BoolWidget
Goffi <goffi@goffi.org>
parents: 2410
diff changeset
460 widget.value = value
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
461 self.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
462
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
463 def submitForm(self, callback=None):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
464 XMLUIPanel._submit_cb = callback
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
465 self.onFormSubmitted()
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 def onFormSubmitted(self, ignore=None):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
468 # self.submitted is a Q&D workaround to avoid
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
469 # double submit when a workflow is set
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
470 if self.submitted:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
471 return
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
472 self.submitted = True
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
473 super(XMLUIPanel, self).onFormSubmitted(ignore)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
474
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
475 def _xmluiClose(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
476 pass
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
477
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
478 def _launchActionCb(self, data):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
479 XMLUIPanel._actions -= 1
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
480 assert XMLUIPanel._actions >= 0
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
481 if u'xmlui' in data:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
482 xmlui_raw = data['xmlui']
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
483 xmlui = xmlui_manager.create(self.host, xmlui_raw)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
484 xmlui.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
485 if xmlui.submit_id:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
486 xmlui.onFormSubmitted()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
487 # TODO: handle data other than XMLUI
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
488 if not XMLUIPanel._actions:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
489 if self._submit_cb is None:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
490 self.host.quit()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
491 else:
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
492 self._submit_cb()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
493
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
494 def _xmluiLaunchAction(self, action_id, data):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
495 XMLUIPanel._actions += 1
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
496 self.host.bridge.launchAction(
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
497 action_id,
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
498 data,
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
499 self.profile,
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
500 callback=self._launchActionCb,
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
501 errback=partial(self.command.errback,
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
502 msg=_(u"can't launch XMLUI action: {}"),
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
503 exit_code=C.EXIT_BRIDGE_ERRBACK))
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
504
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
505
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
506 class XMLUIDialog(xmlui_manager.XMLUIDialog):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
507 type = 'dialog'
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
508 dialog_factory = WidgetFactory()
2541
65695b9343d3 jp (xmlui): added whitelist, read_only and values_only options:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
509 read_only = False
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
510
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
511 def show(self, dummy=None):
2408
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
512 self.dlg.show()
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
513
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
514 def _xmluiClose(self):
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
515 pass
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
516
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
517
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
518 xmlui_manager.registerClass(xmlui_manager.CLASS_PANEL, XMLUIPanel)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
519 xmlui_manager.registerClass(xmlui_manager.CLASS_DIALOG, XMLUIDialog)
a870daeab15e jp: XMLUI implementation first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
520 create = xmlui_manager.create