comparison src/cagou/core/cagou_main.py @ 63:af4f986d86f0

core: pb bridge implementation: - media_dir is now gotten directly from config - replaced sync bridge calls by async ones - pb is now the bridge used in sat.conf for Android
author Goffi <goffi@goffi.org>
date Tue, 13 Dec 2016 23:10:41 +0100
parents 0b7f10de416e
children 8e16abcadbb8
comparison
equal deleted inserted replaced
62:1922506846be 63:af4f986d86f0
32 from sat.tools import config 32 from sat.tools import config
33 from sat.tools.common import dynamic_import 33 from sat.tools.common import dynamic_import
34 import kivy 34 import kivy
35 kivy.require('1.9.1') 35 kivy.require('1.9.1')
36 import kivy.support 36 import kivy.support
37 bridge_name = config.getConfig(config.parseMainConf(), '', 'bridge', 'dbus') 37 main_config = config.parseMainConf()
38 bridge_name = config.getConfig(main_config, '', 'bridge', 'dbus')
38 # FIXME: event loop is choosen according to bridge_name, a better way should be used 39 # FIXME: event loop is choosen according to bridge_name, a better way should be used
39 if bridge_name == 'embedded': 40 if 'dbus' in bridge_name:
41 kivy.support.install_gobject_iteration()
42 elif bridge_name in ('pb', 'embedded'):
40 kivy.support.install_twisted_reactor() 43 kivy.support.install_twisted_reactor()
41 else:
42 kivy.support.install_gobject_iteration()
43 from kivy.app import App 44 from kivy.app import App
44 from kivy.lang import Builder 45 from kivy.lang import Builder
45 from kivy import properties 46 from kivy import properties
46 import xmlui 47 import xmlui
47 from profile_manager import ProfileManager 48 from profile_manager import ProfileManager
58 from importlib import import_module 59 from importlib import import_module
59 import os.path 60 import os.path
60 import glob 61 import glob
61 import cagou.plugins 62 import cagou.plugins
62 import cagou.kv 63 import cagou.kv
63 from sat.core import sat_main
64 from kivy import utils as kivy_utils 64 from kivy import utils as kivy_utils
65 import sys 65 import sys
66 if kivy_utils.platform == "android": 66 if kivy_utils.platform == "android":
67 # FIXME: move to separate android module 67 # FIXME: move to separate android module
68 kivy.support.install_android() 68 kivy.support.install_android()
230 class Cagou(QuickApp): 230 class Cagou(QuickApp):
231 MB_HANDLE = False 231 MB_HANDLE = False
232 232
233 def __init__(self): 233 def __init__(self):
234 if bridge_name == 'embedded': 234 if bridge_name == 'embedded':
235 from sat.core import sat_main
235 self.sat = sat_main.SAT() 236 self.sat = sat_main.SAT()
236 bridge_module = dynamic_import.bridge(bridge_name, 'sat_frontends.bridge') 237 bridge_module = dynamic_import.bridge(bridge_name, 'sat_frontends.bridge')
237 if bridge_module is None: 238 if bridge_module is None:
238 log.error(u"Can't import {} bridge".format(bridge_name)) 239 log.error(u"Can't import {} bridge".format(bridge_name))
239 sys.exit(1) 240 sys.exit(1)
240 else: 241 else:
241 log.info(u"Loading {} bridge".format(bridge_name)) 242 log.info(u"Loading {} bridge".format(bridge_name))
242 super(Cagou, self).__init__(create_bridge=bridge_module.Bridge, xmlui=xmlui, check_options=quick_utils.check_options) 243 super(Cagou, self).__init__(bridge_factory=bridge_module.Bridge, xmlui=xmlui, check_options=quick_utils.check_options, connect_bridge=False)
243 self._import_kv() 244 self._import_kv()
244 self.app = CagouApp() 245 self.app = CagouApp()
245 self.app.host = self 246 self.app.host = self
246 self.media_dir = self.app.media_dir = self.bridge.getConfig("", "media_dir") 247 self.media_dir = self.app.media_dir = config.getConfig(main_config, '', 'media_dir')
247 self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png") 248 self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png")
248 self._plg_wids = [] # widget plugins 249 self._plg_wids = [] # widget plugins
249 self._import_plugins() 250 self._import_plugins()
250 self._visible_widgets = {} # visible widgets by classes 251 self._visible_widgets = {} # visible widgets by classes
251 252
253 def visible_widgets(self): 254 def visible_widgets(self):
254 for w_list in self._visible_widgets.itervalues(): 255 for w_list in self._visible_widgets.itervalues():
255 for w in w_list: 256 for w in w_list:
256 yield w 257 yield w
257 258
259 def _bridgeCb(self):
260 super(Cagou, self)._bridgeCb()
261 self.bridge.getReady(self.onBackendReady)
262
258 def run(self): 263 def run(self):
259 self.bridge.getReady(self.onBackendReady) 264 self.connectBridge()
260 self.app.bind(on_stop=self.onStop) 265 self.app.bind(on_stop=self.onStop)
261 self.app.run() 266 self.app.run()
262 267
263 def onStop(self, obj): 268 def onStop(self, obj):
264 try: 269 try: