Mercurial > libervia-desktop-kivy
comparison cagou/core/common_widgets.py @ 237:059c5b39032d
plugin file sharing: moved common discovery widgets to new core.common_widgets module
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 31 Aug 2018 16:59:38 +0200 |
parents | |
children | 1b835bcfa663 |
comparison
equal
deleted
inserted
replaced
236:ca86954b3788 | 237:059c5b39032d |
---|---|
1 #!/usr/bin/env python2 | |
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 """common advanced widgets, which can be reused everywhere.""" | |
21 | |
22 from sat.core.i18n import _ | |
23 from kivy.uix.label import Label | |
24 from kivy.uix.boxlayout import BoxLayout | |
25 from cagou.core.menu import TouchMenuItemBehaviour | |
26 from kivy import properties | |
27 from kivy.metrics import dp | |
28 from cagou import G | |
29 from sat.core import log as logging | |
30 | |
31 log = logging.getLogger(__name__) | |
32 | |
33 | |
34 class Identities(object): | |
35 | |
36 def __init__(self, entity_ids): | |
37 identities = {} | |
38 for cat, type_, name in entity_ids: | |
39 identities.setdefault(cat, {}).setdefault(type_, []).append(name) | |
40 client = identities.get('client', {}) | |
41 if 'pc' in client: | |
42 self.type = 'desktop' | |
43 elif 'phone' in client: | |
44 self.type = 'phone' | |
45 elif 'web' in client: | |
46 self.type = 'web' | |
47 elif 'console' in client: | |
48 self.type = 'console' | |
49 else: | |
50 self.type = 'desktop' | |
51 | |
52 self.identities = identities | |
53 | |
54 @property | |
55 def name(self): | |
56 return self.identities.values()[0].values()[0][0] | |
57 | |
58 | |
59 class ItemWidget(TouchMenuItemBehaviour, BoxLayout): | |
60 name = properties.StringProperty() | |
61 base_width = properties.NumericProperty(dp(100)) | |
62 | |
63 | |
64 class DeviceWidget(ItemWidget): | |
65 | |
66 def __init__(self, main_wid, entity_jid, identities, **kw): | |
67 self.entity_jid = entity_jid | |
68 self.identities = identities | |
69 own_jid = next(G.host.profiles.itervalues()).whoami | |
70 self.own_device = entity_jid.bare == own_jid | |
71 if self.own_device: | |
72 name = self.identities.name | |
73 elif self.entity_jid.node: | |
74 name = self.entity_jid.node | |
75 elif self.entity_jid == own_jid.domain: | |
76 name = _(u"your server") | |
77 else: | |
78 name = entity_jid | |
79 | |
80 super(DeviceWidget, self).__init__(name=name, main_wid=main_wid, **kw) | |
81 | |
82 @property | |
83 def profile(self): | |
84 return self.main_wid.profile | |
85 | |
86 def getSymbol(self): | |
87 if self.identities.type == 'desktop': | |
88 return 'desktop' | |
89 elif self.identities.type == 'phone': | |
90 return 'mobile' | |
91 elif self.identities.type == 'web': | |
92 return 'globe' | |
93 elif self.identities.type == 'console': | |
94 return 'terminal' | |
95 else: | |
96 return 'desktop' | |
97 | |
98 def do_item_action(self, touch): | |
99 pass | |
100 | |
101 | |
102 class CategorySeparator(Label): | |
103 pass |