mirror of https://github.com/m-labs/artiq.git
examples: code applet
This commit is contained in:
parent
b982832ddc
commit
b7b6e7b9db
|
@ -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")
|
|
@ -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()
|
Loading…
Reference in New Issue