Mercurial > libervia-desktop-kivy
annotate cagou/core/cagou_main.py @ 143:05d602be0120
core: [esc] key handling is disabled (for now)
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 13 Apr 2018 19:29:35 +0200 |
parents | d276cfec38e8 |
children | b9fd83292fc4 |
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 | |
126 | 5 # Copyright (C) 2016-2018 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 |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
32 from sat.tools import config |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
33 from sat.tools.common import dynamic_import |
0 | 34 import kivy |
142 | 35 kivy.require('1.10.0') |
0 | 36 import kivy.support |
63 | 37 main_config = config.parseMainConf() |
38 bridge_name = config.getConfig(main_config, '', 'bridge', 'dbus') | |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
39 # FIXME: event loop is choosen according to bridge_name, a better way should be used |
63 | 40 if 'dbus' in bridge_name: |
41 kivy.support.install_gobject_iteration() | |
42 elif bridge_name in ('pb', 'embedded'): | |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
43 kivy.support.install_twisted_reactor() |
0 | 44 from kivy.app import App |
14 | 45 from kivy.lang import Builder |
29 | 46 from kivy import properties |
0 | 47 import xmlui |
48 from profile_manager import ProfileManager | |
13 | 49 from widgets_handler import WidgetsHandler |
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 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
54 from kivy.uix.screenmanager import ScreenManager, Screen, FallOutTransition, RiseInTransition |
29 | 55 from kivy.uix.dropdown import DropDown |
11
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
56 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
|
57 from . import widgets_handler |
29 | 58 from .common import IconButton |
86 | 59 from . import menu |
14 | 60 from importlib import import_module |
9 | 61 import os.path |
14 | 62 import glob |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
63 import cagou.plugins |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
64 import cagou.kv |
61 | 65 from kivy import utils as kivy_utils |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
66 import sys |
131
36fc269e2a32
core: changed default background color to white
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
67 from kivy.core.window import Window |
36fc269e2a32
core: changed default background color to white
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
68 |
36fc269e2a32
core: changed default background color to white
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
69 # we want white background by default |
36fc269e2a32
core: changed default background color to white
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
70 Window.clearcolor = (1, 1, 1, 1) |
36fc269e2a32
core: changed default background color to white
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
71 |
36fc269e2a32
core: changed default background color to white
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
72 |
61 | 73 if kivy_utils.platform == "android": |
74 # FIXME: move to separate android module | |
75 # sys.platform is "linux" on android by default | |
76 # so we change it to allow backend to detect android | |
77 sys.platform = "android" | |
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
|
78 import mmap |
87
17094a075fd2
core: use C.PLUGIN_EXT to know which plugin extension to use
Goffi <goffi@goffi.org>
parents:
86
diff
changeset
|
79 C.PLUGIN_EXT = 'pyo' |
9 | 80 |
81 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
82 class NotifsIcon(IconButton): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
83 notifs = properties.ListProperty() |
29 | 84 |
85 def on_release(self): | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
86 callback, args, kwargs = self.notifs.pop(0) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
87 callback(*args, **kwargs) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
88 |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
89 def addNotif(self, callback, *args, **kwargs): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
90 self.notifs.append((callback, args, kwargs)) |
29 | 91 |
92 | |
93 class Note(Label): | |
94 title = properties.StringProperty() | |
95 message = properties.StringProperty() | |
96 level = properties.OptionProperty(C.XMLUI_DATA_LVL_DEFAULT, options=list(C.XMLUI_DATA_LVLS)) | |
97 | |
98 | |
99 class NoteDrop(Note): | |
100 pass | |
101 | |
102 | |
103 class NotesDrop(DropDown): | |
104 clear_btn = properties.ObjectProperty() | |
105 | |
106 def __init__(self, notes): | |
107 super(NotesDrop, self).__init__() | |
108 self.notes = notes | |
109 | |
110 def open(self, widget): | |
111 self.clear_widgets() | |
112 for n in self.notes: | |
113 self.add_widget(NoteDrop(title=n.title, message=n.message, level=n.level)) | |
114 self.add_widget(self.clear_btn) | |
115 super(NotesDrop, self).open(widget) | |
116 | |
117 | |
118 class RootHeadWidget(BoxLayout): | |
119 """Notifications widget""" | |
120 manager = properties.ObjectProperty() | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
121 notifs_icon = properties.ObjectProperty() |
29 | 122 notes = properties.ListProperty() |
123 | |
124 def __init__(self): | |
125 super(RootHeadWidget, self).__init__() | |
126 self.notes_last = None | |
127 self.notes_event = None | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
128 self.notes_drop = NotesDrop(self.notes) |
29 | 129 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
130 def addNotif(self, callback, *args, **kwargs): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
131 self.notifs_icon.addNotif(callback, *args, **kwargs) |
29 | 132 |
133 def addNote(self, title, message, level): | |
134 note = Note(title=title, message=message, level=level) | |
135 self.notes.append(note) | |
136 if len(self.notes) > 10: | |
137 del self.notes[:-10] | |
138 if self.notes_event is None: | |
139 self.notes_event = Clock.schedule_interval(self._displayNextNote, 5) | |
140 self._displayNextNote() | |
141 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
142 def addNotifUI(self, ui): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
143 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
|
144 |
29 | 145 def _displayNextNote(self, dummy=None): |
146 screen = Screen() | |
147 try: | |
148 idx = self.notes.index(self.notes_last) + 1 | |
149 except ValueError: | |
150 idx = 0 | |
151 try: | |
152 note = self.notes_last = self.notes[idx] | |
153 except IndexError: | |
154 self.notes_event.cancel() | |
155 self.notes_event = None | |
156 else: | |
157 screen.add_widget(note) | |
158 self.manager.switch_to(screen) | |
159 | |
160 | |
86 | 161 class RootMenus(menu.MenusWidget): |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
162 pass |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
163 |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
164 |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
165 class RootBody(BoxLayout): |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
166 pass |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
167 |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
168 |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
169 class CagouRootWidget(FloatLayout): |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
170 root_menus = properties.ObjectProperty() |
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
171 root_body = properties.ObjectProperty |
9 | 172 |
29 | 173 def __init__(self, main_widget): |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
174 super(CagouRootWidget, self).__init__() |
29 | 175 # header |
176 self._head_widget = RootHeadWidget() | |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
177 self.root_body.add_widget(self._head_widget) |
29 | 178 # body |
179 self._manager = ScreenManager() | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
180 # main widgets |
29 | 181 main_screen = Screen(name='main') |
182 main_screen.add_widget(main_widget) | |
183 self._manager.add_widget(main_screen) | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
184 # backend XMLUI (popups, forms, etc) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
185 xmlui_screen = Screen(name='xmlui') |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
186 self._manager.add_widget(xmlui_screen) |
78 | 187 # extra (file chooser, audio record, etc) |
188 extra_screen = Screen(name='extra') | |
189 self._manager.add_widget(extra_screen) | |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
190 self.root_body.add_widget(self._manager) |
29 | 191 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
192 def changeWidget(self, widget, screen_name="main"): |
29 | 193 """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
|
194 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
|
195 # 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
|
196 # 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
|
197 self._manager.transition.stop() |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
198 screen = self._manager.get_screen(screen_name) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
199 screen.clear_widgets() |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
200 screen.add_widget(widget) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
201 |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
202 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
|
203 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
|
204 # 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
|
205 # 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
|
206 self._manager.transition.stop() |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
207 if self._manager.current == screen: |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
208 return |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
209 if screen == "main": |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
210 self._manager.transition = FallOutTransition() |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
211 else: |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
212 self._manager.transition = RiseInTransition() |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
213 self._manager.current = screen |
29 | 214 |
215 def newAction(self, handler, action_data, id_, security_limit, profile): | |
216 """Add a notification for an action""" | |
217 self._head_widget.addNotif(handler, action_data, id_, security_limit, profile) | |
218 | |
219 def addNote(self, title, message, level): | |
220 self._head_widget.addNote(title, message, level) | |
0 | 221 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
222 def addNotifUI(self, ui): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
223 self._head_widget.addNotifUI(ui) |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
224 |
0 | 225 |
226 class CagouApp(App): | |
227 """Kivy App for Cagou""" | |
228 | |
229 def build(self): | |
143
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
230 Window.bind(on_keyboard=self.key_input) |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
231 return CagouRootWidget(Label(text=u"Loading please wait")) |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
232 |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
233 def showWidget(self): |
49
fd9cbf6ae663
core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents:
48
diff
changeset
|
234 self._profile_manager = ProfileManager() |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
235 self.root.changeWidget(self._profile_manager) |
0 | 236 |
31
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
237 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
|
238 """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
|
239 |
32 | 240 useful in kv. Values which can be used: |
241 - {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
|
242 @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
|
243 @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
|
244 @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
|
245 """ |
31
4f9e701d76b4
core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
246 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
|
247 |
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
|
248 def on_start(self): |
75
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
249 if sys.platform == "android": |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
250 # XXX: we use memory map instead of bridge because if we try to call a bridge method |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
251 # in on_pause method, the call data is not written before the actual pause |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
252 # we create a memory map on .cagou_status file with a 1 byte status |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
253 # status is: |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
254 # R => running |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
255 # P => paused |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
256 # S => stopped |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
257 self._first_pause = True |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
258 self.cagou_status_fd = open('.cagou_status', 'wb+') |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
259 self.cagou_status_fd.write('R') |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
260 self.cagou_status_fd.flush() |
b84dadbab62b
core: added a platform check in on_start:
Goffi <goffi@goffi.org>
parents:
73
diff
changeset
|
261 self.cagou_status = mmap.mmap(self.cagou_status_fd.fileno(), 1, prot=mmap.PROT_WRITE) |
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
|
262 |
65
1c738621bc8d
core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
263 def on_pause(self): |
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
|
264 self.cagou_status[0] = 'P' |
65
1c738621bc8d
core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
265 return True |
1c738621bc8d
core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
266 |
1c738621bc8d
core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
267 def on_resume(self): |
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
|
268 self.cagou_status[0] = 'R' |
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
|
269 |
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
|
270 def on_stop(self): |
77
bc170ccca744
core: added forgotten platfom check in on_stop
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
271 if sys.platform == "android": |
bc170ccca744
core: added forgotten platfom check in on_stop
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
272 self.cagou_status[0] = 'S' |
bc170ccca744
core: added forgotten platfom check in on_stop
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
273 self.cagou_status.flush() |
bc170ccca744
core: added forgotten platfom check in on_stop
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
274 self.cagou_status_fd.close() |
65
1c738621bc8d
core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
275 |
143
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
276 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
|
277 # we disable [esc] handling, because default action is to quit app |
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
278 if key == 27: |
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
279 return True |
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
280 else: |
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
281 return False |
05d602be0120
core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents:
142
diff
changeset
|
282 |
0 | 283 |
284 class Cagou(QuickApp): | |
285 MB_HANDLE = False | |
286 | |
287 def __init__(self): | |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
288 if bridge_name == 'embedded': |
63 | 289 from sat.core import sat_main |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
290 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
|
291 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
|
292 from jnius import autoclass |
8a0019ce3632
core (android): service is now launched using pyjnius, as recommended in doc
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
293 service = autoclass('org.goffi.cagou.cagou.ServiceBackend') |
8a0019ce3632
core (android): service is now launched using pyjnius, as recommended in doc
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
294 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
|
295 argument = '' |
8a0019ce3632
core (android): service is now launched using pyjnius, as recommended in doc
Goffi <goffi@goffi.org>
parents:
131
diff
changeset
|
296 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
|
297 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
|
298 |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
299 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
|
300 if bridge_module is None: |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
301 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
|
302 sys.exit(3) |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
303 else: |
72
1a324c682d8a
core: use onBridgeConnected and exit code 3 when bridge can't be imported
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
304 log.debug(u"Loading {} bridge".format(bridge_name)) |
63 | 305 super(Cagou, self).__init__(bridge_factory=bridge_module.Bridge, xmlui=xmlui, check_options=quick_utils.check_options, 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
|
306 self._import_kv() |
0 | 307 self.app = CagouApp() |
29 | 308 self.app.host = self |
63 | 309 self.media_dir = self.app.media_dir = config.getConfig(main_config, '', 'media_dir') |
25
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
310 self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png") |
91
520a9e1a659b
use of cagou_profile_bleu as Cagou's main icon
Goffi <goffi@goffi.org>
parents:
89
diff
changeset
|
311 self.app.icon = os.path.join(self.media_dir, "icons/muchoslava/png/cagou_profil_bleu_96.png") |
86 | 312 self._plg_wids = [] # main widgets plugins |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
313 self._plg_wids_transfer = [] # transfer widgets plugins |
14 | 314 self._import_plugins() |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
315 self._visible_widgets = {} # visible widgets by classes |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
316 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
317 @property |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
318 def visible_widgets(self): |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
319 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
|
320 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
|
321 yield w |
0 | 322 |
72
1a324c682d8a
core: use onBridgeConnected and exit code 3 when bridge can't be imported
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
323 def onBridgeConnected(self): |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
324 self.registerSignal("otrState", iface="plugin") |
63 | 325 self.bridge.getReady(self.onBackendReady) |
326 | |
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
|
327 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
|
328 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
|
329 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
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 |
0 | 341 def run(self): |
63 | 342 self.connectBridge() |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
343 self.app.bind(on_stop=self.onStop) |
0 | 344 self.app.run() |
345 | |
60
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
346 def onStop(self, obj): |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
347 try: |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
348 sat_instance = self.sat |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
349 except AttributeError: |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
350 pass |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
351 else: |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
352 sat_instance.stopService() |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
353 |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
354 def onBackendReady(self): |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
355 self.app.showWidget() |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
356 self.postInit() |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
357 |
35abe494e6c7
core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
358 def postInit(self, dummy=None): |
61 | 359 # FIXME: resize seem to bug on android, so we use below_target for now |
360 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
|
361 profile_manager = self.app._profile_manager |
fd9cbf6ae663
core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents:
48
diff
changeset
|
362 del self.app._profile_manager |
fd9cbf6ae663
core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents:
48
diff
changeset
|
363 super(Cagou, self).postInit(profile_manager) |
fd9cbf6ae663
core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents:
48
diff
changeset
|
364 |
86 | 365 def _defaultFactoryMain(self, plugin_info, target, profiles): |
366 """default factory used to create main widgets instances | |
367 | |
368 used when PLUGIN_INFO["factory"] is not set | |
369 @param plugin_info(dict): plugin datas | |
370 @param target: QuickWidget target | |
371 @param profiles(iterable): list of profiles | |
372 """ | |
14 | 373 main_cls = plugin_info['main'] |
19
c58b522607f4
main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
374 return self.widgets.getOrCreateWidget(main_cls, target, on_new_widget=None, profiles=iter(self.profiles)) |
14 | 375 |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
376 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
|
377 """default factory used to create transfer widgets instances |
86 | 378 |
379 @param plugin_info(dict): plugin datas | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
380 @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
|
381 @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
|
382 transfer widget must be used as first argument |
86 | 383 @param profiles(iterable): list of profiles |
384 None if not specified | |
385 """ | |
386 main_cls = plugin_info['main'] | |
387 return main_cls(callback=callback, cancel_cb=cancel_cb) | |
388 | |
29 | 389 ## plugins & kv import ## |
390 | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
391 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
|
392 """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
|
393 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
|
394 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
|
395 # 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
|
396 # 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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 break |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
402 else: |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
403 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
|
404 |
0ec3c3c0ed92
core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
405 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
|
406 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
|
407 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
|
408 |
14 | 409 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
|
410 """import all plugins""" |
14 | 411 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
|
412 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
|
413 plugin_glob = u"plugin*." + C.PLUGIN_EXT |
61 | 414 plug_lst = [os.path.splitext(p)[0] for p in map(os.path.basename, glob.glob(os.path.join(plugins_path, plugin_glob)))] |
415 | |
86 | 416 imported_names_main = set() # used to avoid loading 2 times plugin with same import name |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
417 imported_names_transfer = set() |
14 | 418 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
|
419 plugin_path = 'cagou.plugins.' + plug |
86 | 420 |
421 # we get type from plugin name | |
422 suff = plug[7:] | |
423 if u'_' not in suff: | |
424 log.error(u"invalid plugin name: {}, skipping".format(plug)) | |
425 continue | |
426 plugin_type = suff[:suff.find(u'_')] | |
427 | |
428 # and select the variable to use according to type | |
429 if plugin_type == C.PLUG_TYPE_WID: | |
430 imported_names = imported_names_main | |
431 default_factory = self._defaultFactoryMain | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
432 elif plugin_type == C.PLUG_TYPE_TRANSFER: |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
433 imported_names = imported_names_transfer |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
434 default_factory = self._defaultFactoryTransfer |
86 | 435 else: |
436 log.error(u"unknown plugin type {type_} for plugin {file_}, skipping".format( | |
437 type_ = plugin_type, | |
438 file_ = plug | |
439 )) | |
440 continue | |
441 plugins_set = self._getPluginsSet(plugin_type) | |
442 | |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
443 mod = import_module(plugin_path) |
14 | 444 try: |
445 plugin_info = mod.PLUGIN_INFO | |
446 except AttributeError: | |
447 plugin_info = {} | |
448 | |
86 | 449 plugin_info['plugin_file'] = plug |
450 plugin_info['plugin_type'] = plugin_type | |
451 | |
452 if 'platforms' in plugin_info: | |
453 if sys.platform not in plugin_info['platforms']: | |
454 log.info(u"{plugin_file} is not used on this platform, skipping".format(**plugin_info)) | |
455 continue | |
456 | |
14 | 457 # import name is used to differentiate plugins |
458 if 'import_name' not in plugin_info: | |
459 plugin_info['import_name'] = plug | |
86 | 460 if plugin_info['import_name'] in imported_names: |
14 | 461 log.warning(_(u"there is already a plugin named {}, ignoring new one").format(plugin_info['import_name'])) |
462 continue | |
463 if plugin_info['import_name'] == C.WID_SELECTOR: | |
86 | 464 if plugin_type != C.PLUG_TYPE_WID: |
465 log.error(u"{import_name} import name can only be used with {type_} type, skipping {name}".format(type_=C.PLUG_TYPE_WID, **plugin_info)) | |
466 continue | |
14 | 467 # if WidgetSelector exists, it will be our default widget |
468 self.default_wid = plugin_info | |
469 | |
470 # we want everything optional, so we use plugin file name | |
471 # if actual name is not found | |
472 if 'name' not in plugin_info: | |
86 | 473 name_start = 8 + len(plugin_type) |
474 plugin_info['name'] = plug[name_start:] | |
14 | 475 |
476 # we need to load the kv file | |
477 if 'kv_file' not in plugin_info: | |
478 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
|
479 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
|
480 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
|
481 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
|
482 else: |
d249df379fa3
core: kv files are not mandatory anymore for plugins
Goffi <goffi@goffi.org>
parents:
87
diff
changeset
|
483 Builder.load_file(kv_path) |
14 | 484 |
485 # what is the main class ? | |
486 main_cls = getattr(mod, plugin_info['main']) | |
487 plugin_info['main'] = main_cls | |
488 | |
489 # factory is used to create the instance | |
490 # if not found, we use a defaut one with getOrCreateWidget | |
491 if 'factory' not in plugin_info: | |
86 | 492 plugin_info['factory'] = default_factory |
14 | 493 |
25
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
494 # icons |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
495 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
|
496 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
|
497 try: |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
498 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
|
499 except KeyError: |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
500 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
|
501 else: |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
19
diff
changeset
|
502 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
|
503 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
|
504 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
|
505 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
|
506 |
86 | 507 plugins_set.append(plugin_info) |
14 | 508 if not self._plg_wids: |
509 log.error(_(u"no widget plugin found")) | |
510 return | |
511 | |
512 # we want widgets sorted by names | |
513 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
|
514 self._plg_wids_transfer.sort(key=lambda p: p['name'].lower()) |
14 | 515 |
516 if self.default_wid is None: | |
517 # we have no selector widget, we use the first widget as default | |
518 self.default_wid = self._plg_wids[0] | |
519 | |
86 | 520 def _getPluginsSet(self, type_): |
521 if type_ == C.PLUG_TYPE_WID: | |
522 return self._plg_wids | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
523 elif type_ == C.PLUG_TYPE_TRANSFER: |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
91
diff
changeset
|
524 return self._plg_wids_transfer |
86 | 525 else: |
526 raise KeyError(u"{} plugin type is unknown".format(type_)) | |
527 | |
528 def getPluggedWidgets(self, type_=C.PLUG_TYPE_WID, except_cls=None): | |
14 | 529 """get available widgets plugin infos |
530 | |
86 | 531 @param type_(unicode): type of widgets to get |
532 one of C.PLUG_TYPE_* constant | |
14 | 533 @param except_cls(None, class): if not None, |
534 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
|
535 @return (iter[dict]): available widgets plugin infos |
14 | 536 """ |
86 | 537 plugins_set = self._getPluginsSet(type_) |
538 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
|
539 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
|
540 continue |
c58b522607f4
main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
541 yield plugin_data |
14 | 542 |
86 | 543 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
|
544 """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
|
545 |
86 | 546 @param type_(unicode): type of widgets to get |
547 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
|
548 @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
|
549 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
|
550 @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
|
551 """ |
86 | 552 plugins_set = self._getPluginsSet(type_) |
553 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
|
554 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
|
555 try: |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
556 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
|
557 continue |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
558 except KeyError: |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
559 continue |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
560 return plugin_info |
7cac2d1a6f20
core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents:
40
diff
changeset
|
561 |
29 | 562 ## widgets handling |
9 | 563 |
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
|
564 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
|
565 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
|
566 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
|
567 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
|
568 |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
569 def getParentHandler(self, widget): |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
570 """Return handler holding this widget |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
571 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
572 @return (WidgetsHandler): handler |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
573 """ |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
574 w_handler = widget.parent |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
575 while w_handler and not(isinstance(w_handler, widgets_handler.WidgetsHandler)): |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
576 w_handler = w_handler.parent |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
577 return w_handler |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
578 |
11
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
579 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
|
580 """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
|
581 |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
582 old(CagouWidget): CagouWidget instance or a child |
49d30fc15884
core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
583 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
|
584 """ |
14 | 585 to_change = None |
586 if isinstance(old, CagouWidget): | |
587 to_change = old | |
588 else: | |
589 for w in old.walk_reverse(): | |
590 if isinstance(w, CagouWidget): | |
591 to_change = w | |
592 break | |
593 | |
594 if to_change is None: | |
38
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
595 raise exceptions.InternalError(u"no CagouWidget found when trying to switch widget") |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
596 handler = self.getParentHandler(to_change) |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
597 handler.changeWidget(new) |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
598 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
599 def addVisibleWidget(self, widget): |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
600 """declare a widget visible |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
601 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
602 for internal use only! |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
603 """ |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
604 assert isinstance(widget, quick_widgets.QuickWidget) |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
605 self._visible_widgets.setdefault(widget.__class__, []).append(widget) |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
606 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
607 def removeVisibleWidget(self, widget): |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
608 """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
|
609 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
610 for internal use only! |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
611 """ |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
612 self._visible_widgets[widget.__class__].remove(widget) |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
613 self.widgets.deleteWidget(widget) |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
614 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
615 def getVisibleList(self, cls): |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
616 """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
|
617 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
618 @param cls(QuickWidget class): type of widgets to get |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
619 @return (list[QuickWidget class]): visible widgets of this class |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
620 """ |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
621 try: |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
622 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
|
623 except KeyError: |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
624 return [] |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
625 |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
626 def getOrClone(self, widget): |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
627 """Get a QuickWidget if it has not parent set else clone it""" |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
628 if widget.parent is None: |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
629 return widget |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
630 targets = list(widget.targets) |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
631 w = self.widgets.getOrCreateWidget(widget.__class__, targets[0], on_new_widget=None, on_existing_widget=C.WIDGET_RECREATE, profiles=widget.profiles) |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
632 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
|
633 w.addTarget(t) |
9f45098289cc
widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents:
34
diff
changeset
|
634 return w |
29 | 635 |
51 | 636 ## menus ## |
637 | |
112
d654bdfeb404
core: changes menu bridge call, to follow backend
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
638 def _menusGetCb(self, backend_menus): |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
78
diff
changeset
|
639 main_menu = self.app.root.root_menus |
51 | 640 self.menus.addMenus(backend_menus) |
641 self.menus.addMenu(C.MENU_GLOBAL, (_(u"Help"), _(u"About")), callback=main_menu.onAbout) | |
642 main_menu.update(C.MENU_GLOBAL) | |
643 | |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
644 ## bridge handlers ## |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
645 |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
646 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
|
647 """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
|
648 # 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
|
649 # it's only used by Cagou so far |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
650 for widget in self.widgets.getWidgets(quick_chat.QuickChat, profiles=(profile,)): |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
651 widget.onOTRState(state, dest_jid, profile) |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
652 |
29 | 653 ## misc ## |
654 | |
655 def plugging_profiles(self): | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
656 self.app.root.changeWidget(WidgetsHandler()) |
112
d654bdfeb404
core: changes menu bridge call, to follow backend
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
657 self.bridge.menusGet("", C.NO_SECURITY_LIMIT, callback=self._menusGetCb) |
29 | 658 |
659 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE): | |
660 log.info(u"Profile presence status set to {show}/{status}".format(show=show, status=status)) | |
661 | |
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
|
662 def addNote(self, title, message, level=C.XMLUI_DATA_LVL_INFO): |
29 | 663 """add a note (message which disappear) to root widget's header""" |
664 self.app.root.addNote(title, message, level) | |
665 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
666 def addNotifUI(self, ui): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
667 """add a notification with a XMLUI attached |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
668 |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
669 @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
|
670 """ |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
671 self.app.root.addNotifUI(ui) |
29 | 672 |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
673 def showUI(self, ui): |
78 | 674 """show a XMLUI""" |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
675 self.app.root.changeWidget(ui, "xmlui") |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
676 self.app.root.show("xmlui") |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
677 |
78 | 678 def showExtraUI(self, widget): |
679 """show any extra widget""" | |
680 self.app.root.changeWidget(widget, "extra") | |
681 self.app.root.show("extra") | |
682 | |
33
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
683 def closeUI(self): |
c21d1be2e54c
core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents:
32
diff
changeset
|
684 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
|
685 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
43
diff
changeset
|
686 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
|
687 return self.app.default_avatar |
61 | 688 |
689 def showDialog(self, message, title, type="info", answer_cb=None, answer_data=None): | |
690 # TODO | |
691 log.info(u"FIXME: showDialog not implemented") | |
692 log.info(u"message: {} -- {}".format(title, message)) |