comparison 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
comparison
equal deleted inserted replaced
2738:eb58f26ed236 2739:e8dc00f612fb
172 def no_select(self): 172 def no_select(self):
173 return u"noselect" in self.style 173 return u"noselect" in self.style
174 174
175 175
176 class EmptyWidget(xmlui_base.EmptyWidget, Widget): 176 class EmptyWidget(xmlui_base.EmptyWidget, Widget):
177 def __init__(self, _xmlui_parent): 177
178 Widget.__init__(self) 178 def __init__(self, xmlui_parent):
179 Widget.__init__(self, xmlui_parent)
180
181 def show(self):
182 self.host.disp(u'')
179 183
180 184
181 class TextWidget(xmlui_base.TextWidget, ValueWidget): 185 class TextWidget(xmlui_base.TextWidget, ValueWidget):
182 type = u"text" 186 type = u"text"
183 187
201 @param no_lf(bool): same as for [JP.disp] 205 @param no_lf(bool): same as for [JP.disp]
202 @param ansi(unicode): ansi escape code to print before label 206 @param ansi(unicode): ansi escape code to print before label
203 """ 207 """
204 self.disp(A.color(ansi, self.value), no_lf=no_lf) 208 self.disp(A.color(ansi, self.value), no_lf=no_lf)
205 209
210
211 class JidWidget(xmlui_base.JidWidget, TextWidget):
212 type = u"jid"
206 213
207 class StringWidget(xmlui_base.StringWidget, InputWidget): 214 class StringWidget(xmlui_base.StringWidget, InputWidget):
208 type = u"string" 215 type = u"string"
209 216
210 def show(self): 217 def show(self):
284 disp_true = A.color(A.FG_GREEN, u"TRUE") 291 disp_true = A.color(A.FG_GREEN, u"TRUE")
285 disp_false = A.color(A.FG_RED, u"FALSE") 292 disp_false = A.color(A.FG_RED, u"FALSE")
286 if self.read_only: 293 if self.read_only:
287 self.disp(disp_true if self.value else disp_false) 294 self.disp(disp_true if self.value else disp_false)
288 else: 295 else:
289 self.disp(A.color(C.A_HEADER, u"0: ", disp_false)) 296 self.disp(A.color(C.A_HEADER, u"0: ",
290 self.disp(A.color(C.A_HEADER, u"1: ", disp_true)) 297 disp_false, A.RESET,
298 u" *" if not self.value else u""))
299 self.disp(A.color(C.A_HEADER, u"1: ",
300 disp_true, A.RESET,
301 u" *" if self.value else u""))
291 choice = None 302 choice = None
292 while choice not in ("0", "1"): 303 while choice not in ("0", "1"):
293 elems = [C.A_HEADER, _(u"your choice (0,1): ")] 304 elems = [C.A_HEADER, _(u"your choice (0,1): ")]
294 self.verboseName(elems) 305 self.verboseName(elems)
295 choice = raw_input(A.color(*elems)) 306 choice = raw_input(A.color(*elems))
340 no_lf = False 351 no_lf = False
341 # we check linked widget type 352 # we check linked widget type
342 # to see if we want the label on the same line or not 353 # to see if we want the label on the same line or not
343 if child.type == u"label": 354 if child.type == u"label":
344 for_name = child.for_name 355 for_name = child.for_name
345 if for_name is not None: 356 if for_name:
346 for_widget = self.root.widgets[for_name] 357 for_widget = self.root.widgets[for_name]
347 wid_type = for_widget.type 358 wid_type = for_widget.type
348 if self.root.values_only or wid_type in ( 359 if self.root.values_only or wid_type in (
349 "text", 360 "text",
350 "string", 361 "string",
380 class NoteDialog(xmlui_base.NoteDialog, Dialog): 391 class NoteDialog(xmlui_base.NoteDialog, Dialog):
381 def show(self): 392 def show(self):
382 # TODO: handle title and level 393 # TODO: handle title and level
383 self.disp(self.message) 394 self.disp(self.message)
384 395
385 def __init__(self, _xmlui_parent, title, message, level): 396 def __init__(self, xmlui_parent, title, message, level):
386 Dialog.__init__(self, _xmlui_parent) 397 Dialog.__init__(self, xmlui_parent)
387 xmlui_base.NoteDialog.__init__(self, _xmlui_parent) 398 xmlui_base.NoteDialog.__init__(self, xmlui_parent)
388 self.title, self.message, self.level = title, message, level 399 self.title, self.message, self.level = title, message, level
389 400
390 401
391 ## Factory ## 402 ## Factory ##
392 403