diff --git a/artiq/examples/master/repository/code_applet.py b/artiq/examples/master/repository/code_applet.py new file mode 100644 index 000000000..a1e5f2f56 --- /dev/null +++ b/artiq/examples/master/repository/code_applet.py @@ -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") diff --git a/artiq/examples/master/repository/custom_applet.py b/artiq/examples/master/repository/custom_applet.py new file mode 100644 index 000000000..1f197ffbb --- /dev/null +++ b/artiq/examples/master/repository/custom_applet.py @@ -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 = "" + n + "" + self.setText(n) + + +def main(): + applet = SimpleApplet(DemoWidget) + applet.add_dataset("dataset", "dataset to show") + applet.run() + +if __name__ == "__main__": + main()