Mercurial > libervia-desktop-kivy
annotate cagou/core/cagou_main.py @ 282:1b835bcfa663
date update
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 25 Mar 2019 07:11:09 +0100 |
parents | ef77423ce500 |
children | ca4daced4638 |
rev | line source |
---|---|
6
85649eca9f9b
core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
1 #!/usr//bin/env python2 |
0 | 2 # -*- coding: utf-8 -*- |
3 | |
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
282 | 5 # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org) |
0 | 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 | |
14 | 21 from sat.core.i18n import _ |
119
1bbbe26846f4
buildozer: moved sat.conf in a specific dir (platform/android), so it's not used on desktop
Goffi <goffi@goffi.org>
parents:
112
diff
changeset
|
22 from . import kivy_hack |
48
028a98983e46
core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents:
44
diff
changeset
|
23 kivy_hack.do_hack() |
6
85649eca9f9b
core (logs): integrate Kivy logs with SàT:
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
24 from constants import Const as C |
0 | 25 from sat.core import log as logging |
26 log = logging.getLogger(__name__) | |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
27 from sat.core import exceptions |
0 | 28 from sat_frontends.quick_frontend.quick_app import QuickApp |
34
02acbb297a61
handler, widget: deleteWidget is now properly called when a QuickWidget is deleted
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
29 from sat_frontends.quick_frontend import quick_widgets |
43
12fdc7d1feb1
core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
30 from sat_frontends.quick_frontend import quick_chat |
48
028a98983e46
core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents:
44
diff
changeset
|
31 from sat_frontends.quick_frontend import quick_utils |
244
5bd94bc08f5c
plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
32 from sat_frontends.tools import jid |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
33 from sat.tools import config |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
34 from sat.tools.common import dynamic_import |
0 | 35 import kivy |
142 | 36 kivy.require('1.10.0') |
0 | 37 import kivy.support |
63 | 38 main_config = config.parseMainConf() |
39 bridge_name = config.getConfig(main_config, '', 'bridge', 'dbus') | |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
40 # FIXME: event loop is choosen according to bridge_name, a better way should be used |
63 | 41 if 'dbus' in bridge_name: |
42 kivy.support.install_gobject_iteration() | |
43 elif bridge_name in ('pb', 'embedded'): | |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
44 kivy.support.install_twisted_reactor() |
0 | 45 from kivy.app import App |
14 | 46 from kivy.lang import Builder |
29 | 47 from kivy import properties |
0 | 48 import xmlui |
49 from profile_manager import ProfileManager | |
29 | 50 from kivy.clock import Clock |
51 from kivy.uix.label import Label | |
9 | 52 from kivy.uix.boxlayout import BoxLayout |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
53 from kivy.uix.floatlayout import FloatLayout |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
54 from kivy.uix.screenmanager import (ScreenManager, Screen, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
55 FallOutTransition, RiseInTransition) |
29 | 56 from kivy.uix.dropdown import DropDown |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
57 from kivy.uix.behaviors import ButtonBehavior |
166
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
58 from kivy.core.window import Window |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
59 from kivy.animation import Animation |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
60 from kivy.metrics import dp |
11
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
61 from cagou_widget import CagouWidget |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
62 from . import widgets_handler |
29 | 63 from .common import IconButton |
86 | 64 from . import menu |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
65 from . import dialog |
14 | 66 from importlib import import_module |
9 | 67 import os.path |
14 | 68 import glob |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
69 import cagou.plugins |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
70 import cagou.kv |
61 | 71 from kivy import utils as kivy_utils |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
72 import sys |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
73 try: |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
74 from plyer import notification |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
75 except ImportError: |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
76 notification = None |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
77 log.warning(_(u"Can't import plyer, some features disabled")) |
131
36fc269e2a32
core: changed default background color to white
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
78 |
259
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
79 if kivy_utils.platform == "android": |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
80 import socket |
131
36fc269e2a32
core: changed default background color to white
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
81 |
36fc269e2a32
core: changed default background color to white
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
82 |
61 | 83 # FIXME: move to separate android module |
84 # sys.platform is "linux" on android by default | |
85 # so we change it to allow backend to detect android | |
86 sys.platform = "android" | |
87
17094a075fd2
core: use C.PLUGIN_EXT to know which plugin extension to use
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
87 C.PLUGIN_EXT = 'pyo' |
259
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
88 SOCKET_DIR = "/data/data/org.salutatoi.cagou/" |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
89 SOCKET_FILE = ".socket" |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
90 STATE_RUNNING = "running" |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
91 STATE_PAUSED = "paused" |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
92 STATE_STOPPED = "stopped" |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
93 |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
94 |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
95 # we want white background by default |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
96 Window.clearcolor = (1, 1, 1, 1) |
9 | 97 |
98 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
99 class NotifsIcon(IconButton): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
100 notifs = properties.ListProperty() |
29 | 101 |
102 def on_release(self): | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
103 callback, args, kwargs = self.notifs.pop(0) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
104 callback(*args, **kwargs) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
105 |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
106 def addNotif(self, callback, *args, **kwargs): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
107 self.notifs.append((callback, args, kwargs)) |
29 | 108 |
109 | |
110 class Note(Label): | |
111 title = properties.StringProperty() | |
112 message = properties.StringProperty() | |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
113 level = properties.OptionProperty(C.XMLUI_DATA_LVL_DEFAULT, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
114 options=list(C.XMLUI_DATA_LVLS)) |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
115 symbol = properties.StringProperty() |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
116 action = properties.ObjectProperty() |
29 | 117 |
118 | |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
119 class NoteDrop(ButtonBehavior, BoxLayout): |
208 | 120 title = properties.StringProperty() |
121 message = properties.StringProperty() | |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
122 level = properties.OptionProperty(C.XMLUI_DATA_LVL_DEFAULT, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
123 options=list(C.XMLUI_DATA_LVLS)) |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
124 symbol = properties.StringProperty() |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
125 action = properties.ObjectProperty() |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
126 |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
127 def on_press(self): |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
128 if self.action is not None: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
129 self.parent.parent.select(self.action) |
29 | 130 |
131 | |
132 class NotesDrop(DropDown): | |
133 clear_btn = properties.ObjectProperty() | |
134 | |
135 def __init__(self, notes): | |
136 super(NotesDrop, self).__init__() | |
137 self.notes = notes | |
138 | |
139 def open(self, widget): | |
140 self.clear_widgets() | |
141 for n in self.notes: | |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
142 kwargs = { |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
143 u'title': n.title, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
144 u'message': n.message, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
145 u'level': n.level |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
146 } |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
147 if n.symbol is not None: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
148 kwargs[u'symbol'] = n.symbol |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
149 if n.action is not None: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
150 kwargs[u'action'] = n.action |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
151 self.add_widget(NoteDrop(title=n.title, message=n.message, level=n.level, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
152 symbol=n.symbol, action=n.action)) |
29 | 153 self.add_widget(self.clear_btn) |
154 super(NotesDrop, self).open(widget) | |
155 | |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
156 def on_select(self, action_kwargs): |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
157 app = App.get_running_app() |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
158 app.host.doAction(**action_kwargs) |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
159 |
29 | 160 |
161 class RootHeadWidget(BoxLayout): | |
162 """Notifications widget""" | |
163 manager = properties.ObjectProperty() | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
164 notifs_icon = properties.ObjectProperty() |
29 | 165 notes = properties.ListProperty() |
172
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
166 HEIGHT = dp(35) |
29 | 167 |
168 def __init__(self): | |
169 super(RootHeadWidget, self).__init__() | |
170 self.notes_last = None | |
171 self.notes_event = None | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
172 self.notes_drop = NotesDrop(self.notes) |
29 | 173 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
174 def addNotif(self, callback, *args, **kwargs): |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
175 """add a notification with a callback attached |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
176 |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
177 when notification is pressed, callback is called |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
178 @param *args, **kwargs: arguments of callback |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
179 """ |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
180 self.notifs_icon.addNotif(callback, *args, **kwargs) |
29 | 181 |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
182 def addNote(self, title, message, level, symbol, action): |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
183 kwargs = { |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
184 u'title': title, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
185 u'message': message, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
186 u'level': level |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
187 } |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
188 if symbol is not None: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
189 kwargs[u'symbol'] = symbol |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
190 if action is not None: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
191 kwargs[u'action'] = action |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
192 note = Note(**kwargs) |
29 | 193 self.notes.append(note) |
194 if self.notes_event is None: | |
195 self.notes_event = Clock.schedule_interval(self._displayNextNote, 5) | |
196 self._displayNextNote() | |
197 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
198 def addNotifUI(self, ui): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
199 self.notifs_icon.addNotif(ui.show, force=True) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
200 |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
201 def addNotifWidget(self, widget): |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
202 app = App.get_running_app() |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
203 self.notifs_icon.addNotif(app.host.showExtraUI, widget=widget) |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
204 |
29 | 205 def _displayNextNote(self, dummy=None): |
206 screen = Screen() | |
207 try: | |
208 idx = self.notes.index(self.notes_last) + 1 | |
209 except ValueError: | |
210 idx = 0 | |
211 try: | |
212 note = self.notes_last = self.notes[idx] | |
213 except IndexError: | |
214 self.notes_event.cancel() | |
215 self.notes_event = None | |
216 else: | |
217 screen.add_widget(note) | |
218 self.manager.switch_to(screen) | |
219 | |
220 | |
86 | 221 class RootMenus(menu.MenusWidget): |
166
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
222 HEIGHT = dp(30) |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
223 |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
224 |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
225 class RootBody(BoxLayout): |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
226 pass |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
227 |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
228 |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
229 class CagouRootWidget(FloatLayout): |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
230 root_menus = properties.ObjectProperty() |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
231 root_body = properties.ObjectProperty |
9 | 232 |
29 | 233 def __init__(self, main_widget): |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
234 super(CagouRootWidget, self).__init__() |
29 | 235 # header |
172
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
236 self.head_widget = RootHeadWidget() |
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
237 self.root_body.add_widget(self.head_widget) |
29 | 238 # body |
239 self._manager = ScreenManager() | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
240 # main widgets |
29 | 241 main_screen = Screen(name='main') |
242 main_screen.add_widget(main_widget) | |
243 self._manager.add_widget(main_screen) | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
244 # backend XMLUI (popups, forms, etc) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
245 xmlui_screen = Screen(name='xmlui') |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
246 self._manager.add_widget(xmlui_screen) |
78 | 247 # extra (file chooser, audio record, etc) |
248 extra_screen = Screen(name='extra') | |
249 self._manager.add_widget(extra_screen) | |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
250 self.root_body.add_widget(self._manager) |
29 | 251 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
252 def changeWidget(self, widget, screen_name="main"): |
29 | 253 """change main widget""" |
52
647f32d0a004
core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
254 if self._manager.transition.is_active: |
647f32d0a004
core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
255 # FIXME: workaround for what seems a Kivy bug |
647f32d0a004
core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
256 # TODO: report this upstream |
647f32d0a004
core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
257 self._manager.transition.stop() |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
258 screen = self._manager.get_screen(screen_name) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
259 screen.clear_widgets() |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
260 screen.add_widget(widget) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
261 |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
262 def show(self, screen="main"): |
52
647f32d0a004
core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
263 if self._manager.transition.is_active: |
647f32d0a004
core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
264 # FIXME: workaround for what seems a Kivy bug |
647f32d0a004
core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
265 # TODO: report this upstream |
647f32d0a004
core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents:
51
diff
changeset
|
266 self._manager.transition.stop() |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
267 if self._manager.current == screen: |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
268 return |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
269 if screen == "main": |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
270 self._manager.transition = FallOutTransition() |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
271 else: |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
272 self._manager.transition = RiseInTransition() |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
273 self._manager.current = screen |
29 | 274 |
275 def newAction(self, handler, action_data, id_, security_limit, profile): | |
276 """Add a notification for an action""" | |
172
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
277 self.head_widget.addNotif(handler, action_data, id_, security_limit, profile) |
29 | 278 |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
279 def addNote(self, title, message, level, symbol, action): |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
280 self.head_widget.addNote(title, message, level, symbol, action) |
0 | 281 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
282 def addNotifUI(self, ui): |
172
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
283 self.head_widget.addNotifUI(ui) |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
284 |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
285 def addNotifWidget(self, widget): |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
286 self.head_widget.addNotifWidget(widget) |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
287 |
0 | 288 |
289 class CagouApp(App): | |
290 """Kivy App for Cagou""" | |
176
2cfef8fbfd4e
core: moved main colors to constants
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
291 c_prim = properties.ListProperty(C.COLOR_PRIM) |
2cfef8fbfd4e
core: moved main colors to constants
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
292 c_prim_light = properties.ListProperty(C.COLOR_PRIM_LIGHT) |
2cfef8fbfd4e
core: moved main colors to constants
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
293 c_prim_dark = properties.ListProperty(C.COLOR_PRIM_DARK) |
2cfef8fbfd4e
core: moved main colors to constants
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
294 c_sec = properties.ListProperty(C.COLOR_SEC) |
2cfef8fbfd4e
core: moved main colors to constants
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
295 c_sec_light = properties.ListProperty(C.COLOR_SEC_LIGHT) |
2cfef8fbfd4e
core: moved main colors to constants
Goffi <goffi@goffi.org>
parents:
174
diff
changeset
|
296 c_sec_dark = properties.ListProperty(C.COLOR_SEC_DARK) |
274 | 297 # we have to put those constants here and not in core/constants.py |
298 # because of the use of dp(), which would import Kivy too early | |
299 # and prevent the log hack | |
300 MARGIN_LEFT = MARGIN_RIGHT = dp(10) | |
0 | 301 |
152
b9fd83292fc4
core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents:
143
diff
changeset
|
302 def _install_settings_keys(self, window): |
b9fd83292fc4
core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents:
143
diff
changeset
|
303 # we don't want default Kivy's behaviour of displaying |
b9fd83292fc4
core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents:
143
diff
changeset
|
304 # a settings screen when pressing F1 or platform specific key |
b9fd83292fc4
core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents:
143
diff
changeset
|
305 return |
b9fd83292fc4
core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents:
143
diff
changeset
|
306 |
0 | 307 def build(self): |
143
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
308 Window.bind(on_keyboard=self.key_input) |
166
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
309 wid = CagouRootWidget(Label(text=u"Loading please wait")) |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
310 if sys.platform == 'android': |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
311 # we don't want menu on Android |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
312 wid.root_menus.height = 0 |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
313 return wid |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
314 |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
315 def showWidget(self): |
49
fd9cbf6ae663
core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents:
48
diff
changeset
|
316 self._profile_manager = ProfileManager() |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
317 self.root.changeWidget(self._profile_manager) |
0 | 318 |
31
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
319 def expand(self, path, *args, **kwargs): |
28
9f9532eb835f
core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
320 """expand path and replace known values |
9f9532eb835f
core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
321 |
32 | 322 useful in kv. Values which can be used: |
323 - {media}: media dir | |
31
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
324 @param path(unicode): path to expand |
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
325 @param *args: additional arguments used in format |
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
326 @param **kwargs: additional keyword arguments used in format |
28
9f9532eb835f
core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
327 """ |
31
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
328 return os.path.expanduser(path).format(*args, media=self.host.media_dir, **kwargs) |
28
9f9532eb835f
core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents:
25
diff
changeset
|
329 |
259
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
330 def initFrontendState(self): |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
331 """Init state to handle paused/stopped/running on mobile OSes""" |
75
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
332 if sys.platform == "android": |
259
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
333 # XXX: we use a separated socket instead of bridge because if we |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
334 # try to call a bridge method in on_pause method, the call data |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
335 # is not written before the actual pause |
259
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
336 s = self._frontend_status_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
337 s.connect(os.path.join(SOCKET_DIR, SOCKET_FILE)) |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
338 s.sendall(STATE_RUNNING) |
73
674b1fa3c945
core: use memory map on a file to indicate pause/resume status, so backend can now it
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
339 |
65
1c738621bc8d
core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
340 def on_pause(self): |
262
825e8c91b703
core: (de)activate sync flag when the frontend is being paused or resumed
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
341 self.host.sync = False |
259
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
342 self._frontend_status_socket.sendall(STATE_PAUSED) |
65
1c738621bc8d
core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
343 return True |
1c738621bc8d
core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
344 |
1c738621bc8d
core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
345 def on_resume(self): |
259
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
346 self._frontend_status_socket.sendall(STATE_RUNNING) |
262
825e8c91b703
core: (de)activate sync flag when the frontend is being paused or resumed
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
347 self.host.sync = True |
73
674b1fa3c945
core: use memory map on a file to indicate pause/resume status, so backend can now it
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
348 |
674b1fa3c945
core: use memory map on a file to indicate pause/resume status, so backend can now it
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
349 def on_stop(self): |
77
bc170ccca744
core: added forgotten platfom check in on_stop
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
350 if sys.platform == "android": |
259
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
351 self._frontend_status_socket.sendall(STATE_STOPPED) |
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
352 self._frontend_status_socket.close() |
65
1c738621bc8d
core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
353 |
143
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
354 def key_input(self, window, key, scancode, codepoint, modifier): |
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
355 if key == 27: |
166
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
356 # we disable [esc] handling, because default action is to quit app |
143
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
357 return True |
165 | 358 elif key == 292: |
166
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
359 # F11: full screen |
165 | 360 if not Window.fullscreen: |
361 window.fullscreen = 'auto' | |
362 else: | |
363 window.fullscreen = False | |
364 return True | |
166
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
365 elif key == 109 and modifier == ['alt']: |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
366 # M-m we hide/show menu |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
367 menu = self.root.root_menus |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
368 if menu.height: |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
369 Animation(height=0, duration=0.3).start(menu) |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
370 else: |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
371 Animation(height=menu.HEIGHT, duration=0.3).start(menu) |
37220459e93d
core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
372 return True |
172
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
373 elif key == 110 and modifier == ['alt']: |
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
374 # M-n we hide/show notifications |
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
375 head = self.root.head_widget |
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
376 if head.height: |
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
377 Animation(height=0, opacity=0, duration=0.3).start(head) |
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
378 else: |
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
379 Animation(height=head.HEIGHT, opacity=1, duration=0.3).start(head) |
7103655647aa
core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents:
166
diff
changeset
|
380 return True |
143
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
381 else: |
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
382 return False |
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
383 |
0 | 384 |
385 class Cagou(QuickApp): | |
386 MB_HANDLE = False | |
265
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
264
diff
changeset
|
387 AUTO_RESYNC = False |
0 | 388 |
389 def __init__(self): | |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
390 if bridge_name == 'embedded': |
63 | 391 from sat.core import sat_main |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
392 self.sat = sat_main.SAT() |
64
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
393 if sys.platform == 'android': |
141
8a0019ce3632
core (android): service is now launched using pyjnius, as recommended in doc
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
394 from jnius import autoclass |
240 | 395 service = autoclass('org.salutatoi.cagou.ServiceBackend') |
141
8a0019ce3632
core (android): service is now launched using pyjnius, as recommended in doc
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
396 mActivity = autoclass('org.kivy.android.PythonActivity').mActivity |
8a0019ce3632
core (android): service is now launched using pyjnius, as recommended in doc
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
397 argument = '' |
8a0019ce3632
core (android): service is now launched using pyjnius, as recommended in doc
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
398 service.start(mActivity, argument) |
64
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
399 self.service = service |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
400 |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
401 bridge_module = dynamic_import.bridge(bridge_name, 'sat_frontends.bridge') |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
402 if bridge_module is None: |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
403 log.error(u"Can't import {} bridge".format(bridge_name)) |
72
1a324c682d8a
core: use onBridgeConnected and exit code 3 when bridge can't be imported
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
404 sys.exit(3) |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
405 else: |
72
1a324c682d8a
core: use onBridgeConnected and exit code 3 when bridge can't be imported
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
406 log.debug(u"Loading {} bridge".format(bridge_name)) |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
407 super(Cagou, self).__init__(bridge_factory=bridge_module.Bridge, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
408 xmlui=xmlui, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
409 check_options=quick_utils.check_options, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
410 connect_bridge=False) |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
411 self._import_kv() |
0 | 412 self.app = CagouApp() |
29 | 413 self.app.host = self |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
414 self.media_dir = self.app.media_dir = config.getConfig(main_config, '', |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
415 'media_dir') |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
416 self.downloads_dir = self.app.downloads_dir = config.getConfig(main_config, '', |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
417 'downloads_dir') |
188
0abd24ab81b1
core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
418 if not os.path.exists(self.downloads_dir): |
0abd24ab81b1
core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
419 try: |
0abd24ab81b1
core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
420 os.makedirs(self.downloads_dir) |
0abd24ab81b1
core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
421 except OSError as e: |
0abd24ab81b1
core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
422 log.warnings(_(u"Can't create downloads dir: {reason}").format(reason=e)) |
25
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
423 self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png") |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
424 self.app.icon = os.path.join(self.media_dir, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
425 "icons/muchoslava/png/cagou_profil_bleu_96.png") |
86 | 426 self._plg_wids = [] # main widgets plugins |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
427 self._plg_wids_transfer = [] # transfer widgets plugins |
14 | 428 self._import_plugins() |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
429 self._visible_widgets = {} # visible widgets by classes |
246 | 430 self.version = C.APP_VERSION # will be replaced by getVersion() |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
431 |
281
ef77423ce500
core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents:
280
diff
changeset
|
432 self.tls_validation = not C.bool(config.getConfig(main_config, |
ef77423ce500
core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents:
280
diff
changeset
|
433 C.CONFIG_SECTION, |
ef77423ce500
core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents:
280
diff
changeset
|
434 'no_certificate_validation', |
ef77423ce500
core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents:
280
diff
changeset
|
435 C.BOOL_FALSE)) |
ef77423ce500
core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents:
280
diff
changeset
|
436 if not self.tls_validation: |
280
b0461363bc65
core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
437 from cagou.core import patches |
b0461363bc65
core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
438 patches.apply() |
b0461363bc65
core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
439 log.warning(u"SSL certificate validation is disabled, this is unsecure!") |
b0461363bc65
core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
276
diff
changeset
|
440 |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
441 @property |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
442 def visible_widgets(self): |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
443 for w_list in self._visible_widgets.itervalues(): |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
444 for w in w_list: |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
445 yield w |
0 | 446 |
265
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
264
diff
changeset
|
447 @QuickApp.sync.setter |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
264
diff
changeset
|
448 def sync(self, state): |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
264
diff
changeset
|
449 QuickApp.sync.fset(self, state) |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
264
diff
changeset
|
450 # widget are resynchronised in onVisible event, |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
264
diff
changeset
|
451 # so we must call resync for widgets which are already visible |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
264
diff
changeset
|
452 if state: |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
264
diff
changeset
|
453 for w in self.visible_widgets: |
272
c4990a7d5dbd
core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
454 try: |
c4990a7d5dbd
core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
455 resync = w.resync |
c4990a7d5dbd
core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
456 except AttributeError: |
c4990a7d5dbd
core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
457 pass |
c4990a7d5dbd
core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
458 else: |
c4990a7d5dbd
core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents:
267
diff
changeset
|
459 resync() |
265
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
264
diff
changeset
|
460 |
72
1a324c682d8a
core: use onBridgeConnected and exit code 3 when bridge can't be imported
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
461 def onBridgeConnected(self): |
189
a91abcd6d9a5
core: call QuickApp.onBridgeConnected (so ns_map is filled)
Goffi <goffi@goffi.org>
parents:
188
diff
changeset
|
462 super(Cagou, self).onBridgeConnected() |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
463 self.registerSignal("otrState", iface="plugin") |
63 | 464 self.bridge.getReady(self.onBackendReady) |
465 | |
64
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
466 def _bridgeEb(self, failure): |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
467 if bridge_name == "pb" and sys.platform == "android": |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
468 try: |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
469 self.retried += 1 |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
470 except AttributeError: |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
471 self.retried = 1 |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
472 from twisted.internet.error import ConnectionRefusedError |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
473 if failure.check(ConnectionRefusedError) and self.retried < 100: |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
474 if self.retried % 20 == 0: |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
475 log.debug("backend not ready, retrying ({})".format(self.retried)) |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
476 Clock.schedule_once(lambda dummy: self.connectBridge(), 0.05) |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
477 return |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
478 super(Cagou, self)._bridgeEb(failure) |
8e16abcadbb8
core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents:
63
diff
changeset
|
479 |
0 | 480 def run(self): |
63 | 481 self.connectBridge() |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
482 self.app.bind(on_stop=self.onStop) |
0 | 483 self.app.run() |
484 | |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
485 def onStop(self, obj): |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
486 try: |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
487 sat_instance = self.sat |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
488 except AttributeError: |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
489 pass |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
490 else: |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
491 sat_instance.stopService() |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
492 |
246 | 493 def _getVersionCb(self, version): |
494 self.version = version | |
495 | |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
496 def onBackendReady(self): |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
497 self.app.showWidget() |
246 | 498 self.bridge.getVersion(callback=self._getVersionCb) |
259
4601793b0dee
core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents:
250
diff
changeset
|
499 self.app.initFrontendState() |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
500 self.postInit() |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
501 |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
502 def postInit(self, dummy=None): |
276 | 503 # FIXME: resize doesn't work with SDL2 on android, so we use below_target for now |
61 | 504 self.app.root_window.softinput_mode = "below_target" |
49
fd9cbf6ae663
core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents:
48
diff
changeset
|
505 profile_manager = self.app._profile_manager |
fd9cbf6ae663
core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents:
48
diff
changeset
|
506 del self.app._profile_manager |
fd9cbf6ae663
core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents:
48
diff
changeset
|
507 super(Cagou, self).postInit(profile_manager) |
fd9cbf6ae663
core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents:
48
diff
changeset
|
508 |
86 | 509 def _defaultFactoryMain(self, plugin_info, target, profiles): |
510 """default factory used to create main widgets instances | |
511 | |
512 used when PLUGIN_INFO["factory"] is not set | |
513 @param plugin_info(dict): plugin datas | |
514 @param target: QuickWidget target | |
515 @param profiles(iterable): list of profiles | |
516 """ | |
14 | 517 main_cls = plugin_info['main'] |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
518 return self.widgets.getOrCreateWidget(main_cls, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
519 target, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
520 on_new_widget=None, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
521 profiles=iter(self.profiles)) |
14 | 522 |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
523 def _defaultFactoryTransfer(self, plugin_info, callback, cancel_cb, profiles): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
524 """default factory used to create transfer widgets instances |
86 | 525 |
526 @param plugin_info(dict): plugin datas | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
527 @param callback(callable): method to call with path to file to transfer |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
528 @param cancel_cb(callable): call when transfer is cancelled |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
529 transfer widget must be used as first argument |
86 | 530 @param profiles(iterable): list of profiles |
531 None if not specified | |
532 """ | |
533 main_cls = plugin_info['main'] | |
534 return main_cls(callback=callback, cancel_cb=cancel_cb) | |
535 | |
29 | 536 ## plugins & kv import ## |
537 | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
538 def _import_kv(self): |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
539 """import all kv files in cagou.kv""" |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
540 path = os.path.dirname(cagou.kv.__file__) |
130
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
541 kv_files = glob.glob(os.path.join(path, "*.kv")) |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
542 # we want to be sure that base.kv is loaded first |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
543 # as it override some Kivy widgets properties |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
544 for kv_file in kv_files: |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
545 if kv_file.endswith('base.kv'): |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
546 kv_files.remove(kv_file) |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
547 kv_files.insert(0, kv_file) |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
548 break |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
549 else: |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
550 raise exceptions.InternalError("base.kv is missing") |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
551 |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
552 for kv_file in kv_files: |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
553 Builder.load_file(kv_file) |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
554 log.debug(u"kv file {} loaded".format(kv_file)) |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
555 |
14 | 556 def _import_plugins(self): |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
557 """import all plugins""" |
14 | 558 self.default_wid = None |
87
17094a075fd2
core: use C.PLUGIN_EXT to know which plugin extension to use
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
559 plugins_path = os.path.dirname(cagou.plugins.__file__) |
17094a075fd2
core: use C.PLUGIN_EXT to know which plugin extension to use
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
560 plugin_glob = u"plugin*." + C.PLUGIN_EXT |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
561 plug_lst = [os.path.splitext(p)[0] for p in |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
562 map(os.path.basename, glob.glob(os.path.join(plugins_path, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
563 plugin_glob)))] |
61 | 564 |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
565 imported_names_main = set() # used to avoid loading 2 times |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
566 # plugin with same import name |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
567 imported_names_transfer = set() |
14 | 568 for plug in plug_lst: |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
569 plugin_path = 'cagou.plugins.' + plug |
86 | 570 |
571 # we get type from plugin name | |
572 suff = plug[7:] | |
573 if u'_' not in suff: | |
574 log.error(u"invalid plugin name: {}, skipping".format(plug)) | |
575 continue | |
576 plugin_type = suff[:suff.find(u'_')] | |
577 | |
578 # and select the variable to use according to type | |
579 if plugin_type == C.PLUG_TYPE_WID: | |
580 imported_names = imported_names_main | |
581 default_factory = self._defaultFactoryMain | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
582 elif plugin_type == C.PLUG_TYPE_TRANSFER: |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
583 imported_names = imported_names_transfer |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
584 default_factory = self._defaultFactoryTransfer |
86 | 585 else: |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
586 log.error(u"unknown plugin type {type_} for plugin {file_}, skipping" |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
587 .format( |
86 | 588 type_ = plugin_type, |
589 file_ = plug | |
590 )) | |
591 continue | |
592 plugins_set = self._getPluginsSet(plugin_type) | |
593 | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
594 mod = import_module(plugin_path) |
14 | 595 try: |
596 plugin_info = mod.PLUGIN_INFO | |
597 except AttributeError: | |
598 plugin_info = {} | |
599 | |
86 | 600 plugin_info['plugin_file'] = plug |
601 plugin_info['plugin_type'] = plugin_type | |
602 | |
603 if 'platforms' in plugin_info: | |
604 if sys.platform not in plugin_info['platforms']: | |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
605 log.info(u"{plugin_file} is not used on this platform, skipping" |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
606 .format(**plugin_info)) |
86 | 607 continue |
608 | |
14 | 609 # import name is used to differentiate plugins |
610 if 'import_name' not in plugin_info: | |
611 plugin_info['import_name'] = plug | |
86 | 612 if plugin_info['import_name'] in imported_names: |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
613 log.warning(_(u"there is already a plugin named {}, " |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
614 u"ignoring new one").format(plugin_info['import_name'])) |
14 | 615 continue |
616 if plugin_info['import_name'] == C.WID_SELECTOR: | |
86 | 617 if plugin_type != C.PLUG_TYPE_WID: |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
618 log.error(u"{import_name} import name can only be used with {type_} " |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
619 u"type, skipping {name}".format(type_=C.PLUG_TYPE_WID, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
620 **plugin_info)) |
86 | 621 continue |
14 | 622 # if WidgetSelector exists, it will be our default widget |
623 self.default_wid = plugin_info | |
624 | |
625 # we want everything optional, so we use plugin file name | |
626 # if actual name is not found | |
627 if 'name' not in plugin_info: | |
86 | 628 name_start = 8 + len(plugin_type) |
629 plugin_info['name'] = plug[name_start:] | |
14 | 630 |
631 # we need to load the kv file | |
632 if 'kv_file' not in plugin_info: | |
633 plugin_info['kv_file'] = u'{}.kv'.format(plug) | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
634 kv_path = os.path.join(plugins_path, plugin_info['kv_file']) |
89
d249df379fa3
core: kv files are not mandatory anymore for plugins
Goffi <goffi@goffi.org>
parents:
87
diff
changeset
|
635 if not os.path.exists(kv_path): |
d249df379fa3
core: kv files are not mandatory anymore for plugins
Goffi <goffi@goffi.org>
parents:
87
diff
changeset
|
636 log.debug(u"no kv found for {plugin_file}".format(**plugin_info)) |
d249df379fa3
core: kv files are not mandatory anymore for plugins
Goffi <goffi@goffi.org>
parents:
87
diff
changeset
|
637 else: |
d249df379fa3
core: kv files are not mandatory anymore for plugins
Goffi <goffi@goffi.org>
parents:
87
diff
changeset
|
638 Builder.load_file(kv_path) |
14 | 639 |
640 # what is the main class ? | |
641 main_cls = getattr(mod, plugin_info['main']) | |
642 plugin_info['main'] = main_cls | |
643 | |
644 # factory is used to create the instance | |
645 # if not found, we use a defaut one with getOrCreateWidget | |
646 if 'factory' not in plugin_info: | |
86 | 647 plugin_info['factory'] = default_factory |
14 | 648 |
25
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
649 # icons |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
650 for size in ('small', 'medium'): |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
651 key = u'icon_{}'.format(size) |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
652 try: |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
653 path = plugin_info[key] |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
654 except KeyError: |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
655 path = C.DEFAULT_WIDGET_ICON.format(media=self.media_dir) |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
656 else: |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
657 path = path.format(media=self.media_dir) |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
658 if not os.path.isfile(path): |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
659 path = C.DEFAULT_WIDGET_ICON.format(media=self.media_dir) |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
660 plugin_info[key] = path |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
661 |
86 | 662 plugins_set.append(plugin_info) |
14 | 663 if not self._plg_wids: |
664 log.error(_(u"no widget plugin found")) | |
665 return | |
666 | |
667 # we want widgets sorted by names | |
668 self._plg_wids.sort(key=lambda p: p['name'].lower()) | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
669 self._plg_wids_transfer.sort(key=lambda p: p['name'].lower()) |
14 | 670 |
671 if self.default_wid is None: | |
672 # we have no selector widget, we use the first widget as default | |
673 self.default_wid = self._plg_wids[0] | |
674 | |
86 | 675 def _getPluginsSet(self, type_): |
676 if type_ == C.PLUG_TYPE_WID: | |
677 return self._plg_wids | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
678 elif type_ == C.PLUG_TYPE_TRANSFER: |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
679 return self._plg_wids_transfer |
86 | 680 else: |
681 raise KeyError(u"{} plugin type is unknown".format(type_)) | |
682 | |
683 def getPluggedWidgets(self, type_=C.PLUG_TYPE_WID, except_cls=None): | |
14 | 684 """get available widgets plugin infos |
685 | |
86 | 686 @param type_(unicode): type of widgets to get |
687 one of C.PLUG_TYPE_* constant | |
14 | 688 @param except_cls(None, class): if not None, |
689 widgets from this class will be excluded | |
41
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
690 @return (iter[dict]): available widgets plugin infos |
14 | 691 """ |
86 | 692 plugins_set = self._getPluginsSet(type_) |
693 for plugin_data in plugins_set: | |
19
c58b522607f4
main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
694 if plugin_data['main'] == except_cls: |
c58b522607f4
main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
695 continue |
c58b522607f4
main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
696 yield plugin_data |
14 | 697 |
86 | 698 def getPluginInfo(self, type_=C.PLUG_TYPE_WID, **kwargs): |
41
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
699 """get first plugin info corresponding to filters |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
700 |
86 | 701 @param type_(unicode): type of widgets to get |
702 one of C.PLUG_TYPE_* constant | |
41
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
703 @param **kwargs: filter(s) to use, each key present here must also |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
704 exist and be of the same value in requested plugin info |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
705 @return (dict, None): found plugin info or None |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
706 """ |
86 | 707 plugins_set = self._getPluginsSet(type_) |
708 for plugin_info in plugins_set: | |
41
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
709 for k, w in kwargs.iteritems(): |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
710 try: |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
711 if plugin_info[k] != w: |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
712 continue |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
713 except KeyError: |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
714 continue |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
715 return plugin_info |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
716 |
29 | 717 ## widgets handling |
9 | 718 |
43
12fdc7d1feb1
core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
719 def newWidget(self, widget): |
12fdc7d1feb1
core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
720 log.debug(u"new widget created: {}".format(widget)) |
12fdc7d1feb1
core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
721 if isinstance(widget, quick_chat.QuickChat) and widget.type == C.CHAT_GROUP: |
12fdc7d1feb1
core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
722 self.addNote(u"", _(u"room {} has been joined").format(widget.target)) |
12fdc7d1feb1
core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
723 |
11
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
724 def switchWidget(self, old, new): |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
725 """Replace old widget by new one |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
726 |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
727 old(CagouWidgetn None): CagouWidget instance or a child |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
728 None to select automatically widget to switch |
11
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
729 new(CagouWidget): new widget instance |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
730 """ |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
731 if old is None: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
732 old = self.getWidgetToSwitch() |
14 | 733 to_change = None |
734 if isinstance(old, CagouWidget): | |
735 to_change = old | |
736 else: | |
737 for w in old.walk_reverse(): | |
738 if isinstance(w, CagouWidget): | |
739 to_change = w | |
740 break | |
741 | |
742 if to_change is None: | |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
743 raise exceptions.InternalError(u"no CagouWidget found when " |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
744 u"trying to switch widget") |
154 | 745 |
746 wrapper = to_change.parent | |
747 while wrapper is not None and not(isinstance(wrapper, widgets_handler.WHWrapper)): | |
748 wrapper = wrapper.parent | |
749 | |
750 if wrapper is None: | |
751 raise exceptions.InternalError(u"no wrapper found") | |
752 | |
753 wrapper.changeWidget(new) | |
249
5d69e4cab925
core: when switching to a new widget, it becomes the selected one.
Goffi <goffi@goffi.org>
parents:
248
diff
changeset
|
754 self.selected_widget = new |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
755 |
248
b6e33b35538b
core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
756 def _addVisibleWidget(self, widget): |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
757 """declare a widget visible |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
758 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
759 for internal use only! |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
760 """ |
248
b6e33b35538b
core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
761 assert isinstance(widget, CagouWidget) |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
762 self._visible_widgets.setdefault(widget.__class__, []).append(widget) |
264
3e11b5d923e2
core: call new methods onVisible and onNotVisible when a widget is displayed or hidden + fixed a deletion bug on _removeVisibleWidget
Goffi <goffi@goffi.org>
parents:
262
diff
changeset
|
763 widget.onVisible() |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
764 |
248
b6e33b35538b
core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
765 def _removeVisibleWidget(self, widget): |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
766 """declare a widget not visible anymore |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
767 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
768 for internal use only! |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
769 """ |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
770 self._visible_widgets[widget.__class__].remove(widget) |
264
3e11b5d923e2
core: call new methods onVisible and onNotVisible when a widget is displayed or hidden + fixed a deletion bug on _removeVisibleWidget
Goffi <goffi@goffi.org>
parents:
262
diff
changeset
|
771 if isinstance(widget, CagouWidget): |
3e11b5d923e2
core: call new methods onVisible and onNotVisible when a widget is displayed or hidden + fixed a deletion bug on _removeVisibleWidget
Goffi <goffi@goffi.org>
parents:
262
diff
changeset
|
772 widget.onNotVisible() |
3e11b5d923e2
core: call new methods onVisible and onNotVisible when a widget is displayed or hidden + fixed a deletion bug on _removeVisibleWidget
Goffi <goffi@goffi.org>
parents:
262
diff
changeset
|
773 if isinstance(widget, quick_widgets.QuickWidget): |
248
b6e33b35538b
core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
774 self.widgets.deleteWidget(widget) |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
775 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
776 def getVisibleList(self, cls): |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
777 """get list of visible widgets for a given class |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
778 |
248
b6e33b35538b
core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
779 @param cls(type): type of widgets to get |
b6e33b35538b
core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents:
247
diff
changeset
|
780 @return (list[type]): visible widgets of this class |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
781 """ |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
782 try: |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
783 return self._visible_widgets[cls] |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
784 except KeyError: |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
785 return [] |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
786 |
260
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
787 def deleteUnusedWidgetInstances(self, widget): |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
788 """Delete instance of this widget without parent |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
789 |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
790 @param widget(quick_widgets.QuickWidget): reference widget |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
791 other instance of this widget will be deleted if they have no parent |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
792 """ |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
793 # FIXME: unused for now |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
794 to_delete = [] |
267
896f78760b63
core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
795 if isinstance(widget, quick_widgets.QuickWidget): |
896f78760b63
core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
796 for w in self.widgets.getWidgetInstances(widget): |
896f78760b63
core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
797 if w.parent is None and w != widget: |
896f78760b63
core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
798 to_delete.append(w) |
896f78760b63
core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
799 for w in to_delete: |
896f78760b63
core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
800 log.debug(u"cleaning widget: {wid}".format(wid=w)) |
896f78760b63
core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
801 self.widgets.deleteWidget(w) |
260
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
802 |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
803 def getOrClone(self, widget): |
260
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
804 """Get a QuickWidget if it has not parent set else clone it |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
805 |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
806 if an other instance of this widget exist without parent, it will be used. |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
807 """ |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
808 if widget.parent is None: |
260
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
809 self.deleteUnusedWidgetInstances(widget) |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
810 return widget |
260
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
811 for w in self.widgets.getWidgetInstances(widget): |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
812 if w.parent is None: |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
813 self.deleteUnusedWidgetInstances(w) |
145c29b5f2b5
core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents:
259
diff
changeset
|
814 return w |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
815 targets = list(widget.targets) |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
816 w = self.widgets.getOrCreateWidget(widget.__class__, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
817 targets[0], |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
818 on_new_widget=None, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
819 on_existing_widget=C.WIDGET_RECREATE, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
820 profiles=widget.profiles) |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
821 for t in targets[1:]: |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
822 w.addTarget(t) |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
823 return w |
29 | 824 |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
825 def getWidgetToSwitch(self): |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
826 """Choose best candidate when we need to switch widget and old is not specified |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
827 |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
828 @return (CagouWidget): widget to switch |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
829 """ |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
830 if self.selected_widget is not None: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
831 return self.selected_widget |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
832 # no widget is selected we check if we have any default widget |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
833 default_cls = self.default_wid['main'] |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
834 for w in self.visible_widgets: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
835 if isinstance(w, default_cls): |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
836 return w |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
837 |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
838 # no default widget found, we return the first widget |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
839 return next(iter(self.visible_widgets)) |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
840 |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
841 def doAction(self, action, target, profiles): |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
842 """Launch an action handler by a plugin |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
843 |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
844 @param action(unicode): action to do, can be: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
845 - chat: open a chat widget |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
846 @param target(unicode): target of the action |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
847 @param profiles(list[unicode]): profiles to use |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
848 """ |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
849 try: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
850 # FIXME: Q&D way to get chat plugin, should be replaced by a clean method |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
851 # in host |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
852 plg_infos = [p for p in self.getPluggedWidgets() |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
853 if action in p['import_name']][0] |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
854 except IndexError: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
855 log.warning(u"No plugin widget found to do {action}".format(action=action)) |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
856 else: |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
857 factory = plg_infos['factory'] |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
858 self.switchWidget(None, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
859 factory(plg_infos, target=target, profiles=profiles)) |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
860 |
51 | 861 ## menus ## |
862 | |
112
d654bdfeb404
core: changes menu bridge call, to follow backend
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
863 def _menusGetCb(self, backend_menus): |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
864 main_menu = self.app.root.root_menus |
51 | 865 self.menus.addMenus(backend_menus) |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
866 self.menus.addMenu(C.MENU_GLOBAL, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
867 (_(u"Help"), _(u"About")), |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
868 callback=main_menu.onAbout) |
51 | 869 main_menu.update(C.MENU_GLOBAL) |
870 | |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
871 ## bridge handlers ## |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
872 |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
873 def otrStateHandler(self, state, dest_jid, profile): |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
874 """OTR state has changed for on destinee""" |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
875 # XXX: this method could be in QuickApp but it's here as |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
876 # it's only used by Cagou so far |
244
5bd94bc08f5c
plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
877 dest_jid = jid.JID(dest_jid) |
5bd94bc08f5c
plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
878 bare_jid = dest_jid.bare |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
879 for widget in self.widgets.getWidgets(quick_chat.QuickChat, profiles=(profile,)): |
244
5bd94bc08f5c
plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
880 if widget.type == C.CHAT_ONE2ONE and widget.target == bare_jid: |
5bd94bc08f5c
plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents:
240
diff
changeset
|
881 widget.onOTRState(state, dest_jid, profile) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
882 |
266
b3f97729e983
core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
883 def _debugHandler(self, action, parameters, profile): |
b3f97729e983
core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
884 if action == u"visible_widgets_dump": |
b3f97729e983
core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
885 from pprint import pformat |
b3f97729e983
core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
886 log.info(u"Visible widgets dump:\n{data}".format( |
b3f97729e983
core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
887 data=pformat(self._visible_widgets))) |
b3f97729e983
core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
888 else: |
b3f97729e983
core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
889 return super(Cagou, self)._debugHandler(action, parameters, profile) |
b3f97729e983
core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents:
265
diff
changeset
|
890 |
29 | 891 ## misc ## |
892 | |
893 def plugging_profiles(self): | |
154 | 894 self.app.root.changeWidget(widgets_handler.WidgetsHandler()) |
112
d654bdfeb404
core: changes menu bridge call, to follow backend
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
895 self.bridge.menusGet("", C.NO_SECURITY_LIMIT, callback=self._menusGetCb) |
29 | 896 |
897 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE): | |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
898 log.info(u"Profile presence status set to {show}/{status}".format(show=show, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
899 status=status)) |
29 | 900 |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
901 def errback(self, failure_, title=_('error'), |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
902 message=_(u'error while processing: {msg}')): |
190
33ac2d2ce5d7
core: new errback method which can be use as a generic way to show error as notes
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
903 self.addNote(title, message.format(msg=failure_), level=C.XMLUI_DATA_LVL_WARNING) |
33ac2d2ce5d7
core: new errback method which can be use as a generic way to show error as notes
Goffi <goffi@goffi.org>
parents:
189
diff
changeset
|
904 |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
905 def addNote(self, title, message, level=C.XMLUI_DATA_LVL_INFO, symbol=None, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
906 action=None): |
29 | 907 """add a note (message which disappear) to root widget's header""" |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
249
diff
changeset
|
908 self.app.root.addNote(title, message, level, symbol, action) |
29 | 909 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
910 def addNotifUI(self, ui): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
911 """add a notification with a XMLUI attached |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
912 |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
913 @param ui(xmlui.XMLUIPanel): XMLUI instance to show when notification is selected |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
914 """ |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
915 self.app.root.addNotifUI(ui) |
29 | 916 |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
917 def addNotifWidget(self, widget): |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
918 """add a notification with a Kivy widget attached |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
919 |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
920 @param widget(kivy.uix.Widget): widget to attach to notification |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
921 """ |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
922 self.app.root.addNotifWidget(widget) |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
923 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
924 def showUI(self, ui): |
78 | 925 """show a XMLUI""" |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
926 self.app.root.changeWidget(ui, "xmlui") |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
927 self.app.root.show("xmlui") |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
928 |
78 | 929 def showExtraUI(self, widget): |
930 """show any extra widget""" | |
931 self.app.root.changeWidget(widget, "extra") | |
932 self.app.root.show("extra") | |
933 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
934 def closeUI(self): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
935 self.app.root.show() |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
936 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
937 def getDefaultAvatar(self, entity=None): |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
938 return self.app.default_avatar |
61 | 939 |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
940 def _dialog_cb(self, cb, *args, **kwargs): |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
941 """generic dialog callback |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
942 |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
943 close dialog then call the callback with given arguments |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
944 """ |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
945 def callback(): |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
946 self.closeUI() |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
947 cb(*args, **kwargs) |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
948 return callback |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
949 |
61 | 950 def showDialog(self, message, title, type="info", answer_cb=None, answer_data=None): |
220
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
951 if type in ('info', 'warning', 'error'): |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
952 self.addNote(title, message, type) |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
953 elif type == "yes/no": |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
954 wid = dialog.ConfirmDialog(title=title, message=message, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
955 yes_cb=self._dialog_cb(answer_cb, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
956 True, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
957 answer_data), |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
958 no_cb=self._dialog_cb(answer_cb, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
959 False, |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
960 answer_data) |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
961 ) |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
962 self.addNotifWidget(wid) |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
963 else: |
24f8ab7c08be
core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents:
208
diff
changeset
|
964 log.warning(_(u"unknown dialog type: {dialog_type}").format(dialog_type=type)) |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
965 |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
966 |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
967 def desktop_notif(self, message, title=u'', duration=5000): |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
968 if notification is not None: |
229
ab523cc967bb
core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
969 try: |
ab523cc967bb
core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
970 notification.notify(title=title, |
ab523cc967bb
core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
971 message=message, |
ab523cc967bb
core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
972 app_name=C.APP_NAME, |
ab523cc967bb
core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
973 app_icon=self.app.icon, |
ab523cc967bb
core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
974 timeout = duration) |
ab523cc967bb
core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
975 except Exception as e: |
ab523cc967bb
core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
976 log.warning(_(u"Can't use notifications, disabling: {msg}").format( |
ab523cc967bb
core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
977 msg = e)) |
ab523cc967bb
core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
978 global notification |
ab523cc967bb
core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
979 notification = None |