comparison src/cagou/core/cagou_main.py @ 60:35abe494e6c7

core: bridge selection + improvments for android - bridge specified in sat.conf is now imported, in the same way as for backend - when loading, a label showing "Loading please wait" is shown - postInit is now call when backend is ready - avoid division by zero when icon is not available in cagou_widget.kv - twisted reactor is used
author Goffi <goffi@goffi.org>
date Sun, 04 Dec 2016 18:16:10 +0100
parents 647f32d0a004
children 0b7f10de416e
comparison
equal deleted inserted replaced
59:2aa44a82d0e7 60:35abe494e6c7
27 from sat.core import exceptions 27 from sat.core import exceptions
28 from sat_frontends.quick_frontend.quick_app import QuickApp 28 from sat_frontends.quick_frontend.quick_app import QuickApp
29 from sat_frontends.quick_frontend import quick_widgets 29 from sat_frontends.quick_frontend import quick_widgets
30 from sat_frontends.quick_frontend import quick_chat 30 from sat_frontends.quick_frontend import quick_chat
31 from sat_frontends.quick_frontend import quick_utils 31 from sat_frontends.quick_frontend import quick_utils
32 from sat_frontends.bridge.DBus import DBusBridgeFrontend 32 from sat.tools import config
33 from sat.tools.common import dynamic_import
33 import kivy 34 import kivy
34 kivy.require('1.9.1') 35 kivy.require('1.9.1')
35 import kivy.support 36 import kivy.support
36 kivy.support.install_gobject_iteration() 37 bridge_name = config.getConfig(config.parseMainConf(), '', 'bridge', 'dbus')
38 # FIXME: event loop is choosen according to bridge_name, a better way should be used
39 if bridge_name == 'embedded':
40 kivy.support.install_twisted_reactor()
41 else:
42 kivy.support.install_gobject_iteration()
37 from kivy.app import App 43 from kivy.app import App
38 from kivy.lang import Builder 44 from kivy.lang import Builder
39 from kivy import properties 45 from kivy import properties
40 import xmlui 46 import xmlui
41 from profile_manager import ProfileManager 47 from profile_manager import ProfileManager
52 from importlib import import_module 58 from importlib import import_module
53 import os.path 59 import os.path
54 import glob 60 import glob
55 import cagou.plugins 61 import cagou.plugins
56 import cagou.kv 62 import cagou.kv
63 from sat.core import sat_main
64 import sys
57 65
58 66
59 class NotifsIcon(IconButton): 67 class NotifsIcon(IconButton):
60 notifs = properties.ListProperty() 68 notifs = properties.ListProperty()
61 69
192 200
193 class CagouApp(App): 201 class CagouApp(App):
194 """Kivy App for Cagou""" 202 """Kivy App for Cagou"""
195 203
196 def build(self): 204 def build(self):
205 return CagouRootWidget(Label(text=u"Loading please wait"))
206
207 def showWidget(self):
197 self._profile_manager = ProfileManager() 208 self._profile_manager = ProfileManager()
198 return CagouRootWidget(self._profile_manager) 209 self.root.changeWidget(self._profile_manager)
199 210
200 def expand(self, path, *args, **kwargs): 211 def expand(self, path, *args, **kwargs):
201 """expand path and replace known values 212 """expand path and replace known values
202 213
203 useful in kv. Values which can be used: 214 useful in kv. Values which can be used:
211 222
212 class Cagou(QuickApp): 223 class Cagou(QuickApp):
213 MB_HANDLE = False 224 MB_HANDLE = False
214 225
215 def __init__(self): 226 def __init__(self):
216 super(Cagou, self).__init__(create_bridge=DBusBridgeFrontend, xmlui=xmlui, check_options=quick_utils.check_options) 227 if bridge_name == 'embedded':
228 self.sat = sat_main.SAT()
229 bridge_module = dynamic_import.bridge(bridge_name, 'sat_frontends.bridge')
230 if bridge_module is None:
231 log.error(u"Can't import {} bridge".format(bridge_name))
232 sys.exit(1)
233 else:
234 log.info(u"Loading {} bridge".format(bridge_name))
235 super(Cagou, self).__init__(create_bridge=bridge_module.Bridge, xmlui=xmlui, check_options=quick_utils.check_options)
217 self._import_kv() 236 self._import_kv()
218 self.app = CagouApp() 237 self.app = CagouApp()
219 self.app.host = self 238 self.app.host = self
220 self.media_dir = self.app.media_dir = self.bridge.getConfig("", "media_dir") 239 self.media_dir = self.app.media_dir = self.bridge.getConfig("", "media_dir")
221 self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png") 240 self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png")
228 for w_list in self._visible_widgets.itervalues(): 247 for w_list in self._visible_widgets.itervalues():
229 for w in w_list: 248 for w in w_list:
230 yield w 249 yield w
231 250
232 def run(self): 251 def run(self):
233 Clock.schedule_once(self.postInit) 252 self.bridge.getReady(self.onBackendReady)
253 self.app.bind(on_stop=self.onStop)
234 self.app.run() 254 self.app.run()
235 255
236 def postInit(self, dummy): 256 def onStop(self, obj):
257 try:
258 sat_instance = self.sat
259 except AttributeError:
260 pass
261 else:
262 sat_instance.stopService()
263
264 def onBackendReady(self):
265 self.app.showWidget()
266 self.postInit()
267
268 def postInit(self, dummy=None):
237 profile_manager = self.app._profile_manager 269 profile_manager = self.app._profile_manager
238 del self.app._profile_manager 270 del self.app._profile_manager
239 super(Cagou, self).postInit(profile_manager) 271 super(Cagou, self).postInit(profile_manager)
240 272
241 def _defaultFactory(self, plugin_info, target, profiles): 273 def _defaultFactory(self, plugin_info, target, profiles):