forked from M-Labs/artiq
gui: parameter list update
This commit is contained in:
parent
a073a7e055
commit
15b27a1d14
@ -1,6 +1,44 @@
|
|||||||
|
import asyncio
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
from artiq.gui.tools import Window
|
from artiq.gui.tools import Window
|
||||||
|
from artiq.management.sync_struct import Subscriber
|
||||||
|
|
||||||
|
|
||||||
|
class _ParameterStoreSyncer:
|
||||||
|
def __init__(self, parameters_store, init):
|
||||||
|
self.parameters_store = parameters_store
|
||||||
|
self.parameters_store.clear()
|
||||||
|
for name, value in sorted(init.items(), key=itemgetter(0)):
|
||||||
|
self.parameters_store.append(self._convert(name, value))
|
||||||
|
|
||||||
|
def _convert(self, name, value):
|
||||||
|
return [name, str(value)]
|
||||||
|
|
||||||
|
def _find_index(self, name):
|
||||||
|
for i, e in enumerate(self.parameters_store):
|
||||||
|
if e[0] == name:
|
||||||
|
return i
|
||||||
|
raise KeyError
|
||||||
|
|
||||||
|
def __setitem__(self, name, value):
|
||||||
|
try:
|
||||||
|
i = self._find_index(name)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
del self.parameters_store[i]
|
||||||
|
j = len(self.parameters_store)
|
||||||
|
for i, e in enumerate(self.parameters_store):
|
||||||
|
if e[0] > name:
|
||||||
|
j = i
|
||||||
|
break
|
||||||
|
self.parameters_store.insert(j, self._convert(name, value))
|
||||||
|
|
||||||
|
def __delitem__(self, key):
|
||||||
|
del self.parameters_store[self._find_index(key)]
|
||||||
|
|
||||||
|
|
||||||
class ParametersWindow(Window):
|
class ParametersWindow(Window):
|
||||||
@ -17,3 +55,16 @@ class ParametersWindow(Window):
|
|||||||
scroll = Gtk.ScrolledWindow()
|
scroll = Gtk.ScrolledWindow()
|
||||||
scroll.add(tree)
|
scroll.add(tree)
|
||||||
self.add(scroll)
|
self.add(scroll)
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def sub_connect(self, host, port):
|
||||||
|
self.parameters_subscriber = Subscriber("parameters",
|
||||||
|
self.init_parameters_store)
|
||||||
|
yield from self.parameters_subscriber.connect(host, port)
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def sub_close(self):
|
||||||
|
yield from self.parameters_subscriber.close()
|
||||||
|
|
||||||
|
def init_parameters_store(self, init):
|
||||||
|
return _ParameterStoreSyncer(self.parameters_store, init)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import atexit
|
||||||
|
|
||||||
import gbulb
|
import gbulb
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
@ -29,7 +30,8 @@ def main():
|
|||||||
|
|
||||||
asyncio.set_event_loop_policy(gbulb.GtkEventLoopPolicy())
|
asyncio.set_event_loop_policy(gbulb.GtkEventLoopPolicy())
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
try:
|
atexit.register(lambda: loop.close())
|
||||||
|
|
||||||
scheduler_win = SchedulerWindow()
|
scheduler_win = SchedulerWindow()
|
||||||
scheduler_win.connect("delete-event", Gtk.main_quit)
|
scheduler_win.connect("delete-event", Gtk.main_quit)
|
||||||
scheduler_win.show_all()
|
scheduler_win.show_all()
|
||||||
@ -40,12 +42,15 @@ def main():
|
|||||||
|
|
||||||
loop.run_until_complete(scheduler_win.sub_connect(
|
loop.run_until_complete(scheduler_win.sub_connect(
|
||||||
args.server, args.port_notify))
|
args.server, args.port_notify))
|
||||||
try:
|
atexit.register(
|
||||||
|
lambda: loop.run_until_complete(scheduler_win.sub_close()))
|
||||||
|
|
||||||
|
loop.run_until_complete(parameters_win.sub_connect(
|
||||||
|
args.server, args.port_notify))
|
||||||
|
atexit.register(
|
||||||
|
lambda: loop.run_until_complete(parameters_win.sub_close()))
|
||||||
|
|
||||||
loop.run_forever()
|
loop.run_forever()
|
||||||
finally:
|
|
||||||
loop.run_until_complete(scheduler_win.sub_close())
|
|
||||||
finally:
|
|
||||||
loop.close()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user