Mercurial > libervia-desktop-kivy
annotate cagou/plugins/plugin_wid_settings.py @ 353:19422bbd9c8e
core (widgets handler): refactoring:
- CagouWidget now has class properties (to be overridden when needed) which indicate how
if the widget handle must add a wrapping ScreenManager (global_screen_manager) or show
all instances of the class in a Carousel (collection_carousel). If none of those
options is used, a ScrollView will be wrapping the widget, to be sure that the widget
will be resized correctly when necessary (without it, the widget could still be
drawn in the backround when the size is too small and overflow on the WidgetWrapper,
this would be the case with WidgetSelector)
- some helper methods/properties have been added to CagouWidget. Check docstrings for
details
- better handling of (in)visible widget in WidgetsHandler
- thanks to the new wrapping ScrollView, WidgetSelect will show scroll bars if the
available space is too small.
- bugs fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 17 Jan 2020 18:44:35 +0100 |
parents | 772c170b47a9 |
children | 080b6cc17f53 |
rev | line source |
---|---|
70
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client |
282 | 5 # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org) |
70
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from sat.core import log as logging |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 log = logging.getLogger(__name__) |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat.core.i18n import _ |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from sat.core.constants import Const as C |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from sat_frontends.quick_frontend import quick_widgets |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from kivy.uix.label import Label |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from kivy.uix.widget import Widget |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from cagou.core import cagou_widget |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from cagou import G |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 PLUGIN_INFO = { |
312 | 33 "name": _("settings"), |
286 | 34 "main": "CagouSettings", |
312 | 35 "description": _("Cagou/SàT settings"), |
36 "icon_symbol": "wrench", | |
70
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 } |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
286 | 40 class CagouSettings(quick_widgets.QuickWidget, cagou_widget.CagouWidget): |
41 # XXX: this class can't be called "Settings", because Kivy has already a class | |
42 # of this name, and the kv there would apply | |
70
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 def __init__(self, host, target, profiles): |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 quick_widgets.QuickWidget.__init__(self, G.host, target, profiles) |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 cagou_widget.CagouWidget.__init__(self) |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 # the Widget() avoid CagouWidget header to be down at the beginning |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 # then up when the UI is loaded |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 self.loading_widget = Widget() |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 self.add_widget(self.loading_widget) |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 G.host.bridge.getParamsUI(-1, C.APP_NAME, self.profile, callback=self.getParamsUICb, errback=self.getParamsUIEb) |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 def changeWidget(self, widget): |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 self.clear_widgets([self.loading_widget]) |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 del self.loading_widget |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 self.add_widget(widget) |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 def getParamsUICb(self, xmlui): |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 G.host.actionManager({"xmlui": xmlui}, ui_show_cb=self.changeWidget, profile=self.profile) |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 def getParamsUIEb(self, failure): |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 self.changeWidget(Label( |
312 | 63 text=_("Can't load parameters!"), |
70
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 bold=True, |
46b5f3ecf6a1
settings: settings widget plugin, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 color=(1,0,0,1))) |
312 | 66 G.host.showDialog("Can't load params UI", failure, "error") |