annotate src/cagou/plugins/plugin_wid_widget_selector.py @ 97:5d2289127bb7

menu (upload): better menu using dedicated widget: upload menu now use a decicated widget instead of context menu. The menu take half the size of the main window, and show each upload option as an icon. Use can select upload or P2P sending, and a short text message explains how the file will be transmitted.
author Goffi <goffi@goffi.org>
date Thu, 29 Dec 2016 23:47:07 +0100
parents 9a6121722669
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org)
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core import log as logging
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 log = logging.getLogger(__name__)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
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
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from kivy.uix.boxlayout import BoxLayout
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from kivy.uix.listview import ListView
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from kivy.adapters.listadapter import ListAdapter
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from kivy import properties
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
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
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
34 PLUGIN_INFO = {
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
35 "name": _(u"widget selector"),
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
36 "import_name": C.WID_SELECTOR,
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
37 "main": "WidgetSelector",
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
38 "description": _(u"show available widgets and allow to select one"),
90
9a6121722669 chat, contact_list, selector: use of new icons from muchoslava
Goffi <goffi@goffi.org>
parents: 39
diff changeset
39 "icon_small": u"{media}/icons/muchoslava/png/selector_new_32.png",
9a6121722669 chat, contact_list, selector: use of new icons from muchoslava
Goffi <goffi@goffi.org>
parents: 39
diff changeset
40 "icon_medium": u"{media}/icons/muchoslava/png/selector_new_44.png"
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
41 }
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
42
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
43
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 class WidgetSelItem(ButtonBehavior, BoxLayout):
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
45 plugin_info = properties.DictProperty()
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def __init__(self, **kwargs):
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 super(WidgetSelItem, self).__init__(**kwargs)
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
49
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 def select(self, *args):
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
51 log.debug(u"widget selection: {}".format(self.plugin_info["name"]))
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
52 factory = self.plugin_info["factory"]
18
790dbc5c4e89 plugin widget selector: display improvment + host profiles are now used by default
Goffi <goffi@goffi.org>
parents: 16
diff changeset
53 G.host.switchWidget(self, factory(self.plugin_info, None, profiles=iter(G.host.profiles)))
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
54
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 def deselect(self, *args):
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 pass
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
57
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
59 class WidgetSelector(cagou_widget.CagouWidget):
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
60
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
61 def __init__(self):
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
62 super(WidgetSelector, self).__init__()
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
63 self.adapter = ListAdapter(
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
64 data=G.host.getPluggedWidgets(except_cls=self.__class__),
12
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 cls=WidgetSelItem,
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 args_converter=self.dataConverter,
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 selection_mode='single',
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 allow_empty_selection=True,
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 )
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.add_widget(ListView(adapter=self.adapter))
30f6586f904b widget selector:
Goffi <goffi@goffi.org>
parents:
diff changeset
71
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
72 @classmethod
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
73 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
74 return cls()
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
75
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
76 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
77 return {"plugin_info": plugin_info}
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
78
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
79
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 12
diff changeset
80 PLUGIN_INFO["factory"] = WidgetSelector.factory