Skip to content

Commit 255b00f

Browse files
committedDec 29, 2014
gui: queue display
1 parent 1fdad21 commit 255b00f

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed
 

‎frontend/artiq_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
def _get_args():
16-
parser = argparse.ArgumentParser(description="ARTIQ client")
16+
parser = argparse.ArgumentParser(description="ARTIQ CLI client")
1717
parser.add_argument(
1818
"-s", "--server", default="::1",
1919
help="hostname or IP of the master to connect to")

‎frontend/artiq_gui.py

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import asyncio
5+
6+
import gbulb
7+
from gi.repository import Gtk
8+
9+
from artiq.management.sync_struct import Subscriber
10+
11+
12+
class QueueStoreSyncer:
13+
def __init__(self, queue_store, init):
14+
self.queue_store = queue_store
15+
self.queue_store.clear()
16+
for x in init:
17+
self.append(x)
18+
19+
def _convert(self, x):
20+
rid, run_params, timeout = x
21+
row = [rid, run_params["file"]]
22+
for x in run_params["unit"], run_params["function"], timeout:
23+
row.append("-" if x is None else str(x))
24+
return row
25+
26+
def append(self, x):
27+
self.queue_store.append(self._convert(x))
28+
29+
def insert(self, i, x):
30+
self.queue_store.insert(i, self._convert(x))
31+
32+
def __delitem__(self, key):
33+
del self.queue_store[key]
34+
35+
36+
class SchedulerWindow(Gtk.Window):
37+
def __init__(self):
38+
Gtk.Window.__init__(self, title="Scheduler")
39+
40+
self.queue_store = Gtk.ListStore(int, str, str, str, str)
41+
tree = Gtk.TreeView(self.queue_store)
42+
for i, title in enumerate(["RID", "File", "Unit",
43+
"Function", "Timeout"]):
44+
renderer = Gtk.CellRendererText()
45+
column = Gtk.TreeViewColumn(title, renderer, text=i)
46+
tree.append_column(column)
47+
self.add(tree)
48+
49+
@asyncio.coroutine
50+
def sub_connect(self, host, port):
51+
self.subscriber = Subscriber(self.init_queue_store)
52+
yield from self.subscriber.connect(host, port)
53+
54+
@asyncio.coroutine
55+
def sub_close(self):
56+
yield from self.subscriber.close()
57+
58+
def init_queue_store(self, init):
59+
return QueueStoreSyncer(self.queue_store, init)
60+
61+
62+
def _get_args():
63+
parser = argparse.ArgumentParser(description="ARTIQ GUI client")
64+
parser.add_argument(
65+
"-s", "--server", default="::1",
66+
help="hostname or IP of the master to connect to")
67+
parser.add_argument(
68+
"--port-schedule-control", default=8888, type=int,
69+
help="TCP port to connect to for schedule control")
70+
parser.add_argument(
71+
"--port-schedule-notify", default=8887, type=int,
72+
help="TCP port to connect to for schedule notifications")
73+
return parser.parse_args()
74+
75+
76+
def main():
77+
args = _get_args()
78+
79+
asyncio.set_event_loop_policy(gbulb.GtkEventLoopPolicy())
80+
loop = asyncio.get_event_loop()
81+
try:
82+
win = SchedulerWindow()
83+
win.connect("delete-event", Gtk.main_quit)
84+
win.show_all()
85+
86+
loop.run_until_complete(win.sub_connect(args.server,
87+
args.port_schedule_notify))
88+
try:
89+
loop.run_forever()
90+
finally:
91+
loop.run_until_complete(win.sub_close())
92+
finally:
93+
loop.close()
94+
95+
if __name__ == "__main__":
96+
main()

0 commit comments

Comments
 (0)
Please sign in to comment.