browser: own package, own datasets dock

This commit is contained in:
Robert Jördens 2016-04-05 18:50:19 +08:00
parent 1814f12152
commit 1f152bceb2
3 changed files with 65 additions and 7 deletions

57
artiq/browser/datasets.py Normal file
View File

@ -0,0 +1,57 @@
from PyQt5 import QtCore, QtWidgets
from artiq.tools import short_format
from artiq.gui.tools import LayoutWidget
from artiq.gui.models import DictSyncTreeSepModel
# reduced read-only version of artiq.gui.datasets
class Model(DictSyncTreeSepModel):
def __init__(self, init):
DictSyncTreeSepModel.__init__(self, ".", ["Dataset", "Value"], init)
def convert(self, k, v, column):
return short_format(v[1])
class DatasetsDock(QtWidgets.QDockWidget):
def __init__(self, datasets_sub):
QtWidgets.QDockWidget.__init__(self, "Datasets")
self.setObjectName("Datasets")
self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
QtWidgets.QDockWidget.DockWidgetFloatable)
grid = LayoutWidget()
self.setWidget(grid)
self.search = QtWidgets.QLineEdit()
self.search.setPlaceholderText("search...")
self.search.editingFinished.connect(self._search_datasets)
grid.addWidget(self.search, 0, 0)
self.table = QtWidgets.QTreeView()
self.table.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.table.setSelectionMode(
QtWidgets.QAbstractItemView.SingleSelection)
grid.addWidget(self.table, 1, 0)
self.table_model = Model(dict())
datasets_sub.add_setmodel_callback(self.set_model)
def _search_datasets(self):
if hasattr(self, "table_model_filter"):
self.table_model_filter.setFilterFixedString(
self.search.displayText())
def set_model(self, model):
self.table_model = model
self.table_model_filter = QtCore.QSortFilterProxyModel()
self.table_model_filter.setSourceModel(self.table_model)
self.table.setModel(self.table_model_filter)
def save_state(self):
return bytes(self.table.header().saveState())
def restore_state(self, state):
self.table.header().restoreState(QtCore.QByteArray(state))

View File

@ -54,8 +54,9 @@ class ResultsBrowser(QtWidgets.QSplitter):
try: try:
with h5py.File(path, "r") as f: with h5py.File(path, "r") as f:
rd = {} rd = {}
for k in f: #["datasets"]: group = f["datasets"]
rd[k] = False, f[k].value for k in group:
rd[k] = True, group[k].value
self.datasets.init(rd) self.datasets.init(rd)
except: except:
pass pass

View File

@ -10,11 +10,12 @@ from quamash import QEventLoop
from artiq import __artiq_dir__ as artiq_dir from artiq import __artiq_dir__ as artiq_dir
from artiq.tools import verbosity_args, init_logger, atexit_register_coroutine from artiq.tools import verbosity_args, init_logger, atexit_register_coroutine
from artiq.gui import state, results, datasets, applets, models from artiq.gui import state, applets, models
from artiq.browser import datasets, results
def get_argparser(): def get_argparser():
parser = argparse.ArgumentParser(description="ARTIQ results browser") parser = argparse.ArgumentParser(description="ARTIQ Browser")
parser.add_argument( parser.add_argument(
"--db-file", default="artiq_browser.pyon", "--db-file", default="artiq_browser.pyon",
help="database file for local browser settings") help="database file for local browser settings")
@ -29,7 +30,7 @@ class MainWindow(QtWidgets.QMainWindow):
icon = QtGui.QIcon(os.path.join(artiq_dir, "gui", "logo.svg")) icon = QtGui.QIcon(os.path.join(artiq_dir, "gui", "logo.svg"))
self.setWindowIcon(icon) self.setWindowIcon(icon)
self.setWindowTitle("ARTIQ - Browser") self.setWindowTitle("ARTIQ Browser")
qfm = QtGui.QFontMetrics(self.font()) qfm = QtGui.QFontMetrics(self.font())
self.resize(140*qfm.averageCharWidth(), 38*qfm.lineSpacing()) self.resize(140*qfm.averageCharWidth(), 38*qfm.lineSpacing())
@ -94,8 +95,7 @@ def main():
atexit_register_coroutine(d_applets.stop) atexit_register_coroutine(d_applets.stop)
smgr.register(d_applets) smgr.register(d_applets)
d_datasets = datasets.DatasetsDock(datasets_sub, d_datasets = datasets.DatasetsDock(datasets_sub)
None) # TODO: datsets_ctl.delete()
smgr.register(d_datasets) smgr.register(d_datasets)
main_window.setCentralWidget(d_results) main_window.setCentralWidget(d_results)