changeset 498:3b627382e681

core: support async methods and bridge
author Goffi <goffi@goffi.org>
date Mon, 02 Oct 2023 17:24:01 +0200
parents 232a723aae45
children f387992d8e37
files libervia/desktop_kivy/core/cagou_main.py
diffstat 1 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/desktop_kivy/core/cagou_main.py	Mon Oct 02 17:20:13 2023 +0200
+++ b/libervia/desktop_kivy/core/cagou_main.py	Mon Oct 02 17:24:01 2023 +0200
@@ -17,6 +17,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
+import asyncio
 import os.path
 import glob
 import sys
@@ -305,6 +306,9 @@
         return
 
     def build(self):
+        # we connect async bridge here as we must have a running loop
+        self.host.a_bridge.bridge_connect()
+
         Window.bind(on_keyboard=self.key_input)
         Window.bind(on_dropfile=self.on_dropfile)
         wid = LiberviaDesktopKivyRootWidget(Label(text=_("Loading please wait")))
@@ -418,10 +422,13 @@
             sys.exit(3)
         else:
             log.debug(f"Loading {bridge_name} bridge")
-        super(LiberviaDesktopKivy, self).__init__(bridge_factory=bridge_module.bridge,
-                                    xmlui=xmlui,
-                                    check_options=quick_utils.check_options,
-                                    connect_bridge=False)
+        super(LiberviaDesktopKivy, self).__init__(
+            bridge_factory=bridge_module.bridge,
+            xmlui=xmlui,
+            check_options=quick_utils.check_options,
+            connect_bridge=False,
+            async_bridge_factory = bridge_module.AIOBridge
+        )
         self._import_kv()
         self.app = LiberviaDesktopKivyApp()
         self.app.host = self
@@ -528,7 +535,10 @@
     def run(self):
         self.connect_bridge()
         self.app.bind(on_stop=self.onStop)
-        self.app.run()
+        loop = asyncio.get_event_loop()
+        loop.run_until_complete(
+            self.app.async_run("asyncio")
+        )
 
     def onStop(self, obj):
         try: