comparison sat/tools/common/template_xmlui.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children bdb8276fd2da
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
21 21
22 XMLUI classes from this modules can then be iterated to create the template 22 XMLUI classes from this modules can then be iterated to create the template
23 """ 23 """
24 24
25 from sat.core.log import getLogger 25 from sat.core.log import getLogger
26
26 log = getLogger(__name__) 27 log = getLogger(__name__)
27 from sat_frontends.tools import xmlui 28 from sat_frontends.tools import xmlui
28 29
29 30
30 ## Widgets ## 31 ## Widgets ##
31 32
33
32 class Widget(object): 34 class Widget(object):
33 category = u'widget' 35 category = u"widget"
34 type = None 36 type = None
35 enabled = True 37 enabled = True
36 read_only = True 38 read_only = True
37 39
38 def __init__(self, xmlui_parent): 40 def __init__(self, xmlui_parent):
42 def name(self): 44 def name(self):
43 return self._xmlui_name 45 return self._xmlui_name
44 46
45 47
46 class ValueWidget(Widget): 48 class ValueWidget(Widget):
47
48 def __init__(self, xmlui_parent, value): 49 def __init__(self, xmlui_parent, value):
49 super(ValueWidget, self).__init__(xmlui_parent) 50 super(ValueWidget, self).__init__(xmlui_parent)
50 self.value = value 51 self.value = value
51 52
52 @property 53 @property
53 def values(self): 54 def values(self):
54 return [self.value] 55 return [self.value]
55 56
56 @property 57 @property
57 def labels(self): 58 def labels(self):
58 # helper property, there is not label for ValueWidget 59 #  helper property, there is not label for ValueWidget
59 # but using labels make rendering more easy (one single method to call) 60 # but using labels make rendering more easy (one single method to call)
60 # values are actually returned 61 #  values are actually returned
61 return [self.value] 62 return [self.value]
62 63
63 64
64 class InputWidget(ValueWidget): 65 class InputWidget(ValueWidget):
65
66 def __init__(self, xmlui_parent, value, read_only=False): 66 def __init__(self, xmlui_parent, value, read_only=False):
67 super(InputWidget, self).__init__(xmlui_parent, value) 67 super(InputWidget, self).__init__(xmlui_parent, value)
68 self.read_only = read_only 68 self.read_only = read_only
69 69
70 70
71 class OptionsWidget(Widget): 71 class OptionsWidget(Widget):
72
73 def __init__(self, xmlui_parent, options, selected, style): 72 def __init__(self, xmlui_parent, options, selected, style):
74 super(OptionsWidget, self).__init__(xmlui_parent) 73 super(OptionsWidget, self).__init__(xmlui_parent)
75 self.options = options 74 self.options = options
76 self.selected = selected 75 self.selected = selected
77 self.style = style 76 self.style = style
89 88
90 @property 89 @property
91 def items(self): 90 def items(self):
92 """return suitable items, according to style""" 91 """return suitable items, according to style"""
93 no_select = self.no_select 92 no_select = self.no_select
94 for value,label in self.options: 93 for value, label in self.options:
95 if no_select or value in self.selected: 94 if no_select or value in self.selected:
96 yield value,label 95 yield value, label
97 96
98 @property 97 @property
99 def inline(self): 98 def inline(self):
100 return u'inline' in self.style 99 return u"inline" in self.style
101 100
102 @property 101 @property
103 def no_select(self): 102 def no_select(self):
104 return u'noselect' in self.style 103 return u"noselect" in self.style
105 104
106 105
107 class EmptyWidget(xmlui.EmptyWidget, Widget): 106 class EmptyWidget(xmlui.EmptyWidget, Widget):
108
109 def __init__(self, _xmlui_parent): 107 def __init__(self, _xmlui_parent):
110 Widget.__init__(self) 108 Widget.__init__(self)
111 109
112 110
113 class TextWidget(xmlui.TextWidget, ValueWidget): 111 class TextWidget(xmlui.TextWidget, ValueWidget):
141 type = u"list" 139 type = u"list"
142 140
143 141
144 ## Containers ## 142 ## Containers ##
145 143
144
146 class Container(object): 145 class Container(object):
147 category = u'container' 146 category = u"container"
148 type = None 147 type = None
149 148
150 def __init__(self, xmlui_parent): 149 def __init__(self, xmlui_parent):
151 self.xmlui_parent = xmlui_parent 150 self.xmlui_parent = xmlui_parent
152 self.children = [] 151 self.children = []
160 def _xmluiRemove(self, widget): 159 def _xmluiRemove(self, widget):
161 self.children.remove(widget) 160 self.children.remove(widget)
162 161
163 162
164 class VerticalContainer(xmlui.VerticalContainer, Container): 163 class VerticalContainer(xmlui.VerticalContainer, Container):
165 type = u'vertical' 164 type = u"vertical"
166 165
167 166
168 class PairsContainer(xmlui.PairsContainer, Container): 167 class PairsContainer(xmlui.PairsContainer, Container):
169 type = u'pairs' 168 type = u"pairs"
170 169
171 170
172 class LabelContainer(xmlui.PairsContainer, Container): 171 class LabelContainer(xmlui.PairsContainer, Container):
173 type = u'label' 172 type = u"label"
174 173
175 174
176 ## Factory ## 175 ## Factory ##
177 176
177
178 class WidgetFactory(object): 178 class WidgetFactory(object):
179
180 def __getattr__(self, attr): 179 def __getattr__(self, attr):
181 if attr.startswith("create"): 180 if attr.startswith("create"):
182 cls = globals()[attr[6:]] 181 cls = globals()[attr[6:]]
183 return cls 182 return cls
184 183
184
185 ## Core ## 185 ## Core ##
186 186
187 187
188 class XMLUIPanel(xmlui.XMLUIPanel): 188 class XMLUIPanel(xmlui.XMLUIPanel):
189 widget_factory = WidgetFactory() 189 widget_factory = WidgetFactory()