From 92c0ede689dcd8d8393b06a86cc748428305a012 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 11 Feb 2016 16:19:34 +0100 Subject: [PATCH] applets: workaround for Qt window embedding initial size bug --- artiq/applets/simple.py | 11 ++++++++--- artiq/gui/applets.py | 21 +++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/artiq/applets/simple.py b/artiq/applets/simple.py index 75aec014e..cbbdf4fea 100644 --- a/artiq/applets/simple.py +++ b/artiq/applets/simple.py @@ -36,6 +36,9 @@ class AppletIPCClient(AsyncioChildComm): action) self.close_cb() + def fix_initial_size(self): + self.write_pyon({"action": "fix_initial_size"}) + async def listen(self): data = None while True: @@ -133,13 +136,15 @@ class SimpleApplet: # 2. applet creates native window without showing it, and get its ID # 3. applet sends the ID to host, host embeds the widget # 4. applet shows the widget - # Doing embedding the other way around (using QWindow.setParent in the - # applet) breaks resizing. + # 5. parent resizes the widget if self.args.embed is not None: self.ipc.set_close_cb(self.main_widget.close) win_id = int(self.main_widget.winId()) self.loop.run_until_complete(self.ipc.embed(win_id)) - self.main_widget.show() + self.main_widget.show() + self.ipc.fix_initial_size() + else: + self.main_widget.show() def sub_init(self, data): self.data = data diff --git a/artiq/gui/applets.py b/artiq/gui/applets.py index 82e93b686..bc2271cc3 100644 --- a/artiq/gui/applets.py +++ b/artiq/gui/applets.py @@ -44,7 +44,7 @@ class AppletIPCServer(AsyncioParentComm): return self.write_pyon({"action": "mod", "mod": mod}) - async def serve(self, embed_cb): + async def serve(self, embed_cb, fix_initial_size_cb): self.datasets_sub.notify_cbs.append(self._on_mod) try: while True: @@ -54,6 +54,8 @@ class AppletIPCServer(AsyncioParentComm): if action == "embed": embed_cb(obj["win_id"]) self.write_pyon({"action": "embed_done"}) + elif action == "fix_initial_size": + fix_initial_size_cb() elif action == "subscribe": self.datasets = obj["datasets"] if self.datasets_sub.model is not None: @@ -74,8 +76,9 @@ class AppletIPCServer(AsyncioParentComm): finally: self.datasets_sub.notify_cbs.remove(self._on_mod) - def start(self, embed_cb): - self.server_task = asyncio.ensure_future(self.serve(embed_cb)) + def start(self, embed_cb, fix_initial_size_cb): + self.server_task = asyncio.ensure_future( + self.serve(embed_cb, fix_initial_size_cb)) async def stop(self): self.server_task.cancel() @@ -109,14 +112,20 @@ class AppletDock(dockarea.Dock): except: logger.warning("Applet %s failed to start", self.applet_name, exc_info=True) - self.ipc.start(self.embed) + self.ipc.start(self.embed, self.fix_initial_size) def embed(self, win_id): logger.debug("capturing window 0x%x for %s", win_id, self.applet_name) - embed_window = QtGui.QWindow.fromWinId(win_id) - self.embed_widget = QtWidgets.QWidget.createWindowContainer(embed_window) + self.embed_window = QtGui.QWindow.fromWinId(win_id) + self.embed_widget = QtWidgets.QWidget.createWindowContainer( + self.embed_window) self.addWidget(self.embed_widget) + # HACK: This function would not be needed if Qt window embedding + # worked correctly. + def fix_initial_size(self): + self.embed_window.resize(self.embed_widget.size()) + async def terminate(self): if hasattr(self, "ipc"): await self.ipc.stop()