annotate libervia/tui/xmlui.py @ 4232:0fbe5c605eb6

tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests: fix 441
author Goffi <goffi@goffi.org>
date Sat, 06 Apr 2024 12:59:50 +0200
parents b620a8e882e1
children 0d7bb4df2343
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
3
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
4 # Libervia TUI
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
10 # (at your option) any later version.
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
15 # GNU Affero General Public License for more details.
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 607
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
19
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.core.i18n import _
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import urwid
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
22 import copy
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
23 from libervia.backend.core import exceptions
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
24 from urwid_satext import sat_widgets
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
25 from urwid_satext import files_management
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
26 from libervia.backend.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
27
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 976
diff changeset
28 log = getLogger(__name__)
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
29 from libervia.tui.constants import Const as C
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
30 from libervia.tui.widget import LiberviaTUIWidget
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
31 from libervia.frontends.tools import xmlui
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
32
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
33
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
34 class LiberviaTUIEvents(object):
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
35 """ Used to manage change event of LiberviaTUI widgets """
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
36
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
37 def _event_callback(self, ctrl, *args, **kwargs):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
38 """" Call xmlui callback and ignore any extra argument """
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
39 args[-1](ctrl)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
40
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
41 def _xmlui_on_change(self, callback):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
42 """ Call callback with widget as only argument """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
43 urwid.connect_signal(self, "change", self._event_callback, callback)
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
44
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
45
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
46 class LiberviaTUIEmptyWidget(xmlui.EmptyWidget, urwid.Text):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
47 def __init__(self, _xmlui_parent):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
48 urwid.Text.__init__(self, "")
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
49
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
50
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
51 class LiberviaTUITextWidget(xmlui.TextWidget, urwid.Text):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
52 def __init__(self, _xmlui_parent, value, read_only=False):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
53 urwid.Text.__init__(self, value)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
54
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
55
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
56 class LiberviaTUILabelWidget(xmlui.LabelWidget, LiberviaTUITextWidget):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
57 def __init__(self, _xmlui_parent, value):
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
58 super(LiberviaTUILabelWidget, self).__init__(_xmlui_parent, value + ": ")
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
59
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
60
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
61 class LiberviaTUIJidWidget(xmlui.JidWidget, LiberviaTUITextWidget):
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
62 pass
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
63
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
64
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
65 class LiberviaTUIDividerWidget(xmlui.DividerWidget, urwid.Divider):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
66 def __init__(self, _xmlui_parent, style="line"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
67 if style == "line":
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
68 div_char = "─"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
69 elif style == "dot":
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
70 div_char = "·"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
71 elif style == "dash":
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
72 div_char = "-"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
73 elif style == "plain":
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
74 div_char = "█"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
75 elif style == "blank":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
76 div_char = " "
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
77 else:
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 976
diff changeset
78 log.warning(_("Unknown div_char"))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3004
diff changeset
79 div_char = "─"
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
80
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
81 urwid.Divider.__init__(self, div_char)
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
82
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
83
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
84 class LiberviaTUIStringWidget(
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
85 xmlui.StringWidget, sat_widgets.AdvancedEdit, LiberviaTUIEvents
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
86 ):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
87 def __init__(self, _xmlui_parent, value, read_only=False):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
88 sat_widgets.AdvancedEdit.__init__(self, edit_text=value)
1085
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
89 self.read_only = read_only
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
90
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
91 def selectable(self):
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
92 if self.read_only:
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
93 return False
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
94 return super(LiberviaTUIStringWidget, self).selectable()
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
95
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
96 def _xmlui_set_value(self, value):
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
97 self.set_edit_text(value)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
98
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
99 def _xmlui_get_value(self):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
100 return self.get_edit_text()
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
101
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
102
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
103 class LiberviaTUIJidInputWidget(xmlui.JidInputWidget, LiberviaTUIStringWidget):
1473
675e0e9f1653 core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
104 pass
675e0e9f1653 core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
105
675e0e9f1653 core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
106
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
107 class LiberviaTUIPasswordWidget(
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
108 xmlui.PasswordWidget, sat_widgets.Password, LiberviaTUIEvents
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
109 ):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
110 def __init__(self, _xmlui_parent, value, read_only=False):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
111 sat_widgets.Password.__init__(self, edit_text=value)
1085
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
112 self.read_only = read_only
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
113
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
114 def selectable(self):
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
115 if self.read_only:
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
116 return False
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
117 return super(LiberviaTUIPasswordWidget, self).selectable()
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
118
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
119 def _xmlui_set_value(self, value):
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
120 self.set_edit_text(value)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
121
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
122 def _xmlui_get_value(self):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
123 return self.get_edit_text()
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
124
762
aed7d99276b8 core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents: 760
diff changeset
125
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
126 class LiberviaTUITextBoxWidget(
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
127 xmlui.TextBoxWidget, sat_widgets.AdvancedEdit, LiberviaTUIEvents
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
128 ):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
129 def __init__(self, _xmlui_parent, value, read_only=False):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
130 sat_widgets.AdvancedEdit.__init__(self, edit_text=value, multiline=True)
1085
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
131 self.read_only = read_only
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
132
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
133 def selectable(self):
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
134 if self.read_only:
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
135 return False
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
136 return super(LiberviaTUITextBoxWidget, self).selectable()
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
137
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
138 def _xmlui_set_value(self, value):
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
139 self.set_edit_text(value)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
140
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
141 def _xmlui_get_value(self):
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 912
diff changeset
142 return self.get_edit_text()
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
143
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
144
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
145 class LiberviaTUIBoolWidget(xmlui.BoolWidget, urwid.CheckBox, LiberviaTUIEvents):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
146 def __init__(self, _xmlui_parent, state, read_only=False):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
147 urwid.CheckBox.__init__(self, "", state=state)
1085
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
148 self.read_only = read_only
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
149
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
150 def selectable(self):
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
151 if self.read_only:
7a39ae3950f7 frontends (XMLUI): implementation of read_only attributes for widgets String, TextBox, Password and Bool
Goffi <goffi@goffi.org>
parents: 1070
diff changeset
152 return False
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
153 return super(LiberviaTUIBoolWidget, self).selectable()
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
154
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
155 def _xmlui_set_value(self, value):
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
156 self.set_state(value == "true")
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
157
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
158 def _xmlui_get_value(self):
2101
cba3323710f0 Primitivus (xmlui): use constants for BOOL_TRUE and BOOL_FALSE value
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
159 return C.BOOL_TRUE if self.get_state() else C.BOOL_FALSE
632
06f44f797a1b primitivus: really basic implementation of advanced list.
Goffi <goffi@goffi.org>
parents: 610
diff changeset
160
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 632
diff changeset
161
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
162 class LiberviaTUIIntWidget(xmlui.IntWidget, sat_widgets.AdvancedEdit, LiberviaTUIEvents):
1220
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
163 def __init__(self, _xmlui_parent, value, read_only=False):
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
164 sat_widgets.AdvancedEdit.__init__(self, edit_text=value)
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
165 self.read_only = read_only
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
166
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
167 def selectable(self):
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
168 if self.read_only:
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
169 return False
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
170 return super(LiberviaTUIIntWidget, self).selectable()
1220
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
171
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
172 def _xmlui_set_value(self, value):
1220
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
173 self.set_edit_text(value)
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
174
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
175 def _xmlui_get_value(self):
1220
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
176 return self.get_edit_text()
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
177
f91e7028e2c3 memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents: 1185
diff changeset
178
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
179 class LiberviaTUIButtonWidget(
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
180 xmlui.ButtonWidget, sat_widgets.CustomButton, LiberviaTUIEvents
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
181 ):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
182 def __init__(self, _xmlui_parent, value, click_callback):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
183 sat_widgets.CustomButton.__init__(self, value, on_press=click_callback)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
184
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
185 def _xmlui_on_click(self, callback):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
186 urwid.connect_signal(self, "click", callback)
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
187
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
188
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
189 class LiberviaTUIListWidget(xmlui.ListWidget, sat_widgets.List, LiberviaTUIEvents):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
190 def __init__(self, _xmlui_parent, options, selected, flags):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
191 sat_widgets.List.__init__(self, options=options, style=flags)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
192 self._xmlui_select_values(selected)
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
193
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
194 def _xmlui_select_value(self, value):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
195 return self.select_value(value)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
196
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
197 def _xmlui_select_values(self, values):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
198 return self.select_values(values)
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 912
diff changeset
199
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
200 def _xmlui_get_selected_values(self):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
201 return [option.value for option in self.get_selected_values()]
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
202
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
203 def _xmlui_add_values(self, values, select=True):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
204 current_values = self.get_all_values()
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
205 new_values = copy.deepcopy(current_values)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
206 for value in values:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
207 if value not in current_values:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
208 new_values.append(value)
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
209 if select:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
210 selected = self._xmlui_get_selected_values()
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
211 self.change_values(new_values)
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
212 if select:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
213 for value in values:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
214 if value not in selected:
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
215 selected.append(value)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
216 self._xmlui_select_values(selected)
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
217
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
218
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
219 class LiberviaTUIJidsListWidget(xmlui.ListWidget, sat_widgets.List, LiberviaTUIEvents):
1478
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
220 def __init__(self, _xmlui_parent, jids, styles):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
221 sat_widgets.List.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
222 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
223 options=jids + [""], # the empty field is here to add new jids if needed
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
224 option_type=lambda txt, align: sat_widgets.AdvancedEdit(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
225 edit_text=txt, align=align
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
226 ),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
227 on_change=self._on_change,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
228 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
229 self.delete = 0
1478
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
230
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
231 def _on_change(self, list_widget, jid_widget=None, text=None):
1478
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
232 if jid_widget is not None:
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
233 if jid_widget != list_widget.contents[-1] and not text:
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
234 # if a field is empty, we delete the line (except for the last line)
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
235 list_widget.contents.remove(jid_widget)
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
236 elif jid_widget == list_widget.contents[-1] and text:
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
237 # we always want an empty field as last value to be able to add jids
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
238 list_widget.contents.append(sat_widgets.AdvancedEdit())
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
239
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
240 def _xmlui_get_selected_values(self):
1478
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
241 # XXX: there is not selection in this list, so we return all non empty values
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
242 return [jid_ for jid_ in self.get_all_values() if jid_]
1478
90130847a0a8 frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
243
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
244
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
245 class LiberviaTUIAdvancedListContainer(
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
246 xmlui.AdvancedListContainer, sat_widgets.TableContainer, LiberviaTUIEvents
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
247 ):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
248 def __init__(self, _xmlui_parent, columns, selectable="no"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
249 options = {"ADAPT": ()}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
250 if selectable != "no":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
251 options["HIGHLIGHT"] = ()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
252 sat_widgets.TableContainer.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
253 self, columns=columns, options=options, row_selectable=selectable != "no"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
254 )
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
255
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
256 def _xmlui_append(self, widget):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
257 self.add_widget(widget)
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
258
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
259 def _xmlui_add_row(self, idx):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
260 self.set_row_index(idx)
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
261
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
262 def _xmlui_get_selected_widgets(self):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
263 return self.get_selected_widgets()
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
264
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
265 def _xmlui_get_selected_index(self):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
266 return self.get_selected_index()
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
267
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
268 def _xmlui_on_select(self, callback):
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
269 """ Call callback with widget as only argument """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
270 urwid.connect_signal(self, "click", self._event_callback, callback)
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
271
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
272
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
273 class LiberviaTUIPairsContainer(xmlui.PairsContainer, sat_widgets.TableContainer):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
274 def __init__(self, _xmlui_parent):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
275 options = {"ADAPT": (0,), "HIGHLIGHT": (0,)}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
276 if self._xmlui_main.type == "param":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
277 options["FOCUS_ATTR"] = "param_selected"
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
278 sat_widgets.TableContainer.__init__(self, columns=2, options=options)
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
279
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
280 def _xmlui_append(self, widget):
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
281 if isinstance(widget, LiberviaTUIEmptyWidget):
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
282 # we don't want highlight on empty widgets
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
283 widget = urwid.AttrMap(widget, "default")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
284 self.add_widget(widget)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
285
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
286
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
287 class LiberviaTUILabelContainer(LiberviaTUIPairsContainer, xmlui.LabelContainer):
2361
5defafc8ede6 core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents: 2101
diff changeset
288 pass
5defafc8ede6 core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents: 2101
diff changeset
289
5defafc8ede6 core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents: 2101
diff changeset
290
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
291 class LiberviaTUITabsContainer(xmlui.TabsContainer, sat_widgets.TabsContainer):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
292 def __init__(self, _xmlui_parent):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
293 sat_widgets.TabsContainer.__init__(self)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
294
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
295 def _xmlui_append(self, widget):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
296 self.body.append(widget)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
297
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
298 def _xmlui_add_tab(self, label, selected):
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
299 tab = LiberviaTUIVerticalContainer(None)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
300 self.add_tab(label, tab, selected)
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
301 return tab
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
302
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
303
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
304 class LiberviaTUIVerticalContainer(xmlui.VerticalContainer, urwid.ListBox):
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
305 BOX_HEIGHT = 5
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
306
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
307 def __init__(self, _xmlui_parent):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
308 urwid.ListBox.__init__(self, urwid.SimpleListWalker([]))
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
309 self._last_size = None
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
310
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
311 def _xmlui_append(self, widget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
312 if "flow" not in widget.sizing():
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
313 widget = urwid.BoxAdapter(widget, self.BOX_HEIGHT)
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
314 self.body.append(widget)
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
315
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
316 def render(self, size, focus=False):
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
317 if size != self._last_size:
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
318 (maxcol, maxrow) = size
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
319 if self.body:
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
320 widget = self.body[0]
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
321 if isinstance(widget, urwid.BoxAdapter):
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
322 widget.height = maxrow
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
323 self._last_size = size
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
324 return super(LiberviaTUIVerticalContainer, self).render(size, focus)
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
325
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
326
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
327 ### Dialogs ###
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
328
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
329
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
330 class LiberviaTUIDialog(object):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
331 def __init__(self, _xmlui_parent):
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
332 self.host = _xmlui_parent.host
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
333
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
334 def _xmlui_show(self):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
335 self.host.show_pop_up(self)
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
336
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
337 def _xmlui_close(self):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
338 self.host.remove_pop_up(self)
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
339
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
340
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
341 class LiberviaTUIMessageDialog(LiberviaTUIDialog, xmlui.MessageDialog, sat_widgets.Alert):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
342 def __init__(self, _xmlui_parent, title, message, level):
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
343 LiberviaTUIDialog.__init__(self, _xmlui_parent)
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
344 xmlui.MessageDialog.__init__(self, _xmlui_parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
345 sat_widgets.Alert.__init__(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
346 self, title, message, ok_cb=lambda __: self._xmlui_close()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
347 )
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
348
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
349
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
350 class LiberviaTUINoteDialog(xmlui.NoteDialog, LiberviaTUIMessageDialog):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
351 # TODO: separate NoteDialog
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
352 pass
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
353
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
354
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
355 class LiberviaTUIConfirmDialog(
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
356 LiberviaTUIDialog, xmlui.ConfirmDialog, sat_widgets.ConfirmDialog
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
357 ):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
358 def __init__(self, _xmlui_parent, title, message, level, buttons_set):
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
359 LiberviaTUIDialog.__init__(self, _xmlui_parent)
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
360 xmlui.ConfirmDialog.__init__(self, _xmlui_parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
361 sat_widgets.ConfirmDialog.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
362 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
363 title,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
364 message,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
365 no_cb=lambda __: self._xmlui_cancelled(),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
366 yes_cb=lambda __: self._xmlui_validated(),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
367 )
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
368
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
369
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
370 class LiberviaTUIFileDialog(
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
371 LiberviaTUIDialog, xmlui.FileDialog, files_management.FileDialog
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
372 ):
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
373 def __init__(self, _xmlui_parent, title, message, level, filetype):
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
374 # TODO: message is not managed yet
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
375 LiberviaTUIDialog.__init__(self, _xmlui_parent)
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
376 xmlui.FileDialog.__init__(self, _xmlui_parent)
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
377 style = []
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
378 if filetype == C.XMLUI_DATA_FILETYPE_DIR:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
379 style.append("dir")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
380 files_management.FileDialog.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
381 self,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
382 ok_cb=lambda path: self._xmlui_validated({"path": path}),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
383 cancel_cb=lambda __: self._xmlui_cancelled(),
1518
8c071bc359c9 primitivus (XMLUI): manage message in FileDialog /!\ Urwid SàText need to be updated /!\
Goffi <goffi@goffi.org>
parents: 1486
diff changeset
384 message=message,
8c071bc359c9 primitivus (XMLUI): manage message in FileDialog /!\ Urwid SàText need to be updated /!\
Goffi <goffi@goffi.org>
parents: 1486
diff changeset
385 title=title,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
386 style=style,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
387 )
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
388
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
389
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
390 class GenericFactory(object):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
391 def __getattr__(self, attr):
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
392 if attr.startswith("create"):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
393 cls = globals()[
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
394 "LiberviaTUI" + attr[6:]
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
395 ] # XXX: we prefix with "LiberviaTUI" to work around an Urwid bug, WidgetMeta in Urwid don't manage multiple inheritance with same names
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
396 return cls
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
397
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
398
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
399 class WidgetFactory(GenericFactory):
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
400 def __getattr__(self, attr):
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
401 if attr.startswith("create"):
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
402 cls = GenericFactory.__getattr__(self, attr)
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
403 cls._xmlui_main = self._xmlui_main
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
404 return cls
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
405
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
406
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
407 class XMLUIPanel(xmlui.XMLUIPanel, LiberviaTUIWidget):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
408 widget_factory = WidgetFactory()
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
409
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
410 def __init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
411 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
412 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
413 parsed_xml,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
414 title=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
415 flags=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
416 callback=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
417 ignore=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
418 whitelist=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
419 profile=C.PROF_KEY_NONE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
420 ):
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
421 self.widget_factory._xmlui_main = self
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
422 self._dest = None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
423 xmlui.XMLUIPanel.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
424 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
425 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
426 parsed_xml,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
427 title=title,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
428 flags=flags,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
429 callback=callback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
430 ignore=ignore,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
431 profile=profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
432 )
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
433 LiberviaTUIWidget.__init__(self, self.main_cont, self.xmlui_title)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
434
2737
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
435
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
436 def _parse_childs(self, _xmlui_parent, current_node, wanted=("container",), data=None):
4076
b620a8e882e1 refactoring: rename `libervia.frontends.primitivus` to `libervia.tui`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
437 # Small hack to always have a VerticalContainer as main container in LiberviaTUI.
2737
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
438 # this used to be the default behaviour for all frontends, but now
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
439 # TabsContainer can also be the main container.
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
440 if _xmlui_parent is self:
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
441 node = current_node.childNodes[0]
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
442 if node.nodeName == "container" and node.getAttribute("type") == "tabs":
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
443 _xmlui_parent = self.widget_factory.createVerticalContainer(self)
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
444 self.main_cont = _xmlui_parent
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
445 return super(XMLUIPanel, self)._parse_childs(_xmlui_parent, current_node, wanted,
2737
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
446 data)
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
447
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
448
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
449 def construct_ui(self, parsed_dom):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
450 def post_treat():
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 796
diff changeset
451 assert self.main_cont.body
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
452
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
453 if self.type in ("form", "popup"):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
454 buttons = []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
455 if self.type == "form":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
456 buttons.append(urwid.Button(_("Submit"), self.on_form_submitted))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
457 if not "NO_CANCEL" in self.flags:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
458 buttons.append(urwid.Button(_("Cancel"), self.on_form_cancelled))
976
68faf7d77a42 frontends (xmlui): add setter methods + fixes:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
459 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
460 buttons.append(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
461 urwid.Button(_("OK"), on_press=lambda __: self._xmlui_close())
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
462 )
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
463 max_len = max([len(button.get_label()) for button in buttons])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
464 grid_wid = urwid.GridFlow(buttons, max_len + 4, 1, 0, "center")
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 796
diff changeset
465 self.main_cont.body.append(grid_wid)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
466 elif self.type == "param":
912
b70fb2ac5997 primitivus: PrimitivusVerticalContainer box widgets management:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
467 tabs_cont = self.main_cont.body[0].base_widget
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
468 assert isinstance(tabs_cont, sat_widgets.TabsContainer)
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
469 buttons = []
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
470 buttons.append(sat_widgets.CustomButton(_("Save"), self.on_save_params))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
471 buttons.append(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
472 sat_widgets.CustomButton(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
473 _("Cancel"), lambda x: self.host.remove_window()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
474 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
475 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
476 max_len = max([button.get_size() for button in buttons])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
477 grid_wid = urwid.GridFlow(buttons, max_len, 1, 0, "center")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
478 tabs_cont.add_footer(grid_wid)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
479
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
480 xmlui.XMLUIPanel.construct_ui(self, parsed_dom, post_treat)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 796
diff changeset
481 urwid.WidgetWrap.__init__(self, self.main_cont)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
482
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
483 def show(self, show_type=None, valign="middle"):
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
484 """Show the constructed UI
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
485 @param show_type: how to show the UI:
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
486 - None (follow XMLUI's recommendation)
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
487 - 'popup'
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
488 - 'window'
687
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 655
diff changeset
489 @param valign: vertical alignment when show_type is 'popup'.
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
490 Ignored when show_type is 'window'.
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
491
687
af0d08a84cc6 primitivus card_game: bug fix and improvement
souliane <souliane@mailoo.org>
parents: 655
diff changeset
492 """
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
493 if show_type is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
494 if self.type in ("window", "param"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
495 show_type = "window"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
496 elif self.type in ("popup", "form"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
497 show_type = "popup"
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
498
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
499 if show_type not in ("popup", "window"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
500 raise ValueError("Invalid show_type [%s]" % show_type)
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
501
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
502 self._dest = show_type
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
503 if show_type == "popup":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
504 self.host.show_pop_up(self, valign=valign)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
505 elif show_type == "window":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
506 self.host.new_widget(self, user_action=self.user_action)
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
507 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
508 assert False
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
509 self.host.redraw()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
510
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
511 def _xmlui_close(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
512 if self._dest == "window":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
513 self.host.remove_window()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
514 elif self._dest == "popup":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
515 self.host.remove_pop_up(self)
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
516 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
517 raise exceptions.InternalError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
518 "self._dest unknown, are you sure you have called XMLUI.show ?"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2577
diff changeset
519 )
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
520
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
521
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
522 class XMLUIDialog(xmlui.XMLUIDialog):
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
523 dialog_factory = GenericFactory()
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
524
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
525
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
526 xmlui.register_class(xmlui.CLASS_PANEL, XMLUIPanel)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
527 xmlui.register_class(xmlui.CLASS_DIALOG, XMLUIDialog)
1106
e2e1e27a3680 frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents: 1085
diff changeset
528 create = xmlui.create