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 _ |
|
24 from 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 |
|
30 from cagou_widget import CagouWidget |
|
31 |
|
32 |
14
|
33 PLUGIN_INFO = { |
|
34 "name": _(u"widget selector"), |
|
35 "import_name": C.WID_SELECTOR, |
|
36 "main": "WidgetSelector", |
|
37 "description": _(u"show available widgets and allow to select one"), |
|
38 } |
|
39 |
|
40 |
12
|
41 class WidgetSelItem(ButtonBehavior, BoxLayout): |
14
|
42 plugin_info = properties.DictProperty() |
12
|
43 |
|
44 def __init__(self, **kwargs): |
|
45 super(WidgetSelItem, self).__init__(**kwargs) |
|
46 self.host = kwargs['host'] |
|
47 |
|
48 def select(self, *args): |
14
|
49 log.debug(u"widget selection: {}".format(self.plugin_info["name"])) |
|
50 factory = self.plugin_info["factory"] |
|
51 self.host.switchWidget(self, factory(self.host, self.plugin_info, None, None)) |
12
|
52 |
|
53 def deselect(self, *args): |
|
54 pass |
|
55 |
|
56 |
|
57 class WidgetSelector(CagouWidget): |
|
58 |
|
59 def __init__(self, host): |
14
|
60 super(WidgetSelector, self).__init__(host) |
12
|
61 self.host = host |
14
|
62 self.adapter = ListAdapter( |
|
63 data=host.getPluggedWidgets(except_cls=self.__class__), |
12
|
64 cls=WidgetSelItem, |
|
65 args_converter=self.dataConverter, |
|
66 selection_mode='single', |
|
67 allow_empty_selection=True, |
|
68 ) |
|
69 self.add_widget(ListView(adapter=self.adapter)) |
|
70 |
14
|
71 @classmethod |
|
72 def factory(cls, host, plugin_info, target, profiles): |
|
73 return cls(host) |
|
74 |
|
75 def dataConverter(self, idx, plugin_info): |
12
|
76 return { |
|
77 "host": self.host, |
14
|
78 "plugin_info": plugin_info, |
12
|
79 } |
14
|
80 |
|
81 |
|
82 PLUGIN_INFO["factory"] = WidgetSelector.factory |