2015-07-14 23:31:18 +08:00
|
|
|
import asyncio
|
2015-07-17 02:52:53 +08:00
|
|
|
from collections import OrderedDict
|
|
|
|
from functools import partial
|
2015-08-01 19:37:16 +08:00
|
|
|
import logging
|
2015-07-14 23:31:18 +08:00
|
|
|
|
2016-02-14 19:15:57 +08:00
|
|
|
from quamash import QtGui, QtCore, QtWidgets
|
2015-07-14 23:31:18 +08:00
|
|
|
|
2015-10-12 18:10:58 +08:00
|
|
|
from artiq.tools import short_format
|
2016-02-15 07:05:30 +08:00
|
|
|
from artiq.gui.tools import LayoutWidget
|
2015-11-17 19:46:17 +08:00
|
|
|
from artiq.gui.models import DictSyncTreeSepModel
|
2015-07-14 23:31:18 +08:00
|
|
|
|
|
|
|
|
2015-08-01 19:37:16 +08:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2015-11-17 19:46:17 +08:00
|
|
|
class Model(DictSyncTreeSepModel):
|
2015-11-11 12:13:19 +08:00
|
|
|
def __init__(self, init):
|
2015-11-17 19:46:17 +08:00
|
|
|
DictSyncTreeSepModel.__init__(self, ".",
|
|
|
|
["Dataset", "Persistent", "Value"],
|
|
|
|
init)
|
2015-07-14 23:31:18 +08:00
|
|
|
|
|
|
|
def convert(self, k, v, column):
|
2015-11-17 19:46:17 +08:00
|
|
|
if column == 1:
|
2015-10-12 17:18:23 +08:00
|
|
|
return "Y" if v[0] else "N"
|
|
|
|
elif column == 2:
|
|
|
|
return short_format(v[1])
|
2015-07-14 23:31:18 +08:00
|
|
|
else:
|
|
|
|
raise ValueError
|
|
|
|
|
|
|
|
|
2016-02-14 19:15:57 +08:00
|
|
|
class DatasetsDock(QtWidgets.QDockWidget):
|
|
|
|
def __init__(self, datasets_sub, dataset_ctl):
|
|
|
|
QtWidgets.QDockWidget.__init__(self, "Datasets")
|
2016-02-14 20:46:15 +08:00
|
|
|
self.setObjectName("Datasets")
|
2016-02-14 19:15:57 +08:00
|
|
|
self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
|
|
|
|
QtWidgets.QDockWidget.DockWidgetFloatable)
|
2016-02-14 05:46:29 +08:00
|
|
|
self.dataset_ctl = dataset_ctl
|
2015-07-14 23:31:18 +08:00
|
|
|
|
|
|
|
grid = LayoutWidget()
|
2016-02-14 19:15:57 +08:00
|
|
|
self.setWidget(grid)
|
2015-07-14 23:31:18 +08:00
|
|
|
|
2015-10-12 17:31:55 +08:00
|
|
|
self.search = QtGui.QLineEdit()
|
|
|
|
self.search.setPlaceholderText("search...")
|
|
|
|
self.search.editingFinished.connect(self._search_datasets)
|
2015-10-30 19:58:15 +08:00
|
|
|
grid.addWidget(self.search, 0, 0)
|
2015-10-12 17:31:55 +08:00
|
|
|
|
2015-11-17 19:46:17 +08:00
|
|
|
self.table = QtGui.QTreeView()
|
2016-02-14 05:46:29 +08:00
|
|
|
self.table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
|
|
|
|
self.table.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
|
2015-11-17 19:46:17 +08:00
|
|
|
self.table.header().setResizeMode(QtGui.QHeaderView.ResizeToContents)
|
2015-10-12 17:31:55 +08:00
|
|
|
grid.addWidget(self.table, 1, 0)
|
2015-07-14 23:31:18 +08:00
|
|
|
|
2016-02-14 05:46:29 +08:00
|
|
|
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)
|
|
|
|
|
2015-11-11 12:13:19 +08:00
|
|
|
self.table_model = Model(dict())
|
|
|
|
datasets_sub.add_setmodel_callback(self.set_model)
|
2015-07-14 23:31:18 +08:00
|
|
|
|
2015-10-12 17:31:55 +08:00
|
|
|
def _search_datasets(self):
|
2015-11-11 12:13:19 +08:00
|
|
|
if hasattr(self, "table_model_filter"):
|
|
|
|
self.table_model_filter.setFilterFixedString(
|
|
|
|
self.search.displayText())
|
2015-10-12 17:31:55 +08:00
|
|
|
|
2015-11-11 12:13:19 +08:00
|
|
|
def set_model(self, model):
|
|
|
|
self.table_model = model
|
2016-01-10 18:38:24 +08:00
|
|
|
self.table_model_filter = QtCore.QSortFilterProxyModel()
|
2015-10-14 19:29:58 +08:00
|
|
|
self.table_model_filter.setSourceModel(self.table_model)
|
|
|
|
self.table.setModel(self.table_model_filter)
|
2016-02-14 05:46:29 +08:00
|
|
|
|
|
|
|
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))
|