Mercurial > libervia-desktop-kivy
annotate src/cagou/plugins/plugin_wid_widget_selector.py @ 16:ba14b596b90e
host can now be get as a global value:
instead of always copying host from class to class, it can now be gotten from a global class with:
from cagou import G
then G.host will give host.
This will probably be used on the long term on all SàT (backend + frontends).
As host is currently needed in several places (most importantly in QuickFrontend), the argument is still present, and must be there even is unused on class inheriting from QuickSomething.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 09 Jul 2016 18:41:52 +0200 |
parents | 56838ad5c84b |
children | 790dbc5c4e89 |
rev | line source |
---|---|
12 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
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 | |
21 from sat.core import log as logging | |
22 log = logging.getLogger(__name__) | |
14 | 23 from sat.core.i18n import _ |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
24 from cagou.core.constants import Const as C |
12 | 25 from kivy.uix.boxlayout import BoxLayout |
26 from kivy.uix.listview import ListView | |
27 from kivy.adapters.listadapter import ListAdapter | |
28 from kivy import properties | |
29 from kivy.uix.behaviors import ButtonBehavior | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
30 from cagou.core import cagou_widget |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
31 from cagou import G |
12 | 32 |
33 | |
14 | 34 PLUGIN_INFO = { |
35 "name": _(u"widget selector"), | |
36 "import_name": C.WID_SELECTOR, | |
37 "main": "WidgetSelector", | |
38 "description": _(u"show available widgets and allow to select one"), | |
39 } | |
40 | |
41 | |
12 | 42 class WidgetSelItem(ButtonBehavior, BoxLayout): |
14 | 43 plugin_info = properties.DictProperty() |
12 | 44 |
45 def __init__(self, **kwargs): | |
46 super(WidgetSelItem, self).__init__(**kwargs) | |
47 | |
48 def select(self, *args): | |
14 | 49 log.debug(u"widget selection: {}".format(self.plugin_info["name"])) |
50 factory = self.plugin_info["factory"] | |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
51 G.host.switchWidget(self, factory(self.plugin_info, None, None)) |
12 | 52 |
53 def deselect(self, *args): | |
54 pass | |
55 | |
56 | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
57 class WidgetSelector(cagou_widget.CagouWidget): |
12 | 58 |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
59 def __init__(self): |
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
60 super(WidgetSelector, self).__init__() |
14 | 61 self.adapter = ListAdapter( |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
62 data=G.host.getPluggedWidgets(except_cls=self.__class__), |
12 | 63 cls=WidgetSelItem, |
64 args_converter=self.dataConverter, | |
65 selection_mode='single', | |
66 allow_empty_selection=True, | |
67 ) | |
68 self.add_widget(ListView(adapter=self.adapter)) | |
69 | |
14 | 70 @classmethod |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
71 def factory(cls, plugin_info, target, profiles): |
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
72 return cls() |
14 | 73 |
74 def dataConverter(self, idx, plugin_info): | |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
75 return {"plugin_info": plugin_info} |
14 | 76 |
77 | |
78 PLUGIN_INFO["factory"] = WidgetSelector.factory |