Mercurial > libervia-desktop-kivy
annotate src/cagou/core/xmlui.py @ 46:d6a63942d5ad
chat: fixed MUC joining following changes in backend
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 10 Sep 2016 00:04:18 +0200 |
parents | c21d1be2e54c |
children | 65775152aac1 |
rev | line source |
---|---|
0 | 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 | |
29 | 30 from cagou import G |
31 | |
32 | |
33 ## Widgets ## | |
0 | 34 |
35 | |
36 class TextWidget(xmlui.TextWidget, Label): | |
37 | |
38 def __init__(self, xmlui_parent, value): | |
39 Label.__init__(self, text=value) | |
40 | |
41 | |
42 class PasswordWidget(xmlui.PasswordWidget, TextInput): | |
43 | |
44 def __init__(self, _xmlui_parent, value, read_only=False): | |
45 TextInput.__init__(self, password=True, multiline=False, | |
46 text=value, readonly=read_only, size=(100,25), size_hint=(1,None)) | |
47 | |
48 def _xmluiSetValue(self, value): | |
49 self.text = value | |
50 | |
51 def _xmluiGetValue(self): | |
52 return self.text | |
53 | |
54 | |
29 | 55 ## Containers ## |
56 | |
57 | |
0 | 58 class VerticalContainer(xmlui.VerticalContainer, BoxLayout): |
59 | |
60 def __init__(self, xmlui_parent): | |
61 BoxLayout.__init__(self, orientation='vertical') | |
62 | |
63 def _xmluiAppend(self, widget): | |
64 self.add_widget(widget) | |
65 | |
66 | |
29 | 67 ## Dialogs ## |
68 | |
69 | |
70 class NoteDialog(xmlui.NoteDialog): | |
71 | |
72 def __init__(self, _xmlui_parent, title, message, level): | |
73 xmlui.NoteDialog.__init__(self, _xmlui_parent) | |
74 self.title, self.message, self.level = title, message, level | |
75 | |
76 def _xmluiShow(self): | |
77 G.host.addNote(self.title, self.message, self.level) | |
78 | |
79 | |
80 ## Factory ## | |
81 | |
82 | |
0 | 83 class WidgetFactory(object): |
84 | |
85 def __getattr__(self, attr): | |
86 if attr.startswith("create"): | |
87 cls = globals()[attr[6:]] | |
88 return cls | |
89 | |
90 | |
29 | 91 ## Core ## |
92 | |
93 | |
0 | 94 class Title(Label): |
95 | |
96 def __init__(self, *args, **kwargs): | |
97 kwargs['size'] = (100, 25) | |
98 kwargs['size_hint'] = (1,None) | |
99 super(Title, self).__init__(*args, **kwargs) | |
100 | |
101 | |
102 class XMLUIPanel(xmlui.XMLUIPanel, BoxLayout): | |
103 widget_factory = WidgetFactory() | |
104 | |
105 def __init__(self, host, parsed_xml, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): | |
106 self.close_cb = None | |
107 BoxLayout.__init__(self, orientation='vertical') | |
108 xmlui.XMLUIPanel.__init__(self, host, parsed_xml, title, flags, callback, profile) | |
109 | |
110 def setCloseCb(self, close_cb): | |
111 self.close_cb = close_cb | |
112 | |
113 def _xmluiClose(self): | |
114 if self.close_cb is not None: | |
115 self.close_cb(self) | |
116 else: | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
117 G.host.closeUI() |
0 | 118 |
119 def constructUI(self, parsed_dom): | |
120 xmlui.XMLUIPanel.constructUI(self, parsed_dom) | |
121 if self.xmlui_title: | |
122 self.add_widget(Title(text=self.xmlui_title)) | |
123 self.add_widget(self.main_cont) | |
124 if self.type == 'form': | |
125 submit_btn = Button(text=_(u"Submit"), size_hint=(1,0.2)) | |
126 submit_btn.bind(on_press=self.onFormSubmitted) | |
127 self.add_widget(submit_btn) | |
128 if not 'NO_CANCEL' in self.flags: | |
129 cancel_btn = Button(text=_(u"Cancel"), size_hint=(1,0.2)) | |
130 cancel_btn.bind(on_press=self.onFormCancelled) | |
131 self.add_widget(cancel_btn) | |
132 self.add_widget(Widget()) # to have elements on the top | |
133 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
134 def show(self, *args, **kwargs): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
135 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
|
136 G.host.addNotifUI(self) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
137 else: |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
138 G.host.showUI(self) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
139 |
0 | 140 |
29 | 141 class XMLUIDialog(xmlui.XMLUIDialog): |
142 dialog_factory = WidgetFactory() | |
143 | |
144 | |
0 | 145 xmlui.registerClass(xmlui.CLASS_PANEL, XMLUIPanel) |
29 | 146 xmlui.registerClass(xmlui.CLASS_DIALOG, XMLUIDialog) |
0 | 147 create = xmlui.create |