From 5fb86af3a4a0556a7909d07ad46e47d519d2149d Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 24 May 2015 23:20:52 +0800 Subject: [PATCH] gui: support experiment cancellation --- artiq/frontend/artiq_gui.py | 2 +- artiq/gui/schedule.py | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/artiq/frontend/artiq_gui.py b/artiq/frontend/artiq_gui.py index 3dc2a2b2b..40bf6658a 100755 --- a/artiq/frontend/artiq_gui.py +++ b/artiq/frontend/artiq_gui.py @@ -73,7 +73,7 @@ def main(): d_log = LogDock() area.addDock(d_log, "bottom") - d_schedule = ScheduleDock() + d_schedule = ScheduleDock(schedule_ctl) area.addDock(d_schedule, "above", d_log) loop.run_until_complete(d_schedule.sub_connect( args.server, args.port_notify)) diff --git a/artiq/gui/schedule.py b/artiq/gui/schedule.py index 46f42d583..f8cbb9d36 100644 --- a/artiq/gui/schedule.py +++ b/artiq/gui/schedule.py @@ -1,7 +1,7 @@ import asyncio import time -from quamash import QtGui +from quamash import QtGui, QtCore from pyqtgraph import dockarea from artiq.protocols.sync_struct import Subscriber @@ -49,13 +49,20 @@ class _ScheduleModel(DictSyncModel): class ScheduleDock(dockarea.Dock): - def __init__(self): + def __init__(self, schedule_ctl): dockarea.Dock.__init__(self, "Schedule", size=(1000, 300)) + self.schedule_ctl = schedule_ctl + self.table = QtGui.QTableView() self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.addWidget(self.table) + self.table.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) + delete_action = QtGui.QAction("Delete", self.table) + delete_action.triggered.connect(self.delete_clicked) + self.table.addAction(delete_action) + @asyncio.coroutine def sub_connect(self, host, port): self.subscriber = Subscriber("schedule", self.init_schedule_model) @@ -66,6 +73,17 @@ class ScheduleDock(dockarea.Dock): yield from self.subscriber.close() def init_schedule_model(self, init): - table_model = _ScheduleModel(self.table, init) - self.table.setModel(table_model) - return table_model + self.table_model = _ScheduleModel(self.table, init) + self.table.setModel(self.table_model) + return self.table_model + + @asyncio.coroutine + def delete(self, rid): + yield from self.schedule_ctl.delete(rid) + + def delete_clicked(self): + idx = self.table.selectedIndexes() + if idx: + row = idx[0].row() + rid = self.table_model.row_to_key[row] + asyncio.async(self.delete(rid))