forked from M-Labs/artiq
1
0
Fork 0

artiq_browser: load from hdf5

This commit is contained in:
Robert Jördens 2016-04-05 15:51:04 +08:00
parent fa63637a2e
commit 670e8907a5
2 changed files with 37 additions and 19 deletions

View File

@ -12,6 +12,7 @@ from artiq import __artiq_dir__ as artiq_dir
from artiq.tools import *
from artiq.gui import (state, results,
datasets, applets)
from artiq.protocols.sync_struct import process_mod
def get_argparser():
@ -66,11 +67,21 @@ class MdiArea(QtWidgets.QMdiArea):
class LocalModelManager:
def __init__(self, model_factory):
def __init__(self, model_factory, notify_cb=None):
self.model = None
self._model_factory = model_factory
self._setmodel_callbacks = []
self.notify_cbs = []
if notify_cb is None:
notify_cb = []
if not isinstance(notify_cb, list):
notify_cb = [notify_cb]
self.notify_cbs = notify_cb
def init(self, struct):
self._create_model(struct)
mod = {"action": "init", "struct": struct}
for notify_cb in self.notify_cbs:
notify_cb(mod)
def _create_model(self, init):
self.model = self._model_factory(init)
@ -107,7 +118,7 @@ def main():
mdi_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
main_window.setCentralWidget(mdi_area)
d_results = results.ResultsDock()
d_results = results.ResultsDock(datasets_sub)
smgr.register(d_results)
d_applets = applets.AppletsDock(main_window, datasets_sub)
@ -118,11 +129,9 @@ def main():
None) # TODO: datsets_ctl.delete()
smgr.register(d_datasets)
# lay out docks
right_docks = [d_results, d_applets, d_datasets]
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, right_docks[0])
for d1, d2 in zip(right_docks, right_docks[1:]):
main_window.tabifyDockWidget(d1, d2)
main_window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, d_results)
main_window.addDockWidget(QtCore.Qt.BottomDockWidgetArea, d_applets)
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, d_datasets)
# load/initialize state
if os.name == "nt":

View File

@ -1,18 +1,19 @@
import asyncio
import logging
from functools import partial
import h5py
from PyQt5 import QtCore, QtWidgets
from artiq.gui.tools import LayoutWidget
logger = logging.getLogger(__name__)
class ResultsDock(QtWidgets.QDockWidget):
def __init__(self):
def __init__(self, datasets):
QtWidgets.QDockWidget.__init__(self, "Results")
self.datasets = datasets
self.setObjectName("Results")
self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
QtWidgets.QDockWidget.DockWidgetFloatable)
@ -29,21 +30,32 @@ class ResultsDock(QtWidgets.QDockWidget):
self.rt_model = QtWidgets.QFileSystemModel()
self.rt_model.setRootPath(QtCore.QDir.currentPath())
self.rt_model.setNameFilters(["HDF5 files (*.h5)"])
self.rt_model.setNameFilters(["*.h5"])
self.rt_model.setNameFilterDisables(False)
self.rt = QtWidgets.QTreeView()
self.rt.setModel(self.rt_model)
self.rt.setRootIndex(self.rt_model.index(QtCore.QDir.currentPath()))
self.rt.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectItems)
self.rt.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.rt.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
self.rt.selectionModel().selectionChanged.connect(
self.selection_changed)
self.rt_buttons.addWidget(self.rt, 0, 0, colspan=2)
def selection_changed(self, selected, deselected):
indexes = selected.indexes()
if indexes:
print(self.rt_model.filePath(indexes[0]))
if not indexes:
return
path = self.rt_model.filePath(indexes[0])
logger.info("opening %s", path)
try:
with h5py.File(path, "r") as f:
rd = {}
for k in f["datasets"]:
rd[k] = False, f[k].value
self.datasets.init(rd)
except:
pass
def select(self, path):
s = self.rt_model.index(path)
@ -52,9 +64,6 @@ class ResultsDock(QtWidgets.QDockWidget):
QtCore.QItemSelectionModel.ClearAndSelect)
self.rt.scrollTo(s) # TODO: call_soon?
def resultname_action(self, action):
pass
def save_state(self):
return {
"selected": self.rt_model.filePath(