Mercurial > libervia-backend
comparison libervia/tui/xmlui.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | b620a8e882e1 |
children |
comparison
equal
deleted
inserted
replaced
4269:64a85ce8be70 | 4270:0d7bb4df2343 |
---|---|
30 from libervia.tui.widget import LiberviaTUIWidget | 30 from libervia.tui.widget import LiberviaTUIWidget |
31 from libervia.frontends.tools import xmlui | 31 from libervia.frontends.tools import xmlui |
32 | 32 |
33 | 33 |
34 class LiberviaTUIEvents(object): | 34 class LiberviaTUIEvents(object): |
35 """ Used to manage change event of LiberviaTUI widgets """ | 35 """Used to manage change event of LiberviaTUI widgets""" |
36 | 36 |
37 def _event_callback(self, ctrl, *args, **kwargs): | 37 def _event_callback(self, ctrl, *args, **kwargs): |
38 """" Call xmlui callback and ignore any extra argument """ | 38 """ " Call xmlui callback and ignore any extra argument""" |
39 args[-1](ctrl) | 39 args[-1](ctrl) |
40 | 40 |
41 def _xmlui_on_change(self, callback): | 41 def _xmlui_on_change(self, callback): |
42 """ Call callback with widget as only argument """ | 42 """Call callback with widget as only argument""" |
43 urwid.connect_signal(self, "change", self._event_callback, callback) | 43 urwid.connect_signal(self, "change", self._event_callback, callback) |
44 | 44 |
45 | 45 |
46 class LiberviaTUIEmptyWidget(xmlui.EmptyWidget, urwid.Text): | 46 class LiberviaTUIEmptyWidget(xmlui.EmptyWidget, urwid.Text): |
47 def __init__(self, _xmlui_parent): | 47 def __init__(self, _xmlui_parent): |
264 | 264 |
265 def _xmlui_get_selected_index(self): | 265 def _xmlui_get_selected_index(self): |
266 return self.get_selected_index() | 266 return self.get_selected_index() |
267 | 267 |
268 def _xmlui_on_select(self, callback): | 268 def _xmlui_on_select(self, callback): |
269 """ Call callback with widget as only argument """ | 269 """Call callback with widget as only argument""" |
270 urwid.connect_signal(self, "click", self._event_callback, callback) | 270 urwid.connect_signal(self, "click", self._event_callback, callback) |
271 | 271 |
272 | 272 |
273 class LiberviaTUIPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer): | 273 class LiberviaTUIPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer): |
274 def __init__(self, _xmlui_parent): | 274 def __init__(self, _xmlui_parent): |
430 ignore=ignore, | 430 ignore=ignore, |
431 profile=profile, | 431 profile=profile, |
432 ) | 432 ) |
433 LiberviaTUIWidget.__init__(self, self.main_cont, self.xmlui_title) | 433 LiberviaTUIWidget.__init__(self, self.main_cont, self.xmlui_title) |
434 | 434 |
435 | 435 def _parse_childs( |
436 def _parse_childs(self, _xmlui_parent, current_node, wanted=("container",), data=None): | 436 self, _xmlui_parent, current_node, wanted=("container",), data=None |
437 ): | |
437 # Small hack to always have a VerticalContainer as main container in LiberviaTUI. | 438 # Small hack to always have a VerticalContainer as main container in LiberviaTUI. |
438 # this used to be the default behaviour for all frontends, but now | 439 # this used to be the default behaviour for all frontends, but now |
439 # TabsContainer can also be the main container. | 440 # TabsContainer can also be the main container. |
440 if _xmlui_parent is self: | 441 if _xmlui_parent is self: |
441 node = current_node.childNodes[0] | 442 node = current_node.childNodes[0] |
442 if node.nodeName == "container" and node.getAttribute("type") == "tabs": | 443 if node.nodeName == "container" and node.getAttribute("type") == "tabs": |
443 _xmlui_parent = self.widget_factory.createVerticalContainer(self) | 444 _xmlui_parent = self.widget_factory.createVerticalContainer(self) |
444 self.main_cont = _xmlui_parent | 445 self.main_cont = _xmlui_parent |
445 return super(XMLUIPanel, self)._parse_childs(_xmlui_parent, current_node, wanted, | 446 return super(XMLUIPanel, self)._parse_childs( |
446 data) | 447 _xmlui_parent, current_node, wanted, data |
447 | 448 ) |
448 | 449 |
449 def construct_ui(self, parsed_dom): | 450 def construct_ui(self, parsed_dom): |
450 def post_treat(): | 451 def post_treat(): |
451 assert self.main_cont.body | 452 assert self.main_cont.body |
452 | 453 |