forked from M-Labs/artiq
1
0
Fork 0

gui/datasets: support deleting datasets without console

This commit is contained in:
Sebastien Bourdeauducq 2016-02-13 22:46:29 +01:00
parent 4a03335850
commit fb2f53ea9b
2 changed files with 21 additions and 4 deletions

View File

@ -111,7 +111,8 @@ def main():
rpc_clients["schedule"],
rpc_clients["experiment_db"])
d_datasets = datasets.DatasetsDock(win, dock_area, sub_clients["datasets"])
d_datasets = datasets.DatasetsDock(win, sub_clients["datasets"],
rpc_clients["dataset_db"])
d_applets = applets.AppletsDock(dock_area, sub_clients["datasets"])
atexit_register_coroutine(d_applets.stop)

View File

@ -30,10 +30,10 @@ class Model(DictSyncTreeSepModel):
class DatasetsDock(dockarea.Dock):
def __init__(self, dialog_parent, dock_area, datasets_sub):
def __init__(self, dialog_parent, datasets_sub, dataset_ctl):
dockarea.Dock.__init__(self, "Datasets")
self.dialog_parent = dialog_parent
self.dock_area = dock_area
self.dataset_ctl = dataset_ctl
grid = LayoutWidget()
self.addWidget(grid)
@ -44,10 +44,18 @@ class DatasetsDock(dockarea.Dock):
grid.addWidget(self.search, 0, 0)
self.table = QtGui.QTreeView()
self.table.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.table.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self.table.header().setResizeMode(QtGui.QHeaderView.ResizeToContents)
grid.addWidget(self.table, 1, 0)
self.table.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
delete_action = QtGui.QAction("Delete dataset", self.table)
delete_action.triggered.connect(self.delete_clicked)
delete_action.setShortcut("DELETE")
delete_action.setShortcutContext(QtCore.Qt.WidgetShortcut)
self.table.addAction(delete_action)
self.table_model = Model(dict())
datasets_sub.add_setmodel_callback(self.set_model)
@ -61,3 +69,11 @@ class DatasetsDock(dockarea.Dock):
self.table_model_filter = QtCore.QSortFilterProxyModel()
self.table_model_filter.setSourceModel(self.table_model)
self.table.setModel(self.table_model_filter)
def delete_clicked(self):
idx = self.table.selectedIndexes()
if idx:
idx = self.table_model_filter.mapToSource(idx[0])
key = self.table_model.index_to_key(idx)
if key is not None:
asyncio.ensure_future(self.dataset_ctl.delete(key))