Mercurial > libervia-desktop-kivy
annotate cagou/core/xmlui.py @ 236:ca86954b3788
xmlui: implemented TextBoxWidget + set height for XMLUIPanel
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 31 Aug 2018 16:58:15 +0200 |
parents | 525527a01439 |
children | 661b9cf7b4e4 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Cagou: a SàT frontend | |
126 | 5 # Copyright (C) 2016-2018 Jérôme Poisson (goffi@goffi.org) |
0 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 from sat.core.i18n import _ | |
55 | 21 from .constants import Const as C |
0 | 22 from sat.core.log import getLogger |
23 log = getLogger(__name__) | |
24 from sat_frontends.tools import xmlui | |
99 | 25 from kivy.uix.boxlayout import BoxLayout |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
26 from kivy.uix.gridlayout import GridLayout |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
27 from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem |
0 | 28 from kivy.uix.textinput import TextInput |
29 from kivy.uix.label import Label | |
30 from kivy.uix.button import Button | |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
31 from kivy.uix.togglebutton import ToggleButton |
0 | 32 from kivy.uix.widget import Widget |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
33 from kivy.uix.dropdown import DropDown |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
34 from kivy.uix.switch import Switch |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
35 from kivy import properties |
29 | 36 from cagou import G |
204
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
37 from cagou.core import dialog |
235
525527a01439
xmlui: use create with partial and class_map, following change in base class
Goffi <goffi@goffi.org>
parents:
227
diff
changeset
|
38 from functools import partial |
29 | 39 |
40 | |
41 ## Widgets ## | |
0 | 42 |
43 | |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
44 class TextInputOnChange(object): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
45 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
46 def __init__(self): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
47 self._xmlui_onchange_cb = None |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
48 self._got_focus = False |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
49 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
50 def _xmluiOnChange(self, callback): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
51 self._xmlui_onchange_cb = callback |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
52 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
53 def on_focus(self, instance, focus): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
54 # we need to wait for first focus, else initial value |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
55 # will trigger a on_text |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
56 if not self._got_focus and focus: |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
57 self._got_focus = True |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
58 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
59 def on_text(self, instance, new_text): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
60 if self._xmlui_onchange_cb is not None and self._got_focus: |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
61 self._xmlui_onchange_cb(self) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
62 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
63 |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
64 class EmptyWidget(xmlui.EmptyWidget, Widget): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
65 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
66 def __init__(self, _xmlui_parent): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
67 Widget.__init__(self) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
68 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
69 |
0 | 70 class TextWidget(xmlui.TextWidget, Label): |
71 | |
72 def __init__(self, xmlui_parent, value): | |
73 Label.__init__(self, text=value) | |
74 | |
75 | |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
76 class LabelWidget(xmlui.LabelWidget, TextWidget): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
77 pass |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
78 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
79 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
80 class JidWidget(xmlui.JidWidget, TextWidget): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
81 pass |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
82 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
83 |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
84 class StringWidget(xmlui.StringWidget, TextInput, TextInputOnChange): |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
85 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
86 def __init__(self, xmlui_parent, value, read_only=False): |
236
ca86954b3788
xmlui: implemented TextBoxWidget + set height for XMLUIPanel
Goffi <goffi@goffi.org>
parents:
235
diff
changeset
|
87 TextInput.__init__(self, text=value) |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
88 TextInputOnChange.__init__(self) |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
89 self.readonly = read_only |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
90 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
91 def _xmluiSetValue(self, value): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
92 self.text = value |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
93 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
94 def _xmluiGetValue(self): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
95 return self.text |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
96 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
97 |
236
ca86954b3788
xmlui: implemented TextBoxWidget + set height for XMLUIPanel
Goffi <goffi@goffi.org>
parents:
235
diff
changeset
|
98 class TextBoxWidget(xmlui.TextBoxWidget, StringWidget): |
ca86954b3788
xmlui: implemented TextBoxWidget + set height for XMLUIPanel
Goffi <goffi@goffi.org>
parents:
235
diff
changeset
|
99 pass |
ca86954b3788
xmlui: implemented TextBoxWidget + set height for XMLUIPanel
Goffi <goffi@goffi.org>
parents:
235
diff
changeset
|
100 |
ca86954b3788
xmlui: implemented TextBoxWidget + set height for XMLUIPanel
Goffi <goffi@goffi.org>
parents:
235
diff
changeset
|
101 |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
102 class JidInputWidget(xmlui.JidInputWidget, StringWidget): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
103 pass |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
104 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
105 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
106 class ButtonWidget(xmlui.ButtonWidget, Button): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
107 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
108 def __init__(self, _xmlui_parent, value, click_callback): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
109 Button.__init__(self) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
110 self.text = value |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
111 self.callback = click_callback |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
112 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
113 def _xmluiOnClick(self, callback): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
114 self.callback = callback |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
115 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
116 def on_release(self): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
117 self.callback(self) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
118 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
119 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
120 class DividerWidget(xmlui.DividerWidget, Widget): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
121 # FIXME: not working properly + only 'line' is handled |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
122 style = properties.OptionProperty('line', |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
123 options=['line', 'dot', 'dash', 'plain', 'blank']) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
124 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
125 def __init__(self, _xmlui_parent, style="line"): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
126 Widget.__init__(self, style=style) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
127 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
128 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
129 class ListWidgetItem(ToggleButton): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
130 value = properties.StringProperty() |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
131 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
132 def on_release(self): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
133 super(ListWidgetItem, self).on_release() |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
134 parent = self.parent |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
135 while parent is not None and not isinstance(parent, DropDown): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
136 parent = parent.parent |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
137 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
138 if parent is not None and parent.attach_to is not None: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
139 parent.select(self) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
140 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
141 @property |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
142 def selected(self): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
143 return self.state == 'down' |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
144 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
145 @selected.setter |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
146 def selected(self, value): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
147 self.state = 'down' if value else 'normal' |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
148 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
149 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
150 class ListWidget(xmlui.ListWidget, Button): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
151 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
152 def __init__(self, _xmlui_parent, options, selected, flags): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
153 Button.__init__(self) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
154 self.text = _(u"open list") |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
155 self._dropdown = DropDown() |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
156 self._dropdown.auto_dismiss = False |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
157 self._dropdown.bind(on_select = self.on_select) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
158 self.multi = 'single' not in flags |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
159 self._dropdown.dismiss_on_select = not self.multi |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
160 self._values = [] |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
161 for option in options: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
162 self.addValue(option) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
163 self._xmluiSelectValues(selected) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
164 self._on_change = None |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
165 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
166 @property |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
167 def items(self): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
168 return self._dropdown.children[0].children |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
169 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
170 def on_touch_down(self, touch): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
171 # we simulate auto-dismiss ourself because dropdown |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
172 # will dismiss even if attached button is touched |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
173 # resulting in a dismiss just before a toggle in on_release |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
174 # so the dropbox would always be opened, we don't want that! |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
175 if super(ListWidget, self).on_touch_down(touch): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
176 return True |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
177 if self._dropdown.parent: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
178 self._dropdown.dismiss() |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
179 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
180 def on_release(self): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
181 if self._dropdown.parent is not None: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
182 # we want to close a list already opened |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
183 self._dropdown.dismiss() |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
184 else: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
185 self._dropdown.open(self) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
186 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
187 def on_select(self, drop_down, item): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
188 if not self.multi: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
189 self._xmluiSelectValues([item.value]) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
190 if self._on_change is not None: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
191 self._on_change(self) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
192 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
193 def addValue(self, option, selected=False): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
194 """add a value in the list |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
195 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
196 @param option(tuple): value, label in a tuple |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
197 """ |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
198 self._values.append(option) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
199 item = ListWidgetItem() |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
200 item.value, item.text = option |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
201 item.selected = selected |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
202 self._dropdown.add_widget(item) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
203 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
204 def _xmluiSelectValue(self, value): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
205 self._xmluiSelectValues([value]) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
206 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
207 def _xmluiSelectValues(self, values): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
208 for item in self.items: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
209 item.selected = item.value in values |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
210 if item.selected and not self.multi: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
211 self.text = item.text |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
212 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
213 def _xmluiGetSelectedValues(self): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
214 return [item.value for item in self.items if item.selected] |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
215 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
216 def _xmluiAddValues(self, values, select=True): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
217 values = set(values).difference([c.value for c in self.items]) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
218 for v in values: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
219 self.addValue(v, select) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
220 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
221 def _xmluiOnChange(self, callback): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
222 self._on_change = callback |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
223 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
224 |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
225 class JidsListWidget(ListWidget): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
226 # TODO: real list dedicated to jids |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
227 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
228 def __init__(self, _xmlui_parent, jids, flags): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
229 ListWidget.__init__(self, _xmlui_parent, [(j,j) for j in jids], [], flags) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
230 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
231 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
232 class PasswordWidget(xmlui.PasswordWidget, TextInput, TextInputOnChange): |
0 | 233 |
234 def __init__(self, _xmlui_parent, value, read_only=False): | |
235 TextInput.__init__(self, password=True, multiline=False, | |
236 text=value, readonly=read_only, size=(100,25), size_hint=(1,None)) | |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
237 TextInputOnChange.__init__(self) |
0 | 238 |
239 def _xmluiSetValue(self, value): | |
240 self.text = value | |
241 | |
242 def _xmluiGetValue(self): | |
243 return self.text | |
244 | |
245 | |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
246 class BoolWidget(xmlui.BoolWidget, Switch): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
247 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
248 def __init__(self, _xmlui_parent, state, read_only=False): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
249 Switch.__init__(self, active=state) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
250 if read_only: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
251 self.disabled = True |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
252 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
253 def _xmluiSetValue(self, value): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
254 self.active = value |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
255 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
256 def _xmluiGetValue(self): |
76
a766c278b640
xmlui: fixed BoolWidget _xmluiGetValue:
Goffi <goffi@goffi.org>
parents:
71
diff
changeset
|
257 return C.BOOL_TRUE if self.active else C.BOOL_FALSE |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
258 |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
259 def _xmluiOnChange(self, callback): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
260 self.bind(active=lambda instance, value: callback(instance)) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
261 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
262 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
263 class IntWidget(xmlui.IntWidget, TextInput, TextInputOnChange): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
264 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
265 def __init__(self, _xmlui_parent, value, read_only=False): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
266 TextInput.__init__(self, text=value, input_filter='int', multiline=False) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
267 TextInputOnChange.__init__(self) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
268 if read_only: |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
269 self.disabled = True |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
270 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
271 def _xmluiSetValue(self, value): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
272 self.text = value |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
273 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
274 def _xmluiGetValue(self): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
275 return self.text |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
276 |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
277 |
29 | 278 ## Containers ## |
279 | |
280 | |
159 | 281 class VerticalContainer(xmlui.VerticalContainer, BoxLayout): |
0 | 282 |
283 def __init__(self, xmlui_parent): | |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
284 self.xmlui_parent = xmlui_parent |
159 | 285 BoxLayout.__init__(self, orientation="vertical") |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
286 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
287 def _xmluiAppend(self, widget): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
288 self.add_widget(widget) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
289 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
290 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
291 class PairsContainer(xmlui.PairsContainer, GridLayout): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
292 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
293 def __init__(self, xmlui_parent): |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
294 self.xmlui_parent = xmlui_parent |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
295 GridLayout.__init__(self) |
0 | 296 |
297 def _xmluiAppend(self, widget): | |
298 self.add_widget(widget) | |
299 | |
300 | |
125
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
301 class LabelContainer(PairsContainer, xmlui.LabelContainer): |
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
302 pass |
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
303 |
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
304 |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
305 class TabsPanelContainer(TabbedPanelItem): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
306 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
307 def _xmluiAppend(self, widget): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
308 self.add_widget(widget) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
309 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
310 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
311 class TabsContainer(xmlui.TabsContainer, TabbedPanel): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
312 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
313 def __init__(self, xmlui_parent): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
314 self.xmlui_parent = xmlui_parent |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
315 xmlui_panel = xmlui_parent |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
316 while not isinstance(xmlui_panel, XMLUIPanel): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
317 xmlui_panel = xmlui_panel.xmlui_parent |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
318 xmlui_panel.addPostTreat(self._postTreat) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
319 TabbedPanel.__init__(self, do_default_tab=False) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
320 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
321 def _xmluiAddTab(self, label, selected): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
322 tab = TabsPanelContainer(text=label) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
323 self.add_widget(tab) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
324 return tab |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
325 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
326 def _postTreat(self): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
327 """bind minimum height of tabs' content so self.height is adapted""" |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
328 # we need to do this in postTreat because contents exists after UI construction |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
329 for t in self.tab_list: |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
330 t.content.bind(minimum_height=self._updateHeight) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
331 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
332 def _updateHeight(self, instance, height): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
333 """Called after UI is constructed (so height can be calculated)""" |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
334 # needed because TabbedPanel doesn't have a minimum_height property |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
335 self.height = max([t.content.minimum_height for t in self.tab_list]) + self.tab_height + 5 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
336 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
337 |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
338 class AdvancedListRow(GridLayout): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
339 global_index = 0 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
340 index = properties.ObjectProperty() |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
341 selected = properties.BooleanProperty(False) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
342 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
343 def __init__(self, **kwargs): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
344 self.global_index = AdvancedListRow.global_index |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
345 AdvancedListRow.global_index += 1 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
346 super(AdvancedListRow, self).__init__(**kwargs) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
347 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
348 def on_touch_down(self, touch): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
349 if self.collide_point(*touch.pos): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
350 parent = self.parent |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
351 while parent is not None and not isinstance(parent, AdvancedListContainer): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
352 parent = parent.parent |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
353 if parent is None: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
354 log.error(u"Can't find parent AdvancedListContainer") |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
355 else: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
356 if parent.selectable: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
357 self.selected = parent._xmluiToggleSelected(self) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
358 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
359 return super(AdvancedListRow, self).on_touch_down(touch) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
360 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
361 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
362 class AdvancedListContainer(xmlui.AdvancedListContainer, GridLayout): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
363 |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
364 def __init__(self, xmlui_parent, columns, selectable='no'): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
365 self.xmlui_parent = xmlui_parent |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
366 GridLayout.__init__(self) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
367 self._columns = columns |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
368 self.selectable = selectable != 'no' |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
369 self._current_row = None |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
370 self._selected = [] |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
371 self._xmlui_select_cb = None |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
372 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
373 def _xmluiToggleSelected(self, row): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
374 """inverse selection status of an AdvancedListRow |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
375 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
376 @param row(AdvancedListRow): row to (un)select |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
377 @return (bool): True if row is selected |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
378 """ |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
379 try: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
380 self._selected.remove(row) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
381 except ValueError: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
382 self._selected.append(row) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
383 if self._xmlui_select_cb is not None: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
384 self._xmlui_select_cb(self) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
385 return True |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
386 else: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
387 return False |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
388 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
389 def _xmluiAppend(self, widget): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
390 if self._current_row is None: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
391 log.error(u"No row set, ignoring append") |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
392 return |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
393 self._current_row.add_widget(widget) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
394 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
395 def _xmluiAddRow(self, idx): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
396 self._current_row = AdvancedListRow() |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
397 self._current_row.cols = self._columns |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
398 self._current_row.index = idx |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
399 self.add_widget(self._current_row) |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
400 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
401 def _xmluiGetSelectedWidgets(self): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
402 return self._selected |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
403 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
404 def _xmluiGetSelectedIndex(self): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
405 if not self._selected: |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
406 return None |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
407 return self._selected[0].index |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
408 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
409 def _xmluiOnSelect(self, callback): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
410 """ Call callback with widget as only argument """ |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
411 self._xmlui_select_cb = callback |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
412 |
29 | 413 ## Dialogs ## |
414 | |
415 | |
416 class NoteDialog(xmlui.NoteDialog): | |
417 | |
418 def __init__(self, _xmlui_parent, title, message, level): | |
419 xmlui.NoteDialog.__init__(self, _xmlui_parent) | |
420 self.title, self.message, self.level = title, message, level | |
421 | |
422 def _xmluiShow(self): | |
423 G.host.addNote(self.title, self.message, self.level) | |
424 | |
425 | |
204
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
426 class ConfirmDialog(xmlui.ConfirmDialog, dialog.ConfirmDialog): |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
427 |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
428 def __init__(self, _xmlui_parent, title, message, level, buttons_set): |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
429 dialog.ConfirmDialog.__init__(self, |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
430 title=title, |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
431 message=message, |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
432 no_cb = self.no_cb, |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
433 yes_cb = self.yes_cb) |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
434 xmlui.ConfirmDialog.__init__(self, _xmlui_parent) |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
435 |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
436 def no_cb(self): |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
437 G.host.closeUI() |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
438 self._xmluiCancelled() |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
439 |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
440 def yes_cb(self): |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
441 G.host.closeUI() |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
442 self._xmluiValidated() |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
443 |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
444 def _xmluiShow(self): |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
445 G.host.addNotifUI(self) |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
446 |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
447 def _xmluiClose(self): |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
448 G.host.closeUI() |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
449 |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
450 def show(self, *args, **kwargs): |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
451 assert kwargs["force"] |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
452 G.host.showUI(self) |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
453 |
37638765c97b
xmlui: implemented ConfirmDialog using new dialog.ConfirmDialog
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
454 |
99 | 455 class FileDialog(xmlui.FileDialog, BoxLayout): |
456 message = properties.ObjectProperty() | |
457 | |
458 def __init__(self, _xmlui_parent, title, message, level, filetype): | |
459 xmlui.FileDialog.__init__(self, _xmlui_parent) | |
460 BoxLayout.__init__(self) | |
461 self.message.text = message | |
462 if filetype == C.XMLUI_DATA_FILETYPE_DIR: | |
463 self.file_chooser.dirselect = True | |
464 | |
465 def _xmluiShow(self): | |
466 G.host.addNotifUI(self) | |
467 | |
468 def _xmluiClose(self): | |
469 # FIXME: notif UI is not removed if dialog is not shown yet | |
470 G.host.closeUI() | |
471 | |
472 def onSelect(self, path): | |
473 try: | |
474 path = path[0] | |
475 except IndexError: | |
476 path = None | |
477 if not path: | |
478 self._xmluiCancelled() | |
479 else: | |
480 self._xmluiValidated({'path': path}) | |
481 | |
482 def show(self, *args, **kwargs): | |
483 assert kwargs["force"] | |
484 G.host.showUI(self) | |
485 | |
486 | |
29 | 487 ## Factory ## |
488 | |
489 | |
0 | 490 class WidgetFactory(object): |
491 | |
492 def __getattr__(self, attr): | |
493 if attr.startswith("create"): | |
494 cls = globals()[attr[6:]] | |
495 return cls | |
496 | |
497 | |
29 | 498 ## Core ## |
499 | |
500 | |
0 | 501 class Title(Label): |
502 | |
503 def __init__(self, *args, **kwargs): | |
504 kwargs['size'] = (100, 25) | |
505 kwargs['size_hint'] = (1,None) | |
506 super(Title, self).__init__(*args, **kwargs) | |
507 | |
508 | |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
509 class FormButton(Button): |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
510 pass |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
511 |
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
512 |
159 | 513 class XMLUIPanel(xmlui.XMLUIPanel, BoxLayout): |
0 | 514 widget_factory = WidgetFactory() |
515 | |
129
0704f3be65cb
xmlui: fixed missing whitelist argument
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
516 def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, ignore=None, whitelist=None, profile=C.PROF_KEY_NONE): |
159 | 517 BoxLayout.__init__(self, orientation="vertical") |
0 | 518 self.close_cb = None |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
519 self._post_treats = [] # list of callback to call after UI is constructed |
125
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
520 xmlui.XMLUIPanel.__init__(self, |
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
521 host, |
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
522 parsed_xml, |
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
523 title=title, |
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
524 flags=flags, |
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
525 callback=callback, |
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
526 ignore=ignore, |
129
0704f3be65cb
xmlui: fixed missing whitelist argument
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
527 whitelist=whitelist, |
125
b6e6afb0dc46
xmlui: added LabelContainer and updated XMLUIPanel following changes in main class
Goffi <goffi@goffi.org>
parents:
99
diff
changeset
|
528 profile=profile) |
0 | 529 |
530 def setCloseCb(self, close_cb): | |
531 self.close_cb = close_cb | |
532 | |
533 def _xmluiClose(self): | |
534 if self.close_cb is not None: | |
535 self.close_cb(self) | |
536 else: | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
537 G.host.closeUI() |
0 | 538 |
71
8c9fe2c5aacc
settings: save button is now disabled when there is nothing to save
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
539 def onParamChange(self, ctrl): |
8c9fe2c5aacc
settings: save button is now disabled when there is nothing to save
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
540 super(XMLUIPanel, self).onParamChange(ctrl) |
8c9fe2c5aacc
settings: save button is now disabled when there is nothing to save
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
541 self.save_btn.disabled = False |
8c9fe2c5aacc
settings: save button is now disabled when there is nothing to save
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
542 |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
543 def addPostTreat(self, callback): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
544 self._post_treats.append(callback) |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
545 |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
546 def _postTreatCb(self): |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
547 for cb in self._post_treats: |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
548 cb() |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
549 del self._post_treats |
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
550 |
71
8c9fe2c5aacc
settings: save button is now disabled when there is nothing to save
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
551 def _saveButtonCb(self, button): |
8c9fe2c5aacc
settings: save button is now disabled when there is nothing to save
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
552 button.disabled = True |
8c9fe2c5aacc
settings: save button is now disabled when there is nothing to save
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
553 self.onSaveParams(button) |
8c9fe2c5aacc
settings: save button is now disabled when there is nothing to save
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
554 |
0 | 555 def constructUI(self, parsed_dom): |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
556 xmlui.XMLUIPanel.constructUI(self, parsed_dom, self._postTreatCb) |
0 | 557 if self.xmlui_title: |
558 self.add_widget(Title(text=self.xmlui_title)) | |
559 self.add_widget(self.main_cont) | |
560 if self.type == 'form': | |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
561 submit_btn = FormButton(text=_(u"Submit")) |
0 | 562 submit_btn.bind(on_press=self.onFormSubmitted) |
563 self.add_widget(submit_btn) | |
564 if not 'NO_CANCEL' in self.flags: | |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
565 cancel_btn = FormButton(text=_(u"Cancel")) |
0 | 566 cancel_btn.bind(on_press=self.onFormCancelled) |
567 self.add_widget(cancel_btn) | |
69
a9c6b089070d
xmlui: improvments to prepare parameters:
Goffi <goffi@goffi.org>
parents:
55
diff
changeset
|
568 elif self.type == 'param': |
71
8c9fe2c5aacc
settings: save button is now disabled when there is nothing to save
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
569 self.save_btn = FormButton(text=_(u"Save"), disabled=True) |
8c9fe2c5aacc
settings: save button is now disabled when there is nothing to save
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
570 self.save_btn.bind(on_press=self._saveButtonCb) |
8c9fe2c5aacc
settings: save button is now disabled when there is nothing to save
Goffi <goffi@goffi.org>
parents:
69
diff
changeset
|
571 self.add_widget(self.save_btn) |
53
65775152aac1
xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
572 self.add_widget(Widget()) # to have elements on the top |
0 | 573 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
574 def show(self, *args, **kwargs): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
575 if not self.user_action and not kwargs.get("force", False): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
576 G.host.addNotifUI(self) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
577 else: |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
578 G.host.showUI(self) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
579 |
0 | 580 |
29 | 581 class XMLUIDialog(xmlui.XMLUIDialog): |
582 dialog_factory = WidgetFactory() | |
583 | |
584 | |
235
525527a01439
xmlui: use create with partial and class_map, following change in base class
Goffi <goffi@goffi.org>
parents:
227
diff
changeset
|
585 create = partial(xmlui.create, class_map={ |
525527a01439
xmlui: use create with partial and class_map, following change in base class
Goffi <goffi@goffi.org>
parents:
227
diff
changeset
|
586 xmlui.CLASS_PANEL: XMLUIPanel, |
525527a01439
xmlui: use create with partial and class_map, following change in base class
Goffi <goffi@goffi.org>
parents:
227
diff
changeset
|
587 xmlui.CLASS_DIALOG: XMLUIDialog}) |