annotate src/cagou/core/xmlui.py @ 54:514c187afebc

chat: changed udpate to use dict instead of single key/value
author Goffi <goffi@goffi.org>
date Thu, 15 Sep 2016 21:59:39 +0200
parents 65775152aac1
children b0011c6dc7dc
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
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org)
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 _
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat_frontends.constants import Const as C
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
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
25 from kivy.uix.scrollview import ScrollView
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
26 from kivy.uix.gridlayout import GridLayout
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from kivy.uix.textinput import TextInput
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from kivy.uix.label import Label
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from kivy.uix.button import Button
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
30 from kivy.uix.togglebutton import ToggleButton
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from kivy.uix.widget import Widget
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
32 from kivy.uix.dropdown import DropDown
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
33 from kivy.uix.switch import Switch
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
34 from kivy import properties
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
35 from cagou import G
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
36
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 ## Widgets ##
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
41 class EmptyWidget(xmlui.EmptyWidget, Widget):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
42
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
43 def __init__(self, _xmlui_parent):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
44 Widget.__init__(self)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
45
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
46
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 class TextWidget(xmlui.TextWidget, Label):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 def __init__(self, xmlui_parent, value):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 Label.__init__(self, text=value)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
53 class LabelWidget(xmlui.LabelWidget, TextWidget):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
54 pass
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
55
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
56
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
57 class JidWidget(xmlui.JidWidget, TextWidget):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
58 pass
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
59
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
60
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
61 class StringWidget(xmlui.StringWidget, TextInput):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
62
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
63 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
64 TextInput.__init__(self, text=value, multiline=False)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
65 self.readonly = read_only
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
66
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
67 def _xmluiSetValue(self, value):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
68 self.text = value
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
69
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
70 def _xmluiGetValue(self):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
71 return self.text
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
72
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
73
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
74 class JidInputWidget(xmlui.JidInputWidget, StringWidget):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
75 pass
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
76
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 class ButtonWidget(xmlui.ButtonWidget, Button):
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 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
81 Button.__init__(self)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
82 self.text = value
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
83 self.callback = click_callback
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 _xmluiOnClick(self, callback):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
86 self.callback = callback
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
87
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
88 def on_release(self):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
89 self.callback(self)
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
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
92 class DividerWidget(xmlui.DividerWidget, Widget):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
93 # 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
94 style = properties.OptionProperty('line',
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
95 options=['line', 'dot', 'dash', 'plain', 'blank'])
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 def __init__(self, _xmlui_parent, style="line"):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
98 Widget.__init__(self, style=style)
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 ListWidgetItem(ToggleButton):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
102 value = properties.StringProperty()
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
103
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
104 def on_release(self):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
105 super(ListWidgetItem, self).on_release()
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
106 parent = self.parent
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
107 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
108 parent = parent.parent
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
109
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
110 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
111 parent.select(self)
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 @property
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
114 def selected(self):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
115 return self.state == 'down'
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
116
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
117 @selected.setter
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
118 def selected(self, value):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
119 self.state = 'down' if value else 'normal'
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
120
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
121
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
122 class ListWidget(xmlui.ListWidget, Button):
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 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
125 Button.__init__(self)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
126 self.text = _(u"open list")
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
127 self._dropdown = DropDown()
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
128 self._dropdown.auto_dismiss = False
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
129 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
130 self.multi = 'single' not in flags
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
131 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
132 self._values = []
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
133 for option in options:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
134 self.addValue(option)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
135 self._xmluiSelectValues(selected)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
136 self._on_change = None
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 @property
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
139 def items(self):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
140 return self._dropdown.children[0].children
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
141
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
142 def on_touch_down(self, touch):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
143 # we simulate auto-dismiss ourself because dropdown
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
144 # 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
145 # 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
146 # 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
147 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
148 return True
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
149 if self._dropdown.parent:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
150 self._dropdown.dismiss()
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 on_release(self):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
153 if self._dropdown.parent is not None:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
154 # 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
155 self._dropdown.dismiss()
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
156 else:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
157 self._dropdown.open(self)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
158
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
159 def on_select(self, drop_down, item):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
160 if not self.multi:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
161 self._xmluiSelectValues([item.value])
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
162 if self._on_change is not None:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
163 self._on_change(self)
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 addValue(self, option, selected=False):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
166 """add a value in the list
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
167
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
168 @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
169 """
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
170 self._values.append(option)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
171 item = ListWidgetItem()
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
172 item.value, item.text = option
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
173 item.selected = selected
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
174 self._dropdown.add_widget(item)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
175
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
176 def _xmluiSelectValue(self, value):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
177 self._xmluiSelectValues([value])
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
178
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
179 def _xmluiSelectValues(self, values):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
180 for item in self.items:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
181 item.selected = item.value in values
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
182 if item.selected and not self.multi:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
183 self.text = item.text
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
184
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
185 def _xmluiGetSelectedValues(self):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
186 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
187
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
188 def _xmluiAddValues(self, values, select=True):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
189 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
190 for v in values:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
191 self.addValue(v, select)
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 _xmluiOnChange(self, callback):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
194 self._on_change = callback
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
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 class PasswordWidget(xmlui.PasswordWidget, TextInput):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
198
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 def __init__(self, _xmlui_parent, value, read_only=False):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 TextInput.__init__(self, password=True, multiline=False,
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 text=value, readonly=read_only, size=(100,25), size_hint=(1,None))
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
202
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 def _xmluiSetValue(self, value):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 self.text = value
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
205
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 def _xmluiGetValue(self):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 return self.text
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
208
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
209
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
210 class BoolWidget(xmlui.BoolWidget, Switch):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
211
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
212 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
213 Switch.__init__(self, active=state)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
214 if read_only:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
215 self.disabled = True
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
216
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
217 def _xmluiSetValue(self, value):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
218 self.active = value
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
219
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
220 def _xmluiGetValue(self):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
221 return self.active
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
222
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
223
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
224 ## Containers ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
225
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
226
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
227 class VerticalContainer(xmlui.VerticalContainer, GridLayout):
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):
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
230 GridLayout.__init__(self)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
231
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
232 def _xmluiAppend(self, widget):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
233 self.add_widget(widget)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
234
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
235
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
236 class PairsContainer(xmlui.PairsContainer, GridLayout):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
237
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
238 def __init__(self, xmlui_parent):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
239 GridLayout.__init__(self)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
240
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 def _xmluiAppend(self, widget):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 self.add_widget(widget)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
243
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
244
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
245 class AdvancedListRow(GridLayout):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
246 global_index = 0
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
247 index = properties.ObjectProperty()
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
248 selected = properties.BooleanProperty(False)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
249
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
250 def __init__(self, **kwargs):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
251 self.global_index = AdvancedListRow.global_index
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
252 AdvancedListRow.global_index += 1
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
253 super(AdvancedListRow, self).__init__(**kwargs)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
254
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
255 def on_touch_down(self, touch):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
256 if self.collide_point(*touch.pos):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
257 parent = self.parent
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
258 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
259 parent = parent.parent
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
260 if parent is None:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
261 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
262 else:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
263 if parent.selectable:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
264 self.selected = parent._xmluiToggleSelected(self)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
265
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
266 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
267
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
268
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
269 class AdvancedListContainer(xmlui.AdvancedListContainer, GridLayout):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
270
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
271 def __init__(self, _xmlui_parent, columns, selectable='no'):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
272 GridLayout.__init__(self)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
273 self._columns = columns
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
274 self.selectable = selectable != 'no'
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
275 self._current_row = None
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
276 self._selected = []
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
277 self._xmlui_select_cb = None
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
278
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
279 def _xmluiToggleSelected(self, row):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
280 """inverse selection status of an AdvancedListRow
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 @param row(AdvancedListRow): row to (un)select
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
283 @return (bool): True if row is selected
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 try:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
286 self._selected.remove(row)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
287 except ValueError:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
288 self._selected.append(row)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
289 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
290 self._xmlui_select_cb(self)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
291 return True
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
292 else:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
293 return False
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
294
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
295 def _xmluiAppend(self, widget):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
296 if self._current_row is None:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
297 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
298 return
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
299 self._current_row.add_widget(widget)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
300
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
301 def _xmluiAddRow(self, idx):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
302 self._current_row = AdvancedListRow()
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
303 self._current_row.cols = self._columns
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
304 self._current_row.index = idx
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
305 self.add_widget(self._current_row)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
306
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
307 def _xmluiGetSelectedWidgets(self):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
308 return self._selected
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
309
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
310 def _xmluiGetSelectedIndex(self):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
311 if not self._selected:
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
312 return None
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
313 return self._selected[0].index
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
314
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
315 def _xmluiOnSelect(self, callback):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
316 """ Call callback with widget as only argument """
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
317 self._xmlui_select_cb = callback
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
318
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
319 ## Dialogs ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
320
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
321
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
322 class NoteDialog(xmlui.NoteDialog):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
323
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
324 def __init__(self, _xmlui_parent, title, message, level):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
325 xmlui.NoteDialog.__init__(self, _xmlui_parent)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
326 self.title, self.message, self.level = title, message, level
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
327
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
328 def _xmluiShow(self):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
329 G.host.addNote(self.title, self.message, self.level)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
330
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
331
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
332 ## Factory ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
333
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
334
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
335 class WidgetFactory(object):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
336
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 def __getattr__(self, attr):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 if attr.startswith("create"):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 cls = globals()[attr[6:]]
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 return cls
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
341
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
342
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
343 ## Core ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
344
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
345
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 class Title(Label):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
347
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 def __init__(self, *args, **kwargs):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 kwargs['size'] = (100, 25)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 kwargs['size_hint'] = (1,None)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 super(Title, self).__init__(*args, **kwargs)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
352
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
353
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
354 class FormButton(Button):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
355 pass
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
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
358 class XMLUIPanelGrid(GridLayout):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
359 pass
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 class XMLUIPanel(xmlui.XMLUIPanel, ScrollView):
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 widget_factory = WidgetFactory()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
363
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
365 ScrollView.__init__(self)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 self.close_cb = None
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
367 self._grid = XMLUIPanelGrid()
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
368 ScrollView.add_widget(self, self._grid)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
369 xmlui.XMLUIPanel.__init__(self, host, parsed_xml, title, flags, callback, profile)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
370
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
371 def add_widget(self, wid):
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
372 self._grid.add_widget(wid)
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
373
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
374 def setCloseCb(self, close_cb):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 self.close_cb = close_cb
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
376
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 def _xmluiClose(self):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 if self.close_cb is not None:
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
379 self.close_cb(self)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
380 else:
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
381 G.host.closeUI()
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
382
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
383 def constructUI(self, parsed_dom):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
384 xmlui.XMLUIPanel.constructUI(self, parsed_dom)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
385 if self.xmlui_title:
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
386 self.add_widget(Title(text=self.xmlui_title))
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 self.add_widget(self.main_cont)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
388 if self.type == 'form':
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
389 submit_btn = FormButton(text=_(u"Submit"))
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
390 submit_btn.bind(on_press=self.onFormSubmitted)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
391 self.add_widget(submit_btn)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
392 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
393 cancel_btn = FormButton(text=_(u"Cancel"))
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
394 cancel_btn.bind(on_press=self.onFormCancelled)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
395 self.add_widget(cancel_btn)
53
65775152aac1 xmlui: implemented most of XMLUI, not finished yet
Goffi <goffi@goffi.org>
parents: 33
diff changeset
396 self.add_widget(Widget()) # to have elements on the top
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
397
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
398 def show(self, *args, **kwargs):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
399 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
400 G.host.addNotifUI(self)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
401 else:
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
402 G.host.showUI(self)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 29
diff changeset
403
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
404
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
405 class XMLUIDialog(xmlui.XMLUIDialog):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
406 dialog_factory = WidgetFactory()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
407
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
408
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
409 xmlui.registerClass(xmlui.CLASS_PANEL, XMLUIPanel)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
410 xmlui.registerClass(xmlui.CLASS_DIALOG, XMLUIDialog)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
411 create = xmlui.create