Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c9a9d1918268
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 92c0ede689dc
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Feb 11, 2016

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    cd9467a View commit details
  2. Copy the full SHA
    92c0ede View commit details
Showing with 27 additions and 10 deletions.
  1. +8 −3 artiq/applets/simple.py
  2. +19 −7 artiq/gui/applets.py
11 changes: 8 additions & 3 deletions artiq/applets/simple.py
Original file line number Diff line number Diff line change
@@ -36,6 +36,9 @@ async def embed(self, win_id):
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 @@ def create_main_widget(self):
# 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
26 changes: 19 additions & 7 deletions artiq/gui/applets.py
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ def _on_mod(self, mod):
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 @@ async def serve(self, embed_cb):
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 @@ async def serve(self, embed_cb):
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,13 +112,19 @@ async def start(self):
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)
embed_widget = QtWidgets.QWidget.createWindowContainer(embed_window)
self.addWidget(embed_widget)
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"):
@@ -133,6 +142,9 @@ async def terminate(self):
await self.ipc.process.wait()
del self.ipc

self.embed_widget.deleteLater()
del self.embed_widget

async def restart(self):
await self.terminate()
await self.start()