annotate cagou/core/common.py @ 316:86566968837a

android (p4a): updated P4A option to use Python 3: - hostpython3 is now used so we are using Python 3 - added pyasn1 and pyasn1-modules which were lacking - recent p4a now use setup.py, this is currently disabled to keep the building working
author Goffi <goffi@goffi.org>
date Wed, 16 Oct 2019 08:48:32 +0200
parents 772c170b47a9
children e2b51663d8b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr//bin/env python2
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
3
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
282
1b835bcfa663 date update
Goffi <goffi@goffi.org>
parents: 273
diff changeset
5 # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org)
26
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
6
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
11
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
16
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
19
237
059c5b39032d plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents: 220
diff changeset
20 """common simple widgets"""
26
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
21
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
22 from sat.core.i18n import _
26
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from kivy.uix.image import Image
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
24 from kivy.uix.label import Label
26
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from kivy.uix.behaviors import ButtonBehavior
193
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
26 from kivy.uix.behaviors import ToggleButtonBehavior
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
27 from kivy.uix.boxlayout import BoxLayout
193
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
28 from cagou.core.constants import Const as C
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
29 from kivy import properties
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
30 from cagou import G
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
31 import json
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
32 from sat.core import log as logging
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
33
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
34 log = logging.getLogger(__name__)
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
35
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
36 UNKNOWN_SYMBOL = 'Unknown symbol name'
26
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
37
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
38
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
39 class IconButton(ButtonBehavior, Image):
3efca1b10b2f common: first draft of a module were common widgets will be put
Goffi <goffi@goffi.org>
parents:
diff changeset
40 pass
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
41
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
42
193
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
43 class JidItem(BoxLayout):
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
44 bg_color = properties.ListProperty([0.2, 0.2, 0.2, 1])
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
45 color = properties.ListProperty([1, 1, 1, 1])
256
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
46 jid = properties.StringProperty()
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
47 profile = properties.StringProperty()
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
48 nick = properties.StringProperty()
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
49 avatar = properties.ObjectProperty()
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
50
256
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
51 def on_avatar(self, wid, jid_):
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
52 if self.jid and self.profile:
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
53 self.getImage()
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
54
256
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
55 def on_jid(self, wid, jid_):
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
56 if self.profile and self.avatar:
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
57 self.getImage()
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
58
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
59 def on_profile(self, wid, profile):
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
60 if self.jid and self.avatar:
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
61 self.getImage()
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
62
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
63 def getImage(self):
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
64 host = G.host
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
65 if host.contact_lists[self.profile].isRoom(self.jid.bare):
256
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
66 self.avatar.opacity = 0
ba7b8cb7ddcd common: don't use anymore positional argument in JidItem
Goffi <goffi@goffi.org>
parents: 247
diff changeset
67 self.avatar.source = ""
107
f0cf44df8486 JidWidget: first draft
Goffi <goffi@goffi.org>
parents: 26
diff changeset
68 else:
273
0ef216091f2b core: removed forgotten debugging code
Goffi <goffi@goffi.org>
parents: 256
diff changeset
69 self.avatar.source = (
0ef216091f2b core: removed forgotten debugging code
Goffi <goffi@goffi.org>
parents: 256
diff changeset
70 host.getAvatar(self.jid, profile=self.profile)
0ef216091f2b core: removed forgotten debugging code
Goffi <goffi@goffi.org>
parents: 256
diff changeset
71 or host.getDefaultAvatar(self.jid)
0ef216091f2b core: removed forgotten debugging code
Goffi <goffi@goffi.org>
parents: 256
diff changeset
72 )
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
73
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
74
193
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
75 class JidButton(ButtonBehavior, JidItem):
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
76 pass
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
77
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
78
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
79 class JidToggle(ToggleButtonBehavior, JidItem):
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
80 selected_color = properties.ListProperty(C.COLOR_SEC_DARK)
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
81
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 179
diff changeset
82
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
83 class Symbol(Label):
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
84 symbol_map = None
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
85 symbol = properties.StringProperty()
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
86
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
87 def __init__(self, **kwargs):
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
88 if self.symbol_map is None:
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
89 with open(G.host.app.expand('{media}/fonts/fontello/config.json')) as f:
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
90 fontello_conf = json.load(f)
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
91 Symbol.symbol_map = {g['css']:g['code'] for g in fontello_conf['glyphs']}
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
92
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
93 super(Symbol, self).__init__(**kwargs)
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
94
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
95 def on_symbol(self, instance, symbol):
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
96 try:
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
97 code = self.symbol_map[symbol]
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
98 except KeyError:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
99 log.warning(_("Invalid symbol {symbol}").format(symbol=symbol))
134
1cca97e27a69 core (common): new Symbol widget:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
100 else:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
101 self.text = chr(code)
135
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 134
diff changeset
102
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 134
diff changeset
103
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 134
diff changeset
104 class SymbolButton(ButtonBehavior, Symbol):
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 134
diff changeset
105 pass
178
11ff8cd93659 common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents: 145
diff changeset
106
11ff8cd93659 common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents: 145
diff changeset
107
218
30be583dbabc core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents: 193
diff changeset
108 class SymbolLabel(ButtonBehavior, BoxLayout):
30be583dbabc core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents: 193
diff changeset
109 symbol = properties.StringProperty("")
30be583dbabc core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents: 193
diff changeset
110 text = properties.StringProperty("")
30be583dbabc core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents: 193
diff changeset
111 color = properties.ListProperty(C.COLOR_SEC)
30be583dbabc core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents: 193
diff changeset
112 bold = properties.BooleanProperty(True)
30be583dbabc core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents: 193
diff changeset
113 symbol_wid = properties.ObjectProperty()
30be583dbabc core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents: 193
diff changeset
114 label = properties.ObjectProperty()
30be583dbabc core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents: 193
diff changeset
115
30be583dbabc core (common): new SymbolLabel class to have a clickable area with a symbol and a label next to it.
Goffi <goffi@goffi.org>
parents: 193
diff changeset
116
178
11ff8cd93659 common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents: 145
diff changeset
117 class ActionSymbol(Symbol):
11ff8cd93659 common: new ActionSymbol widget, which use a symbol to show an action
Goffi <goffi@goffi.org>
parents: 145
diff changeset
118 pass
179
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
119
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
120
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
121 class ActionIcon(BoxLayout):
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
122 plugin_info = properties.DictProperty()
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
123
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
124 def on_plugin_info(self, instance, plugin_info):
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
125 self.clear_widgets()
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
126 try:
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
127 symbol = plugin_info['icon_symbol']
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
128 except KeyError:
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
129 icon_src = plugin_info['icon_medium']
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
130 icon_wid = Image(source=icon_src, allow_stretch=True)
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
131 self.add_widget(icon_wid)
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
132 else:
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
133 icon_wid = ActionSymbol(symbol=symbol)
7177fe2d9725 common: new ActionIcon widget which display symbol or image icon according to what is specified in plugin_info
Goffi <goffi@goffi.org>
parents: 178
diff changeset
134 self.add_widget(icon_wid)