forked from M-Labs/artiq
1
0
Fork 0

applets: fix initial embedded widget size

This commit is contained in:
spaqin 2024-07-25 09:36:40 +02:00 committed by Sébastien Bourdeauducq
parent d6bcc64518
commit e7f906e47a
2 changed files with 19 additions and 20 deletions

View File

@ -137,9 +137,8 @@ class AppletIPCClient(AsyncioChildComm):
logger.error("unexpected action reply to embed request: %s",
reply["action"])
self.close_cb()
def fix_initial_size(self):
self.write_pyon({"action": "fix_initial_size"})
else:
return reply["size_w"], reply["size_h"]
async def listen(self):
data = None
@ -286,12 +285,13 @@ class SimpleApplet:
# 2. applet creates native window without showing it, and
# gets its ID
# 3. applet sends the ID to host, host embeds the widget
# 4. applet shows the widget
# 5. parent resizes the widget
# and returns embedded size
# 4. applet is resized to that given size
# 5. applet shows the widget
win_id = int(self.main_widget.winId())
self.loop.run_until_complete(self.ipc.embed(win_id))
size_w, size_h = self.loop.run_until_complete(self.ipc.embed(win_id))
self.main_widget.resize(size_w, size_h)
self.main_widget.show()
self.ipc.fix_initial_size()
else:
self.main_widget.show()

View File

@ -137,7 +137,7 @@ class AppletIPCServer(AsyncioParentComm):
return
self.write_pyon({"action": "mod", "mod": mod})
async def serve(self, embed_cb, fix_initial_size_cb):
async def serve(self, embed_cb):
self.dataset_sub.notify_cbs.append(self._on_mod)
try:
while True:
@ -145,10 +145,11 @@ class AppletIPCServer(AsyncioParentComm):
try:
action = obj["action"]
if action == "embed":
embed_cb(obj["win_id"])
self.write_pyon({"action": "embed_done"})
elif action == "fix_initial_size":
fix_initial_size_cb()
size = embed_cb(obj["win_id"])
if size is None:
self.write_pyon({"action": "embed_done"})
else:
self.write_pyon({"action": "embed_done", "size_h": size.height(), "size_w": size.width()})
elif action == "subscribe":
self.datasets = obj["datasets"]
self.dataset_prefixes = obj["dataset_prefixes"]
@ -176,9 +177,9 @@ class AppletIPCServer(AsyncioParentComm):
finally:
self.dataset_sub.notify_cbs.remove(self._on_mod)
def start_server(self, embed_cb, fix_initial_size_cb, *, loop=None):
def start_server(self, embed_cb, *, loop=None):
self.server_task = asyncio.ensure_future(
self.serve(embed_cb, fix_initial_size_cb), loop=loop)
self.serve(embed_cb), loop=loop)
async def stop_server(self):
if hasattr(self, "server_task"):
@ -239,7 +240,7 @@ class _AppletDock(QDockWidgetCloseDetect):
asyncio.ensure_future(
LogParser(self._get_log_source).stream_task(
self.ipc.process.stderr))
self.ipc.start_server(self.embed, self.fix_initial_size)
self.ipc.start_server(self.embed)
finally:
self.starting_stopping = False
@ -268,11 +269,9 @@ class _AppletDock(QDockWidgetCloseDetect):
self.embed_widget = QtWidgets.QWidget.createWindowContainer(
self.embed_window)
self.setWidget(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())
# return the size after embedding. Applet must resize to that,
# otherwise the applet may not fit within the dock properly.
return self.embed_widget.size()
async def terminate(self, delete_self=True):
if self.starting_stopping: