browser: use thumbnail dataset

This commit is contained in:
Robert Jördens 2016-04-08 11:44:37 +08:00
parent 30d557a4f8
commit 88495f2ea9
1 changed files with 22 additions and 8 deletions

View File

@ -18,10 +18,20 @@ class ResultIconProvider(QtWidgets.QFileIconProvider):
if not (info.isFile() and info.isReadable() and if not (info.isFile() and info.isReadable() and
info.suffix() == "h5"): info.suffix() == "h5"):
return return
with h5py.File(info.filePath(), "r") as f: try:
if "thumbnail" not in f: f = h5py.File(info.filePath(), "r")
except:
return
with f:
try:
t = f["datasets/thumbnail"]
except KeyError:
return
try:
img = QtGui.QImage.fromData(t.value)
except:
logger.warning("unable to read thumbnail", exc_info=True)
return return
img = QtGui.QImage.fromData(f["thumbnail"].value)
pix = QtGui.QPixmap.fromImage(img) pix = QtGui.QPixmap.fromImage(img)
return QtGui.QIcon(pix) return QtGui.QIcon(pix)
@ -82,12 +92,17 @@ class ResultsBrowser(QtWidgets.QSplitter):
if not (info.isFile() and info.isReadable() and if not (info.isFile() and info.isReadable() and
info.suffix() == "h5"): info.suffix() == "h5"):
return return
with h5py.File(info.filePath(), "r") as f: try:
f = h5py.File(info.filePath(), "r")
except:
logger.warning("unable to read HDF5 file", exc_info=True)
with f:
rd = {} rd = {}
if "datasets" not in f: try:
group = f["datasets"]
except KeyError:
return return
group = f["datasets"] for k in f["datasets"]:
for k in group:
rd[k] = True, group[k].value rd[k] = True, group[k].value
self.datasets.init(rd) self.datasets.init(rd)
@ -96,7 +111,6 @@ class ResultsBrowser(QtWidgets.QSplitter):
self.rt.expand(idx) self.rt.expand(idx)
self.rt.scrollTo(idx) self.rt.scrollTo(idx)
self.rt.setCurrentIndex(idx) self.rt.setCurrentIndex(idx)
# rl root is signaled
self.rl.setCurrentIndex(self.rl_model.index(path)) self.rl.setCurrentIndex(self.rl_model.index(path))
def save_state(self): def save_state(self):