From ba24bbc8ed0fcb8f63ccd22162bd8c226277631a Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Mon, 18 Apr 2016 17:10:40 +0200 Subject: [PATCH] browser: expid from h5 --- artiq/browser/files.py | 43 ++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/artiq/browser/files.py b/artiq/browser/files.py index 8ea46214c..a9cd73488 100644 --- a/artiq/browser/files.py +++ b/artiq/browser/files.py @@ -4,9 +4,24 @@ import os import h5py from PyQt5 import QtCore, QtWidgets, QtGui +from artiq.protocols import pyon + logger = logging.getLogger(__name__) +def open_h5(info): + if not (info.isFile() and info.isReadable() and + info.suffix() == "h5"): + return + try: + f = h5py.File(info.filePath(), "r") + except: + logger.warning("unable to read HDF5 file %s", info.filePath(), + exc_info=True) + return + return f + + class ThumbnailIconProvider(QtWidgets.QFileIconProvider): def icon(self, info): icon = self.hdf5_thumbnail(info) @@ -15,12 +30,8 @@ class ThumbnailIconProvider(QtWidgets.QFileIconProvider): return icon def hdf5_thumbnail(self, info): - if not (info.isFile() and info.isReadable() and - info.suffix() == "h5"): - return - try: - f = h5py.File(info.filePath(), "r") - except: + f = open_h5(info) + if not f: return with f: try: @@ -92,6 +103,7 @@ class FilesDock(QtWidgets.QDockWidget): self.rl.setModel(self.model) self.rl.selectionModel().currentChanged.connect( self.list_current_changed) + self.rl.doubleClicked.connect(self.open_experiment) self.splitter.addWidget(self.rl) def tree_current_changed(self, current, previous): @@ -101,14 +113,8 @@ class FilesDock(QtWidgets.QDockWidget): def list_current_changed(self, current, previous): info = self.model.fileInfo(current) logger.info("opening %s", info.filePath()) - if not (info.isFile() and info.isReadable() and - info.suffix() == "h5"): - return - try: - f = h5py.File(info.filePath(), "r") - except: - logger.warning("unable to read HDF5 file %s", info.filePath(), - exc_info=True) + f = open_h5(info) + if not f: return with f: rd = {} @@ -120,6 +126,15 @@ class FilesDock(QtWidgets.QDockWidget): rd[k] = True, group[k].value self.datasets.init(rd) + def open_experiment(self, current): + info = self.model.fileInfo(current) + logger.info("loading experiment for %s", info.filePath()) + f = open_h5(info) + if not f: + return + with f: + expid = pyon.decode(f["expid"].value) + def select_dir(self, path): if not os.path.exists(path): return