annotate cagou/core/xmlui.py @ 170:f4522b7c3318

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