forked from M-Labs/artiq
applets: fix initial embedded widget size
This commit is contained in:
parent
d6bcc64518
commit
e7f906e47a
|
@ -137,9 +137,8 @@ class AppletIPCClient(AsyncioChildComm):
|
||||||
logger.error("unexpected action reply to embed request: %s",
|
logger.error("unexpected action reply to embed request: %s",
|
||||||
reply["action"])
|
reply["action"])
|
||||||
self.close_cb()
|
self.close_cb()
|
||||||
|
else:
|
||||||
def fix_initial_size(self):
|
return reply["size_w"], reply["size_h"]
|
||||||
self.write_pyon({"action": "fix_initial_size"})
|
|
||||||
|
|
||||||
async def listen(self):
|
async def listen(self):
|
||||||
data = None
|
data = None
|
||||||
|
@ -286,12 +285,13 @@ class SimpleApplet:
|
||||||
# 2. applet creates native window without showing it, and
|
# 2. applet creates native window without showing it, and
|
||||||
# gets its ID
|
# gets its ID
|
||||||
# 3. applet sends the ID to host, host embeds the widget
|
# 3. applet sends the ID to host, host embeds the widget
|
||||||
# 4. applet shows the widget
|
# and returns embedded size
|
||||||
# 5. parent resizes the widget
|
# 4. applet is resized to that given size
|
||||||
|
# 5. applet shows the widget
|
||||||
win_id = int(self.main_widget.winId())
|
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.main_widget.show()
|
||||||
self.ipc.fix_initial_size()
|
|
||||||
else:
|
else:
|
||||||
self.main_widget.show()
|
self.main_widget.show()
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ class AppletIPCServer(AsyncioParentComm):
|
||||||
return
|
return
|
||||||
self.write_pyon({"action": "mod", "mod": mod})
|
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)
|
self.dataset_sub.notify_cbs.append(self._on_mod)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
@ -145,10 +145,11 @@ class AppletIPCServer(AsyncioParentComm):
|
||||||
try:
|
try:
|
||||||
action = obj["action"]
|
action = obj["action"]
|
||||||
if action == "embed":
|
if action == "embed":
|
||||||
embed_cb(obj["win_id"])
|
size = embed_cb(obj["win_id"])
|
||||||
self.write_pyon({"action": "embed_done"})
|
if size is None:
|
||||||
elif action == "fix_initial_size":
|
self.write_pyon({"action": "embed_done"})
|
||||||
fix_initial_size_cb()
|
else:
|
||||||
|
self.write_pyon({"action": "embed_done", "size_h": size.height(), "size_w": size.width()})
|
||||||
elif action == "subscribe":
|
elif action == "subscribe":
|
||||||
self.datasets = obj["datasets"]
|
self.datasets = obj["datasets"]
|
||||||
self.dataset_prefixes = obj["dataset_prefixes"]
|
self.dataset_prefixes = obj["dataset_prefixes"]
|
||||||
|
@ -176,9 +177,9 @@ class AppletIPCServer(AsyncioParentComm):
|
||||||
finally:
|
finally:
|
||||||
self.dataset_sub.notify_cbs.remove(self._on_mod)
|
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.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):
|
async def stop_server(self):
|
||||||
if hasattr(self, "server_task"):
|
if hasattr(self, "server_task"):
|
||||||
|
@ -239,7 +240,7 @@ class _AppletDock(QDockWidgetCloseDetect):
|
||||||
asyncio.ensure_future(
|
asyncio.ensure_future(
|
||||||
LogParser(self._get_log_source).stream_task(
|
LogParser(self._get_log_source).stream_task(
|
||||||
self.ipc.process.stderr))
|
self.ipc.process.stderr))
|
||||||
self.ipc.start_server(self.embed, self.fix_initial_size)
|
self.ipc.start_server(self.embed)
|
||||||
finally:
|
finally:
|
||||||
self.starting_stopping = False
|
self.starting_stopping = False
|
||||||
|
|
||||||
|
@ -268,11 +269,9 @@ class _AppletDock(QDockWidgetCloseDetect):
|
||||||
self.embed_widget = QtWidgets.QWidget.createWindowContainer(
|
self.embed_widget = QtWidgets.QWidget.createWindowContainer(
|
||||||
self.embed_window)
|
self.embed_window)
|
||||||
self.setWidget(self.embed_widget)
|
self.setWidget(self.embed_widget)
|
||||||
|
# return the size after embedding. Applet must resize to that,
|
||||||
# HACK: This function would not be needed if Qt window embedding
|
# otherwise the applet may not fit within the dock properly.
|
||||||
# worked correctly.
|
return self.embed_widget.size()
|
||||||
def fix_initial_size(self):
|
|
||||||
self.embed_window.resize(self.embed_widget.size())
|
|
||||||
|
|
||||||
async def terminate(self, delete_self=True):
|
async def terminate(self, delete_self=True):
|
||||||
if self.starting_stopping:
|
if self.starting_stopping:
|
||||||
|
|
Loading…
Reference in New Issue