From 1f152bceb26c6c5da97c3a07998e1d2e882894af Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Tue, 5 Apr 2016 18:50:19 +0800 Subject: [PATCH] browser: own package, own datasets dock --- artiq/browser/datasets.py | 57 +++++++++++++++++++++++++++++++ artiq/{gui => browser}/results.py | 5 +-- artiq/frontend/artiq_browser.py | 10 +++--- 3 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 artiq/browser/datasets.py rename artiq/{gui => browser}/results.py (95%) diff --git a/artiq/browser/datasets.py b/artiq/browser/datasets.py new file mode 100644 index 000000000..8059fd599 --- /dev/null +++ b/artiq/browser/datasets.py @@ -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)) diff --git a/artiq/gui/results.py b/artiq/browser/results.py similarity index 95% rename from artiq/gui/results.py rename to artiq/browser/results.py index a832093a0..e76d12106 100644 --- a/artiq/gui/results.py +++ b/artiq/browser/results.py @@ -54,8 +54,9 @@ class ResultsBrowser(QtWidgets.QSplitter): try: with h5py.File(path, "r") as f: rd = {} - for k in f: #["datasets"]: - rd[k] = False, f[k].value + group = f["datasets"] + for k in group: + rd[k] = True, group[k].value self.datasets.init(rd) except: pass diff --git a/artiq/frontend/artiq_browser.py b/artiq/frontend/artiq_browser.py index 70188781a..e1de979bd 100755 --- a/artiq/frontend/artiq_browser.py +++ b/artiq/frontend/artiq_browser.py @@ -10,11 +10,12 @@ from quamash import QEventLoop from artiq import __artiq_dir__ as artiq_dir 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(): - parser = argparse.ArgumentParser(description="ARTIQ results browser") + parser = argparse.ArgumentParser(description="ARTIQ Browser") parser.add_argument( "--db-file", default="artiq_browser.pyon", 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")) self.setWindowIcon(icon) - self.setWindowTitle("ARTIQ - Browser") + self.setWindowTitle("ARTIQ Browser") qfm = QtGui.QFontMetrics(self.font()) self.resize(140*qfm.averageCharWidth(), 38*qfm.lineSpacing()) @@ -94,8 +95,7 @@ def main(): atexit_register_coroutine(d_applets.stop) smgr.register(d_applets) - d_datasets = datasets.DatasetsDock(datasets_sub, - None) # TODO: datsets_ctl.delete() + d_datasets = datasets.DatasetsDock(datasets_sub) smgr.register(d_datasets) main_window.setCentralWidget(d_results)