forked from M-Labs/artiq
1
0
Fork 0

gui: 'remove' buttons functionality

This commit is contained in:
Sebastien Bourdeauducq 2015-01-05 19:52:58 +08:00
parent f9d4056ee9
commit 4c4da77cc8
2 changed files with 33 additions and 13 deletions

View File

@ -32,7 +32,9 @@ class _PeriodicStoreSyncer(DictSyncer):
class SchedulerWindow(Window): class SchedulerWindow(Window):
def __init__(self): def __init__(self, schedule_ctl):
self.schedule_ctl = schedule_ctl
Window.__init__(self, title="Scheduler") Window.__init__(self, title="Scheduler")
self.set_default_size(720, 570) self.set_default_size(720, 570)
@ -50,13 +52,13 @@ class SchedulerWindow(Window):
topvbox.pack_start(notebook, True, True, 0) topvbox.pack_start(notebook, True, True, 0)
self.queue_store = Gtk.ListStore(int, str, str, str) self.queue_store = Gtk.ListStore(int, str, str, str)
tree = Gtk.TreeView(self.queue_store) self.queue_tree = Gtk.TreeView(self.queue_store)
for i, title in enumerate(["RID", "File", "Unit", "Timeout"]): for i, title in enumerate(["RID", "File", "Unit", "Timeout"]):
renderer = Gtk.CellRendererText() renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(title, renderer, text=i) column = Gtk.TreeViewColumn(title, renderer, text=i)
tree.append_column(column) self.queue_tree.append_column(column)
scroll = Gtk.ScrolledWindow() scroll = Gtk.ScrolledWindow()
scroll.add(tree) scroll.add(self.queue_tree)
vbox = Gtk.VBox(spacing=6) vbox = Gtk.VBox(spacing=6)
vbox.pack_start(scroll, True, True, 0) vbox.pack_start(scroll, True, True, 0)
hbox = Gtk.HBox(spacing=6) hbox = Gtk.HBox(spacing=6)
@ -67,31 +69,45 @@ class SchedulerWindow(Window):
button = Gtk.Button("Move down") button = Gtk.Button("Move down")
hbox.pack_start(button, True, True, 0) hbox.pack_start(button, True, True, 0)
button = Gtk.Button("Remove") button = Gtk.Button("Remove")
button.connect("clicked", self.remove_queue)
hbox.pack_start(button, True, True, 0) hbox.pack_start(button, True, True, 0)
vbox.pack_start(hbox, False, False, 0) vbox.pack_start(hbox, False, False, 0)
vbox.set_border_width(6) vbox.set_border_width(6)
notebook.insert_page(vbox, Gtk.Label("Queue"), -1) notebook.insert_page(vbox, Gtk.Label("Queue"), -1)
self.periodic_store = Gtk.ListStore(str, int, str, str, str, str) self.periodic_store = Gtk.ListStore(str, int, str, str, str, str)
tree = Gtk.TreeView(self.periodic_store) self.periodic_tree = Gtk.TreeView(self.periodic_store)
for i, title in enumerate(["Next run", "PRID", "File", "Unit", for i, title in enumerate(["Next run", "PRID", "File", "Unit",
"Timeout", "Period"]): "Timeout", "Period"]):
renderer = Gtk.CellRendererText() renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(title, renderer, text=i) column = Gtk.TreeViewColumn(title, renderer, text=i)
tree.append_column(column) self.periodic_tree.append_column(column)
scroll = Gtk.ScrolledWindow() scroll = Gtk.ScrolledWindow()
scroll.add(tree) scroll.add(self.periodic_tree)
vbox = Gtk.VBox(spacing=6) vbox = Gtk.VBox(spacing=6)
vbox.pack_start(scroll, True, True, 0) vbox.pack_start(scroll, True, True, 0)
hbox = Gtk.HBox(spacing=6) hbox = Gtk.HBox(spacing=6)
button = Gtk.Button("Change period") button = Gtk.Button("Change period")
hbox.pack_start(button, True, True, 0) hbox.pack_start(button, True, True, 0)
button = Gtk.Button("Remove") button = Gtk.Button("Remove")
button.connect("clicked", self.remove_periodic)
hbox.pack_start(button, True, True, 0) hbox.pack_start(button, True, True, 0)
vbox.pack_start(hbox, False, False, 0) vbox.pack_start(hbox, False, False, 0)
vbox.set_border_width(6) vbox.set_border_width(6)
notebook.insert_page(vbox, Gtk.Label("Periodic schedule"), -1) notebook.insert_page(vbox, Gtk.Label("Periodic schedule"), -1)
def remove_queue(self, widget):
store, selected = self.queue_tree.get_selection().get_selected()
if selected is not None:
rid = store[selected][0]
asyncio.Task(self.schedule_ctl.cancel_once(rid))
def remove_periodic(self, widget):
store, selected = self.periodic_tree.get_selection().get_selected()
if selected is not None:
prid = store[selected][1]
asyncio.Task(self.schedule_ctl.cancel_periodic(prid))
@asyncio.coroutine @asyncio.coroutine
def sub_connect(self, host, port): def sub_connect(self, host, port):
self.queue_subscriber = Subscriber("queue", self.init_queue_store) self.queue_subscriber = Subscriber("queue", self.init_queue_store)

View File

@ -7,6 +7,7 @@ import atexit
import gbulb import gbulb
from gi.repository import Gtk from gi.repository import Gtk
from artiq.management.pc_rpc import AsyncioClient
from artiq.gui.scheduler import SchedulerWindow from artiq.gui.scheduler import SchedulerWindow
from artiq.gui.parameters import ParametersWindow from artiq.gui.parameters import ParametersWindow
@ -32,19 +33,22 @@ def main():
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
atexit.register(lambda: loop.close()) atexit.register(lambda: loop.close())
scheduler_win = SchedulerWindow() # share the schedule control connection
schedule_ctl = AsyncioClient()
loop.run_until_complete(schedule_ctl.connect_rpc(
args.server, args.port_control, "master_schedule"))
scheduler_win = SchedulerWindow(schedule_ctl)
scheduler_win.connect("delete-event", Gtk.main_quit) scheduler_win.connect("delete-event", Gtk.main_quit)
scheduler_win.show_all() scheduler_win.show_all()
parameters_win = ParametersWindow()
parameters_win.connect("delete-event", Gtk.main_quit)
parameters_win.show_all()
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))
atexit.register( atexit.register(
lambda: loop.run_until_complete(scheduler_win.sub_close())) lambda: loop.run_until_complete(scheduler_win.sub_close()))
parameters_win = ParametersWindow()
parameters_win.connect("delete-event", Gtk.main_quit)
parameters_win.show_all()
loop.run_until_complete(parameters_win.sub_connect( loop.run_until_complete(parameters_win.sub_connect(
args.server, args.port_notify)) args.server, args.port_notify))
atexit.register( atexit.register(