Mercurial > libervia-backend
comparison sat/tools/common/template_xmlui.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 | src/tools/common/template_xmlui.py@0046283a285d |
children | 56f94936df1e |
comparison
equal
deleted
inserted
replaced
2561:bd30dc3ffe5a | 2562:26edcf3a30eb |
---|---|
1 #!/usr/bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SAT: a jabber client | |
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 """ template XMLUI parsing | |
21 | |
22 XMLUI classes from this modules can then be iterated to create the template | |
23 """ | |
24 | |
25 from sat.core.log import getLogger | |
26 log = getLogger(__name__) | |
27 from sat_frontends.tools import xmlui | |
28 | |
29 | |
30 ## Widgets ## | |
31 | |
32 class Widget(object): | |
33 category = u'widget' | |
34 type = None | |
35 enabled = True | |
36 read_only = True | |
37 | |
38 def __init__(self, xmlui_parent): | |
39 self.xmlui_parent = xmlui_parent | |
40 | |
41 @property | |
42 def name(self): | |
43 return self._xmlui_name | |
44 | |
45 | |
46 class ValueWidget(Widget): | |
47 | |
48 def __init__(self, xmlui_parent, value): | |
49 super(ValueWidget, self).__init__(xmlui_parent) | |
50 self.value = value | |
51 | |
52 @property | |
53 def values(self): | |
54 return [self.value] | |
55 | |
56 @property | |
57 def labels(self): | |
58 # helper property, there is not label for ValueWidget | |
59 # but using labels make rendering more easy (one single method to call) | |
60 # values are actually returned | |
61 return [self.value] | |
62 | |
63 | |
64 class InputWidget(ValueWidget): | |
65 | |
66 def __init__(self, xmlui_parent, value, read_only=False): | |
67 super(InputWidget, self).__init__(xmlui_parent, value) | |
68 self.read_only = read_only | |
69 | |
70 | |
71 class OptionsWidget(Widget): | |
72 | |
73 def __init__(self, xmlui_parent, options, selected, style): | |
74 super(OptionsWidget, self).__init__(xmlui_parent) | |
75 self.options = options | |
76 self.selected = selected | |
77 self.style = style | |
78 | |
79 @property | |
80 def values(self): | |
81 for value, label in self.items: | |
82 yield value | |
83 | |
84 @property | |
85 def labels(self): | |
86 """return only labels from self.items""" | |
87 for value, label in self.items: | |
88 yield label | |
89 | |
90 @property | |
91 def items(self): | |
92 """return suitable items, according to style""" | |
93 no_select = self.no_select | |
94 for value,label in self.options: | |
95 if no_select or value in self.selected: | |
96 yield value,label | |
97 | |
98 @property | |
99 def inline(self): | |
100 return u'inline' in self.style | |
101 | |
102 @property | |
103 def no_select(self): | |
104 return u'noselect' in self.style | |
105 | |
106 | |
107 class EmptyWidget(xmlui.EmptyWidget, Widget): | |
108 | |
109 def __init__(self, _xmlui_parent): | |
110 Widget.__init__(self) | |
111 | |
112 | |
113 class TextWidget(xmlui.TextWidget, ValueWidget): | |
114 type = u"text" | |
115 | |
116 | |
117 class LabelWidget(xmlui.LabelWidget, ValueWidget): | |
118 type = u"label" | |
119 | |
120 @property | |
121 def for_name(self): | |
122 try: | |
123 return self._xmlui_for_name | |
124 except AttributeError: | |
125 return None | |
126 | |
127 | |
128 class StringWidget(xmlui.StringWidget, InputWidget): | |
129 type = u"string" | |
130 | |
131 | |
132 class JidInputWidget(xmlui.JidInputWidget, StringWidget): | |
133 type = u"jid" | |
134 | |
135 | |
136 class TextBoxWidget(xmlui.TextWidget, InputWidget): | |
137 type = u"textbox" | |
138 | |
139 | |
140 class ListWidget(xmlui.ListWidget, OptionsWidget): | |
141 type = u"list" | |
142 | |
143 | |
144 ## Containers ## | |
145 | |
146 class Container(object): | |
147 category = u'container' | |
148 type = None | |
149 | |
150 def __init__(self, xmlui_parent): | |
151 self.xmlui_parent = xmlui_parent | |
152 self.children = [] | |
153 | |
154 def __iter__(self): | |
155 return iter(self.children) | |
156 | |
157 def _xmluiAppend(self, widget): | |
158 self.children.append(widget) | |
159 | |
160 def _xmluiRemove(self, widget): | |
161 self.children.remove(widget) | |
162 | |
163 | |
164 class VerticalContainer(xmlui.VerticalContainer, Container): | |
165 type = u'vertical' | |
166 | |
167 | |
168 class PairsContainer(xmlui.PairsContainer, Container): | |
169 type = u'pairs' | |
170 | |
171 | |
172 class LabelContainer(xmlui.PairsContainer, Container): | |
173 type = u'label' | |
174 | |
175 | |
176 ## Factory ## | |
177 | |
178 class WidgetFactory(object): | |
179 | |
180 def __getattr__(self, attr): | |
181 if attr.startswith("create"): | |
182 cls = globals()[attr[6:]] | |
183 return cls | |
184 | |
185 ## Core ## | |
186 | |
187 | |
188 class XMLUIPanel(xmlui.XMLUIPanel): | |
189 widget_factory = WidgetFactory() | |
190 | |
191 def show(self, *args, **kwargs): | |
192 raise NotImplementedError | |
193 | |
194 | |
195 class XMLUIDialog(xmlui.XMLUIDialog): | |
196 dialog_factory = WidgetFactory() | |
197 | |
198 def __init__(*args, **kwargs): | |
199 raise NotImplementedError | |
200 | |
201 | |
202 xmlui.registerClass(xmlui.CLASS_PANEL, XMLUIPanel) | |
203 xmlui.registerClass(xmlui.CLASS_DIALOG, XMLUIDialog) | |
204 create = xmlui.create |