annotate src/plugin_wid_contact_list.py @ 14:21a432afd06d

plugin system, first draft: - widgets are now handled with plugins, ContactList and WidgetSelector have been changed to be pluggins - everything in PLUGIN_INFO (including PLUGIN_INFO itself) is optional. Best guess is used if a value is missing - WidgetsHandler use default widget from plugins, which is WidgetSelector for now - PLUGIN_INFO is used in the same way as for backed plugins, with (for now) following possible keys: - "name": human readable name - "description": long description of what widget do - "import_name": unique short name used as reference for import - "main": main class name - "factory": callback used to instanciate a widget (see Cagou._defaultFactory) - "kv_file": path to the kv language file to load (same filename with ".kv" will be used if key is not found) other data should be added quickly, as a path to a file used as icon - host.getPluggedWidgets can be used to find loaded widgets. except_cls can be used to excluse a class (self.__class__ usually) - fixed host.switchWidget when old widget is already a CagouWidget - CagouWidget header new display the available widgets
author Goffi <goffi@goffi.org>
date Sat, 09 Jul 2016 16:02:44 +0200
parents src/contact_list.py@8b2836b5b6c7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org)
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core import log as logging
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 log = logging.getLogger(__name__)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
23 from sat.core.i18n import _
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from kivy.uix.boxlayout import BoxLayout
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from kivy.uix.listview import ListView
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from kivy.adapters.listadapter import ListAdapter
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from kivy import properties
10
8b2836b5b6c7 added CagouWidget:
Goffi <goffi@goffi.org>
parents: 9
diff changeset
29 from cagou_widget import CagouWidget
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 import image
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
33 PLUGIN_INFO = {
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
34 "name": _(u"contacts"),
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
35 "main": "ContactList",
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
36 "description": _(u"list of contacts"),
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
37 }
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
38
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
39
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 class Avatar(image.Image):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 pass
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 class ContactItem(BoxLayout):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 data = properties.DictProperty()
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 jid = properties.StringProperty('')
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def __init__(self, **kwargs):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 BoxLayout.__init__(self, **kwargs)
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51
10
8b2836b5b6c7 added CagouWidget:
Goffi <goffi@goffi.org>
parents: 9
diff changeset
52 class ContactList(QuickContactList, CagouWidget):
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 def __init__(self, host, target, profiles):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 QuickContactList.__init__(self, host, profiles)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
56 CagouWidget.__init__(self, host)
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.adapter = ListAdapter(data={},
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 cls=ContactItem,
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 args_converter=self.contactDataConverter,
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 selection_mode='multiple',
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 allow_empty_selection=True,
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 )
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 self.add_widget(ListView(adapter=self.adapter))
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.update()
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 def contactDataConverter(self, idx, bare_jid):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 return {"jid": bare_jid, "data": self._items_cache[bare_jid]}
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 def update(self, entities=None, type_=None, profile=None):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 log.info("update: %s %s %s" % (entities, type_, profile))
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 # FIXME: for now we update on each event
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 # if entities is None and type_ is None:
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self._items_cache = self.items
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.adapter.data = self.items_sorted
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75