Mercurial > libervia-desktop-kivy
diff 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 |
line wrap: on
line diff
--- a/src/cagou/core/cagou_main.py Sun Oct 02 13:29:37 2016 +0200 +++ b/src/cagou/core/cagou_main.py Sun Dec 04 18:16:10 2016 +0100 @@ -29,11 +29,17 @@ from sat_frontends.quick_frontend import quick_widgets from sat_frontends.quick_frontend import quick_chat from sat_frontends.quick_frontend import quick_utils -from sat_frontends.bridge.DBus import DBusBridgeFrontend +from sat.tools import config +from sat.tools.common import dynamic_import import kivy kivy.require('1.9.1') import kivy.support -kivy.support.install_gobject_iteration() +bridge_name = config.getConfig(config.parseMainConf(), '', 'bridge', 'dbus') +# FIXME: event loop is choosen according to bridge_name, a better way should be used +if bridge_name == 'embedded': + kivy.support.install_twisted_reactor() +else: + kivy.support.install_gobject_iteration() from kivy.app import App from kivy.lang import Builder from kivy import properties @@ -54,6 +60,8 @@ import glob import cagou.plugins import cagou.kv +from sat.core import sat_main +import sys class NotifsIcon(IconButton): @@ -194,8 +202,11 @@ """Kivy App for Cagou""" def build(self): + return CagouRootWidget(Label(text=u"Loading please wait")) + + def showWidget(self): self._profile_manager = ProfileManager() - return CagouRootWidget(self._profile_manager) + self.root.changeWidget(self._profile_manager) def expand(self, path, *args, **kwargs): """expand path and replace known values @@ -213,7 +224,15 @@ MB_HANDLE = False def __init__(self): - super(Cagou, self).__init__(create_bridge=DBusBridgeFrontend, xmlui=xmlui, check_options=quick_utils.check_options) + if bridge_name == 'embedded': + self.sat = sat_main.SAT() + bridge_module = dynamic_import.bridge(bridge_name, 'sat_frontends.bridge') + if bridge_module is None: + log.error(u"Can't import {} bridge".format(bridge_name)) + sys.exit(1) + else: + log.info(u"Loading {} bridge".format(bridge_name)) + super(Cagou, self).__init__(create_bridge=bridge_module.Bridge, xmlui=xmlui, check_options=quick_utils.check_options) self._import_kv() self.app = CagouApp() self.app.host = self @@ -230,10 +249,23 @@ yield w def run(self): - Clock.schedule_once(self.postInit) + self.bridge.getReady(self.onBackendReady) + self.app.bind(on_stop=self.onStop) self.app.run() - def postInit(self, dummy): + def onStop(self, obj): + try: + sat_instance = self.sat + except AttributeError: + pass + else: + sat_instance.stopService() + + def onBackendReady(self): + self.app.showWidget() + self.postInit() + + def postInit(self, dummy=None): profile_manager = self.app._profile_manager del self.app._profile_manager super(Cagou, self).postInit(profile_manager)