Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_wid_widget_selector.py @ 126:cd99f70ea592
global file reorganisation:
- follow common convention by puttin cagou in "cagou" instead of "src/cagou"
- added VERSION in cagou with current version
- updated dates
- moved main executable in /bin
- moved buildozer files in root directory
- temporary moved platform to assets/platform
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 05 Apr 2018 17:11:21 +0200 |
parents | src/cagou/plugins/plugin_wid_widget_selector.py@9a6121722669 |
children | 6a288d4a493f |
comparison
equal
deleted
inserted
replaced
125:b6e6afb0dc46 | 126:cd99f70ea592 |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
5 # Copyright (C) 2016-2018 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__) | |
23 from sat.core.i18n import _ | |
24 from cagou.core.constants import Const as C | |
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 | |
30 from cagou.core import cagou_widget | |
31 from cagou import G | |
32 | |
33 | |
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 "icon_small": u"{media}/icons/muchoslava/png/selector_new_32.png", | |
40 "icon_medium": u"{media}/icons/muchoslava/png/selector_new_44.png" | |
41 } | |
42 | |
43 | |
44 class WidgetSelItem(ButtonBehavior, BoxLayout): | |
45 plugin_info = properties.DictProperty() | |
46 | |
47 def __init__(self, **kwargs): | |
48 super(WidgetSelItem, self).__init__(**kwargs) | |
49 | |
50 def select(self, *args): | |
51 log.debug(u"widget selection: {}".format(self.plugin_info["name"])) | |
52 factory = self.plugin_info["factory"] | |
53 G.host.switchWidget(self, factory(self.plugin_info, None, profiles=iter(G.host.profiles))) | |
54 | |
55 def deselect(self, *args): | |
56 pass | |
57 | |
58 | |
59 class WidgetSelector(cagou_widget.CagouWidget): | |
60 | |
61 def __init__(self): | |
62 super(WidgetSelector, self).__init__() | |
63 self.adapter = ListAdapter( | |
64 data=G.host.getPluggedWidgets(except_cls=self.__class__), | |
65 cls=WidgetSelItem, | |
66 args_converter=self.dataConverter, | |
67 selection_mode='single', | |
68 allow_empty_selection=True, | |
69 ) | |
70 self.add_widget(ListView(adapter=self.adapter)) | |
71 | |
72 @classmethod | |
73 def factory(cls, plugin_info, target, profiles): | |
74 return cls() | |
75 | |
76 def dataConverter(self, idx, plugin_info): | |
77 return {"plugin_info": plugin_info} | |
78 | |
79 | |
80 PLUGIN_INFO["factory"] = WidgetSelector.factory |