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: bf863053b3d8
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: b7b6e7b9db8e
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Sep 6, 2016

  1. Copy the full SHA
    b982832 View commit details
  2. examples: code applet

    sbourdeauducq committed Sep 6, 2016
    Copy the full SHA
    b7b6e7b View commit details
Showing with 67 additions and 10 deletions.
  1. +4 −4 artiq/dashboard/applets_ccb.py
  2. +29 −0 artiq/examples/master/repository/code_applet.py
  3. +26 −0 artiq/examples/master/repository/custom_applet.py
  4. +8 −6 artiq/gui/applets.py
8 changes: 4 additions & 4 deletions artiq/dashboard/applets_ccb.py
Original file line number Diff line number Diff line change
@@ -49,14 +49,14 @@ def locate_applet(self, name, group, create_groups):
break
return parent, applet

def ccb_create_applet(self, name, command_or_code, group=None, is_code=False):
def ccb_create_applet(self, name, command, group=None, code=None):
if not self.listen_action.isChecked():
return
parent, applet = self.locate_applet(name, group, True)
if is_code:
spec = {"ty": "code", "code": command_or_code}
if code is None:
spec = {"ty": "command", "command": command}
else:
spec = {"ty": "command", "command": command_or_code}
spec = {"ty": "code", "code": code, "command": command}
if applet is None:
applet = self.new(name=name, spec=spec, parent=parent)
else:
29 changes: 29 additions & 0 deletions artiq/examples/master/repository/code_applet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import time

from artiq.experiment import *


# Do the applet source code path determination on import.
# ARTIQ imports the experiment, then changes the current
# directory to the results, then instantiates the experiment.
# In Python __file__ is a relative path which is not updated
# when the current directory is changed.
custom_applet = os.path.abspath(os.path.join(os.path.dirname(__file__),
"custom_applet.py"))


class CreateCodeApplet(EnvExperiment):
def build(self):
self.setattr_device("ccb")

def run(self):
with open(custom_applet) as f:
self.ccb.issue("create_applet", "code_applet_example",
"code_applet_dataset", code=f.read(), group="autoapplet")
for i in reversed(range(10)):
self.set_dataset("code_applet_dataset", i,
broadcast=True, save=False)
time.sleep(1)
self.ccb.issue("disable_applet", "code_applet_example",
group="autoapplet")
26 changes: 26 additions & 0 deletions artiq/examples/master/repository/custom_applet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from PyQt5 import QtWidgets

from artiq.applets.simple import SimpleApplet


class DemoWidget(QtWidgets.QLabel):
def __init__(self, args):
QtWidgets.QLabel.__init__(self)
self.dataset_name = args.dataset

def data_changed(self, data, mods):
try:
n = str(data[self.dataset_name][1])
except (KeyError, ValueError, TypeError):
n = "---"
n = "<font size=15>" + n + "</font>"
self.setText(n)


def main():
applet = SimpleApplet(DemoWidget)
applet.add_dataset("dataset", "dataset to show")
applet.run()

if __name__ == "__main__":
main()
14 changes: 8 additions & 6 deletions artiq/gui/applets.py
Original file line number Diff line number Diff line change
@@ -156,7 +156,10 @@ async def start(self):
logger.debug("starting command %s for %s", command, self.applet_name)
await self.start_process(shlex.split(command), None)
elif self.spec["ty"] == "code":
await self.start_process([sys.executable], self.spec["code"])
args = [sys.executable, "-"]
args += shlex.split(self.spec["command"])
logger.debug("starting code applet %s", self.applet_name)
await self.start_process(args, self.spec["code"])
else:
raise ValueError

@@ -377,21 +380,21 @@ def get_spec(self, item):
if item.applet_spec_ty == "command":
return {"ty": "command", "command": item.text(2)}
elif item.applet_spec_ty == "code":
return {"ty": "code", "code": item.applet_code}
return {"ty": "code", "code": item.applet_code,
"command": item.text(2)}
else:
raise ValueError

def set_spec(self, item, spec):
self.table.itemChanged.disconnect()
try:
item.applet_spec_ty = spec["ty"]
item.setText(2, spec["command"])
if spec["ty"] == "command":
item.setText(2, spec["command"])
item.setIcon(2, QtGui.QIcon())
if hasattr(item, "applet_code"):
del item.applet_code
elif spec["ty"] == "code":
item.setText(2, "(code)")
item.setIcon(2, QtWidgets.QApplication.style().standardIcon(
QtWidgets.QStyle.SP_FileIcon))
item.applet_code = spec["code"]
@@ -436,8 +439,7 @@ def item_changed(self, item, column):
if column == 1:
dock.rename(new_value)
else:
self.set_spec(
item, {"ty": "command", "command": new_value})
dock.spec = self.get_spec(item)
elif item.ty == "group":
# To Qt's credit, it already does everything for us here.
pass