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: 38a99fde5273
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: e41b9db787af
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 2, 2016

  1. Copy the full SHA
    5ad6c5c View commit details
  2. Copy the full SHA
    6007b64 View commit details
  3. gui: minor cleanup

    sbourdeauducq committed Jan 2, 2016
    Copy the full SHA
    e41b9db View commit details
Showing with 97 additions and 2 deletions.
  1. 0 artiq/applets/__init__.py
  2. +30 −0 artiq/applets/big_number.py
  3. +65 −0 artiq/applets/simple.py
  4. +2 −2 artiq/frontend/artiq_gui.py
Empty file added artiq/applets/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions artiq/applets/big_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3.5

from quamash import QtWidgets

from artiq.applets.simple import SimpleApplet


class NumberWidget(QtWidgets.QLCDNumber):
def __init__(self, args):
QtWidgets.QLCDNumber.__init__(self)
self.setDigitCount(args.digit_count)
self.dataset_name = args.dataset

def data_changed(self, data, mod):
try:
n = float(data[self.dataset_name][1])
except (KeyError, ValueError, TypeError):
n = "---"
self.display(n)


def main():
applet = SimpleApplet(NumberWidget)
applet.add_dataset("dataset", "dataset to show")
applet.argparser.add_argument("--digit-count", type=int, default=10,
help="total number of digits to show")
applet.run()

if __name__ == "__main__":
main()
65 changes: 65 additions & 0 deletions artiq/applets/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import argparse
import asyncio

from quamash import QEventLoop, QtWidgets, QtCore

from artiq.protocols.sync_struct import Subscriber


class SimpleApplet:
def __init__(self, main_widget_class, cmd_description=None):
self.main_widget_class = main_widget_class

self.argparser = argparse.ArgumentParser(description=cmd_description)
group = self.argparser.add_argument_group("data server")
group.add_argument(
"--server", default="::1",
help="hostname or IP to connect to")
group.add_argument(
"--port", default=3250, type=int,
help="TCP port to connect to")
self._arggroup_datasets = self.argparser.add_argument_group("datasets")

def add_dataset(self, name, help=None):
if help is None:
self._arggroup_datasets.add_argument(name)
else:
self._arggroup_datasets.add_argument(name, help=help)

def args_init(self):
self.args = self.argparser.parse_args()

def quamash_init(self):
app = QtWidgets.QApplication([])
self.loop = QEventLoop(app)
asyncio.set_event_loop(self.loop)

def create_main_widget(self):
self.main_widget = self.main_widget_class(self.args)
self.main_widget.show()

def sub_init(self, data):
self.data = data
return data

def sub_mod(self, mod):
self.main_widget.data_changed(self.data, mod)

def create_subscriber(self):
self.subscriber = Subscriber("datasets",
self.sub_init, self.sub_mod)
self.loop.run_until_complete(self.subscriber.connect(
self.args.server, self.args.port))

def run(self):
self.args_init()
self.quamash_init()
try:
self.create_main_widget()
self.create_subscriber()
try:
self.loop.run_forever()
finally:
self.loop.run_until_complete(self.subscriber.close())
finally:
self.loop.close()
4 changes: 2 additions & 2 deletions artiq/frontend/artiq_gui.py
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ def get_argparser():


class MainWindow(QtGui.QMainWindow):
def __init__(self, app, server):
def __init__(self, server):
QtGui.QMainWindow.__init__(self)
icon = QtGui.QIcon(os.path.join(artiq_dir, "gui", "icon.png"))
self.setWindowIcon(icon)
@@ -85,7 +85,7 @@ def main():
sub_clients[notifier_name] = subscriber

# initialize main window
win = MainWindow(app, args.server)
win = MainWindow(args.server)
dock_area = dockarea.DockArea()
smgr.register(dock_area)
smgr.register(win)