From 9344b64679896bc1a94e6309b4c12634f1a61ce9 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 23 Oct 2023 13:19:50 +0200 Subject: [PATCH 1/4] Pass filename used to load object through sigH5pyObjectLoaded --- src/silx/gui/hdf5/Hdf5TreeModel.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/silx/gui/hdf5/Hdf5TreeModel.py b/src/silx/gui/hdf5/Hdf5TreeModel.py index 1b77df4fcc..1e9e3636b9 100644 --- a/src/silx/gui/hdf5/Hdf5TreeModel.py +++ b/src/silx/gui/hdf5/Hdf5TreeModel.py @@ -72,7 +72,7 @@ class LoadingItemRunnable(qt.QRunnable): class __Signals(qt.QObject): """Signal holder""" - itemReady = qt.Signal(object, object, object) + itemReady = qt.Signal(object, object, object, str) runnerFinished = qt.Signal(object) def __init__(self, filename, item): @@ -129,7 +129,7 @@ def run(self): if h5file is not None: h5file.close() - self.itemReady.emit(self.oldItem, newItem, error) + self.itemReady.emit(self.oldItem, newItem, error, self.filename) self.runnerFinished.emit(self) def autoDelete(self): @@ -184,7 +184,7 @@ class Hdf5TreeModel(qt.QAbstractItemModel): ] """List of logical columns available""" - sigH5pyObjectLoaded = qt.Signal(object) + sigH5pyObjectLoaded = qt.Signal(object, str) """Emitted when a new root item was loaded and inserted to the model.""" sigH5pyObjectRemoved = qt.Signal(object) @@ -269,14 +269,21 @@ def __updateLoadingItems(self, icon): index2 = self.index(i, self.columnCount() - 1, qt.QModelIndex()) self.dataChanged.emit(index1, index2) - def __itemReady(self, oldItem, newItem, error): + def __itemReady( + self, + oldItem: Hdf5Node, + newItem: Optional[Hdf5Node], + error: Optional[Exception], + filename: str, + ): """Called at the end of a concurent file loading, when the loading item is ready. AN error is defined if an exception occured when loading the newItem . - :param Hdf5Node oldItem: current displayed item - :param Hdf5Node newItem: item loaded, or None if error is defined - :param Exception error: An exception, or None if newItem is defined + :param oldItem: current displayed item + :param newItem: item loaded, or None if error is defined + :param error: An exception, or None if newItem is defined + :param filename: The filename used to load the new item """ row = self.__root.indexOfChild(oldItem) @@ -294,7 +301,7 @@ def __itemReady(self, oldItem, newItem, error): self.endInsertRows() if isinstance(oldItem, Hdf5LoadingItem): - self.sigH5pyObjectLoaded.emit(newItem.obj) + self.sigH5pyObjectLoaded.emit(newItem.obj, filename) else: self.sigH5pyObjectSynchronized.emit(oldItem.obj, newItem.obj) @@ -703,7 +710,7 @@ def insertFile(self, filename, row=-1): h5file = silx_io.open(filename) if self.__ownFiles: self.__openedFiles.append(h5file) - self.sigH5pyObjectLoaded.emit(h5file) + self.sigH5pyObjectLoaded.emit(h5file, filename) self.insertH5pyObject(h5file, row=row, filename=filename) except IOError: _logger.debug("File '%s' can't be read.", filename, exc_info=True) From a0f5535ccbeb05f8c3a7cfe6f87af54be6f9a4e0 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 23 Oct 2023 13:20:16 +0200 Subject: [PATCH 2/4] Display data at startup even when selecting a dataset --- src/silx/app/view/Viewer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/silx/app/view/Viewer.py b/src/silx/app/view/Viewer.py index 327e86e76e..1503963a00 100644 --- a/src/silx/app/view/Viewer.py +++ b/src/silx/app/view/Viewer.py @@ -453,9 +453,9 @@ def __createCustomNxdataWindow(self, customNxdataWidget): layout.addWidget(customNxdataWidget) return widget - def __h5FileLoaded(self, loadedH5): + def __h5FileLoaded(self, loadedH5, filename): self.__context.pushRecentFile(loadedH5.file.filename) - if loadedH5.file.filename == self.__displayIt: + if filename == self.__displayIt: self.__displayIt = None self.displayData(loadedH5) From 3dd67606f0fc2aa0f85e27a77a883083df9c731f Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 23 Oct 2023 13:36:49 +0200 Subject: [PATCH 3/4] update test --- src/silx/gui/hdf5/test/test_hdf5.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/silx/gui/hdf5/test/test_hdf5.py b/src/silx/gui/hdf5/test/test_hdf5.py index d08e3bcbb3..b554fb5be8 100755 --- a/src/silx/gui/hdf5/test/test_hdf5.py +++ b/src/silx/gui/hdf5/test/test_hdf5.py @@ -1,6 +1,6 @@ # /*########################################################################## # -# Copyright (c) 2016-2021 European Synchrotron Radiation Facility +# Copyright (c) 2016-2023 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -40,6 +40,7 @@ from silx.gui.utils.testutils import SignalListener from silx.io import commonh5 from silx.io import h5py_utils +from silx.io.url import DataUrl import weakref import h5py @@ -400,11 +401,17 @@ def testInsert(self): self.assertEqual(self.listener.callCount(), 0) def testLoaded(self): - self.model.insertFile(self.filename) - self.assertEqual(self.listener.callCount(), 1) - self.assertEqual(self.listener.karguments(argumentName="signal")[0], "loaded") - self.assertIsNot(self.listener.arguments(callIndex=0)[0], self.h5) - self.assertEqual(self.listener.arguments(callIndex=0)[0].filename, self.filename) + for data_path in [None, "/arrays/scalar"]: + with self.subTest(data_path=data_path): + url = DataUrl(file_path=self.filename, data_path=data_path) + insertedFilename = url.path() + self.model.insertFile(insertedFilename) + self.assertEqual(self.listener.callCount(), 1) + self.assertEqual(self.listener.karguments(argumentName="signal")[0], "loaded") + self.assertIsNot(self.listener.arguments(callIndex=0)[0], self.h5) + self.assertEqual(self.listener.arguments(callIndex=0)[0].file.filename, self.filename) + self.assertEqual(self.listener.arguments(callIndex=0)[1], insertedFilename) + self.listener.clear() def testRemoved(self): self.model.removeH5pyObject(self.h5) From bec66e683dc427bad8135588c3db9e6678009fa5 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 23 Oct 2023 13:37:00 +0200 Subject: [PATCH 4/4] remove log message leading to exception for h5py Dataset --- src/silx/gui/hdf5/Hdf5TreeModel.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/silx/gui/hdf5/Hdf5TreeModel.py b/src/silx/gui/hdf5/Hdf5TreeModel.py index 1e9e3636b9..8d15702ec7 100644 --- a/src/silx/gui/hdf5/Hdf5TreeModel.py +++ b/src/silx/gui/hdf5/Hdf5TreeModel.py @@ -250,7 +250,6 @@ def _closeFileList(fileList): """Static method to close explicit references to internal objects.""" _logger.debug("Clear Hdf5TreeModel") for obj in fileList: - _logger.debug("Close file %s", obj.filename) obj.close() fileList[:] = []