From 1a04cc0c249dc9006405b347bac6a48bbf34e3db Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Wed, 6 Apr 2016 02:01:25 +0800 Subject: [PATCH] browser: add thumbnail icon provider --- artiq/browser/results.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/artiq/browser/results.py b/artiq/browser/results.py index e76d12106..b0f1ccf72 100644 --- a/artiq/browser/results.py +++ b/artiq/browser/results.py @@ -6,6 +6,20 @@ from PyQt5 import QtCore, QtWidgets, QtGui logger = logging.getLogger(__name__) +class ResultIconProvider(QtWidgets.QFileIconProvider): + def icon(self, info): + if not (info.isFile() and info.isReadable() and info.suffix() == "h5"): + return QtWidgets.QFileIconProvider.icon(self, info) + try: + with h5py.File(info.filePath(), "r") as f: + d = f["thumbnail"] + img = QtGui.QImage.fromData(d.value, d.attrs["extension"]) + pix = QtGui.QPixmap.fromImage(img) + return QtGui.QIcon(pix) + except: + return QtWidgets.QFileIconProvider.icon(self, info) + + class ResultsBrowser(QtWidgets.QSplitter): def __init__(self, datasets): QtWidgets.QSplitter.__init__(self) @@ -16,6 +30,7 @@ class ResultsBrowser(QtWidgets.QSplitter): self.rt_model.setRootPath(QtCore.QDir.currentPath()) self.rt_model.setNameFilters(["*.h5"]) self.rt_model.setNameFilterDisables(False) + self.rt_model.setIconProvider(ResultIconProvider()) self.rt = QtWidgets.QTreeView() self.rt.setModel(self.rt_model)