comparison src/cagou/core/xmlui.py @ 15:56838ad5c84b

files reorganisation, cagou is now launched with python2 cagou.py in src/
author Goffi <goffi@goffi.org>
date Sat, 09 Jul 2016 17:24:01 +0200
parents src/xmlui.py@160cc95ad7ea
children 8b5827c43155
comparison
equal deleted inserted replaced
14:21a432afd06d 15:56838ad5c84b
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Cagou: a SàT frontend
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org)
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 from sat.core.i18n import _
21 from sat_frontends.constants import Const as C
22 from sat.core.log import getLogger
23 log = getLogger(__name__)
24 from sat_frontends.tools import xmlui
25 from kivy.uix.boxlayout import BoxLayout
26 from kivy.uix.textinput import TextInput
27 from kivy.uix.label import Label
28 from kivy.uix.button import Button
29 from kivy.uix.widget import Widget
30
31
32 class TextWidget(xmlui.TextWidget, Label):
33
34 def __init__(self, xmlui_parent, value):
35 Label.__init__(self, text=value)
36
37
38 class PasswordWidget(xmlui.PasswordWidget, TextInput):
39
40 def __init__(self, _xmlui_parent, value, read_only=False):
41 TextInput.__init__(self, password=True, multiline=False,
42 text=value, readonly=read_only, size=(100,25), size_hint=(1,None))
43
44 def _xmluiSetValue(self, value):
45 self.text = value
46
47 def _xmluiGetValue(self):
48 return self.text
49
50
51 class VerticalContainer(xmlui.VerticalContainer, BoxLayout):
52
53 def __init__(self, xmlui_parent):
54 BoxLayout.__init__(self, orientation='vertical')
55
56 def _xmluiAppend(self, widget):
57 self.add_widget(widget)
58
59
60 class WidgetFactory(object):
61
62 def __getattr__(self, attr):
63 if attr.startswith("create"):
64 cls = globals()[attr[6:]]
65 return cls
66
67
68 class Title(Label):
69
70 def __init__(self, *args, **kwargs):
71 kwargs['size'] = (100, 25)
72 kwargs['size_hint'] = (1,None)
73 super(Title, self).__init__(*args, **kwargs)
74
75
76 class XMLUIPanel(xmlui.XMLUIPanel, BoxLayout):
77 widget_factory = WidgetFactory()
78
79 def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
80 self.close_cb = None
81 BoxLayout.__init__(self, orientation='vertical')
82 xmlui.XMLUIPanel.__init__(self, host, parsed_xml, title, flags, callback, profile)
83
84 def setCloseCb(self, close_cb):
85 self.close_cb = close_cb
86
87 def _xmluiClose(self):
88 if self.close_cb is not None:
89 self.close_cb(self)
90 else:
91 log.error(u"No close method defined")
92
93 def constructUI(self, parsed_dom):
94 xmlui.XMLUIPanel.constructUI(self, parsed_dom)
95 if self.xmlui_title:
96 self.add_widget(Title(text=self.xmlui_title))
97 self.add_widget(self.main_cont)
98 if self.type == 'form':
99 submit_btn = Button(text=_(u"Submit"), size_hint=(1,0.2))
100 submit_btn.bind(on_press=self.onFormSubmitted)
101 self.add_widget(submit_btn)
102 if not 'NO_CANCEL' in self.flags:
103 cancel_btn = Button(text=_(u"Cancel"), size_hint=(1,0.2))
104 cancel_btn.bind(on_press=self.onFormCancelled)
105 self.add_widget(cancel_btn)
106 self.add_widget(Widget()) # to have elements on the top
107
108
109 xmlui.registerClass(xmlui.CLASS_PANEL, XMLUIPanel)
110 create = xmlui.create