mirror of https://github.com/m-labs/artiq.git
artiq_browser: load from hdf5
This commit is contained in:
parent
fa63637a2e
commit
670e8907a5
|
@ -12,6 +12,7 @@ from artiq import __artiq_dir__ as artiq_dir
|
||||||
from artiq.tools import *
|
from artiq.tools import *
|
||||||
from artiq.gui import (state, results,
|
from artiq.gui import (state, results,
|
||||||
datasets, applets)
|
datasets, applets)
|
||||||
|
from artiq.protocols.sync_struct import process_mod
|
||||||
|
|
||||||
|
|
||||||
def get_argparser():
|
def get_argparser():
|
||||||
|
@ -66,11 +67,21 @@ class MdiArea(QtWidgets.QMdiArea):
|
||||||
|
|
||||||
|
|
||||||
class LocalModelManager:
|
class LocalModelManager:
|
||||||
def __init__(self, model_factory):
|
def __init__(self, model_factory, notify_cb=None):
|
||||||
self.model = None
|
self.model = None
|
||||||
self._model_factory = model_factory
|
self._model_factory = model_factory
|
||||||
self._setmodel_callbacks = []
|
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):
|
def _create_model(self, init):
|
||||||
self.model = self._model_factory(init)
|
self.model = self._model_factory(init)
|
||||||
|
@ -107,7 +118,7 @@ def main():
|
||||||
mdi_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
|
mdi_area.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
|
||||||
main_window.setCentralWidget(mdi_area)
|
main_window.setCentralWidget(mdi_area)
|
||||||
|
|
||||||
d_results = results.ResultsDock()
|
d_results = results.ResultsDock(datasets_sub)
|
||||||
smgr.register(d_results)
|
smgr.register(d_results)
|
||||||
|
|
||||||
d_applets = applets.AppletsDock(main_window, datasets_sub)
|
d_applets = applets.AppletsDock(main_window, datasets_sub)
|
||||||
|
@ -118,11 +129,9 @@ def main():
|
||||||
None) # TODO: datsets_ctl.delete()
|
None) # TODO: datsets_ctl.delete()
|
||||||
smgr.register(d_datasets)
|
smgr.register(d_datasets)
|
||||||
|
|
||||||
# lay out docks
|
main_window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, d_results)
|
||||||
right_docks = [d_results, d_applets, d_datasets]
|
main_window.addDockWidget(QtCore.Qt.BottomDockWidgetArea, d_applets)
|
||||||
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, right_docks[0])
|
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, d_datasets)
|
||||||
for d1, d2 in zip(right_docks, right_docks[1:]):
|
|
||||||
main_window.tabifyDockWidget(d1, d2)
|
|
||||||
|
|
||||||
# load/initialize state
|
# load/initialize state
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
from functools import partial
|
|
||||||
|
|
||||||
|
import h5py
|
||||||
from PyQt5 import QtCore, QtWidgets
|
from PyQt5 import QtCore, QtWidgets
|
||||||
|
|
||||||
from artiq.gui.tools import LayoutWidget
|
from artiq.gui.tools import LayoutWidget
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ResultsDock(QtWidgets.QDockWidget):
|
class ResultsDock(QtWidgets.QDockWidget):
|
||||||
def __init__(self):
|
def __init__(self, datasets):
|
||||||
QtWidgets.QDockWidget.__init__(self, "Results")
|
QtWidgets.QDockWidget.__init__(self, "Results")
|
||||||
|
|
||||||
|
self.datasets = datasets
|
||||||
|
|
||||||
self.setObjectName("Results")
|
self.setObjectName("Results")
|
||||||
self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
|
self.setFeatures(QtWidgets.QDockWidget.DockWidgetMovable |
|
||||||
QtWidgets.QDockWidget.DockWidgetFloatable)
|
QtWidgets.QDockWidget.DockWidgetFloatable)
|
||||||
|
@ -29,21 +30,32 @@ class ResultsDock(QtWidgets.QDockWidget):
|
||||||
|
|
||||||
self.rt_model = QtWidgets.QFileSystemModel()
|
self.rt_model = QtWidgets.QFileSystemModel()
|
||||||
self.rt_model.setRootPath(QtCore.QDir.currentPath())
|
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_model.setNameFilterDisables(False)
|
||||||
|
|
||||||
self.rt = QtWidgets.QTreeView()
|
self.rt = QtWidgets.QTreeView()
|
||||||
self.rt.setModel(self.rt_model)
|
self.rt.setModel(self.rt_model)
|
||||||
self.rt.setRootIndex(self.rt_model.index(QtCore.QDir.currentPath()))
|
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.rt.selectionModel().selectionChanged.connect(
|
||||||
self.selection_changed)
|
self.selection_changed)
|
||||||
self.rt_buttons.addWidget(self.rt, 0, 0, colspan=2)
|
self.rt_buttons.addWidget(self.rt, 0, 0, colspan=2)
|
||||||
|
|
||||||
def selection_changed(self, selected, deselected):
|
def selection_changed(self, selected, deselected):
|
||||||
indexes = selected.indexes()
|
indexes = selected.indexes()
|
||||||
if indexes:
|
if not indexes:
|
||||||
print(self.rt_model.filePath(indexes[0]))
|
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):
|
def select(self, path):
|
||||||
s = self.rt_model.index(path)
|
s = self.rt_model.index(path)
|
||||||
|
@ -52,9 +64,6 @@ class ResultsDock(QtWidgets.QDockWidget):
|
||||||
QtCore.QItemSelectionModel.ClearAndSelect)
|
QtCore.QItemSelectionModel.ClearAndSelect)
|
||||||
self.rt.scrollTo(s) # TODO: call_soon?
|
self.rt.scrollTo(s) # TODO: call_soon?
|
||||||
|
|
||||||
def resultname_action(self, action):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
return {
|
return {
|
||||||
"selected": self.rt_model.filePath(
|
"selected": self.rt_model.filePath(
|
||||||
|
|
Loading…
Reference in New Issue