annotate src/xmlui.py @ 6:85649eca9f9b

core (logs): integrate Kivy logs with SàT: - forbid kivy to handle its own logs - added log_kivy_level option which can be put in sat.conf in [cagou] section. This option can have the following values: - follow [default]: follow SàT cagou level - kivy: follow level set in kivy own configuration - [log_level]: set this log level only for kivy messages
author Goffi <goffi@goffi.org>
date Thu, 07 Jul 2016 09:39:21 +0200
parents 160cc95ad7ea
children
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
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from kivy.uix.boxlayout import BoxLayout
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from kivy.uix.textinput import TextInput
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from kivy.uix.label import Label
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from kivy.uix.button import Button
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from kivy.uix.widget import Widget
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 class TextWidget(xmlui.TextWidget, Label):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 def __init__(self, xmlui_parent, value):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 Label.__init__(self, text=value)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 class PasswordWidget(xmlui.PasswordWidget, TextInput):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 def __init__(self, _xmlui_parent, value, read_only=False):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 TextInput.__init__(self, password=True, multiline=False,
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 text=value, readonly=read_only, size=(100,25), size_hint=(1,None))
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def _xmluiSetValue(self, value):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.text = value
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def _xmluiGetValue(self):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 return self.text
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
49
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 class VerticalContainer(xmlui.VerticalContainer, BoxLayout):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def __init__(self, xmlui_parent):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 BoxLayout.__init__(self, orientation='vertical')
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 def _xmluiAppend(self, widget):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.add_widget(widget)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
59
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 class WidgetFactory(object):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def __getattr__(self, attr):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 if attr.startswith("create"):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 cls = globals()[attr[6:]]
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 return cls
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
66
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
67
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 class Title(Label):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
69
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 def __init__(self, *args, **kwargs):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 kwargs['size'] = (100, 25)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 kwargs['size_hint'] = (1,None)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 super(Title, self).__init__(*args, **kwargs)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
74
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
75
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 class XMLUIPanel(xmlui.XMLUIPanel, BoxLayout):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 widget_factory = WidgetFactory()
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
78
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 self.close_cb = None
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 BoxLayout.__init__(self, orientation='vertical')
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 xmlui.XMLUIPanel.__init__(self, host, parsed_xml, title, flags, callback, profile)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
83
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 def setCloseCb(self, close_cb):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 self.close_cb = close_cb
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
86
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 def _xmluiClose(self):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 if self.close_cb is not None:
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.close_cb(self)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 else:
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 log.error(u"No close method defined")
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
92
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 def constructUI(self, parsed_dom):
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 xmlui.XMLUIPanel.constructUI(self, parsed_dom)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 if self.xmlui_title:
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 self.add_widget(Title(text=self.xmlui_title))
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 self.add_widget(self.main_cont)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 if self.type == 'form':
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 submit_btn = Button(text=_(u"Submit"), size_hint=(1,0.2))
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 submit_btn.bind(on_press=self.onFormSubmitted)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 self.add_widget(submit_btn)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 if not 'NO_CANCEL' in self.flags:
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 cancel_btn = Button(text=_(u"Cancel"), size_hint=(1,0.2))
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 cancel_btn.bind(on_press=self.onFormCancelled)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.add_widget(cancel_btn)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 self.add_widget(Widget()) # to have elements on the top
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
107
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
108
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 xmlui.registerClass(xmlui.CLASS_PANEL, XMLUIPanel)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 create = xmlui.create