Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/silx/app/view/Viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,20 @@ def __init__(self, parent=None, settings=None):

self.__dialogState = None
self.__customNxDataItem = None
self.__treeview = silx.gui.hdf5.Hdf5TreeView(self)

# Custom the model to be able to manage the life cycle of the files
self.__treeModelSorted = silx.gui.hdf5.NexusSortFilterProxyModel(self)
self.__treeModelSorted.sort(0, qt.Qt.AscendingOrder)
self.__treeModelSorted.setSortCaseSensitivity(qt.Qt.CaseInsensitive)

treeModel = silx.gui.hdf5.Hdf5TreeModel(self.__treeModelSorted, ownFiles=False)
treeModel.sigH5pyObjectLoaded.connect(self.__h5FileLoaded)
treeModel.sigH5pyObjectRemoved.connect(self.__h5FileRemoved)
treeModel.sigH5pyObjectSynchronized.connect(self.__h5FileSynchonized)
treeModel.setDatasetDragEnabled(True)
self.__treeModelSorted.setSourceModel(treeModel)

self.__treeview = silx.gui.hdf5.Hdf5TreeView(self, model=self.__treeModelSorted)
self.__treeview.setExpandsOnDoubleClick(False)
"""Silx HDF5 TreeView"""

Expand All @@ -85,21 +98,6 @@ def __init__(self, parent=None, settings=None):

self.__displayIt = None
self.__treeWindow = self.__createTreeWindow(self.__treeview)

# Custom the model to be able to manage the life cycle of the files
treeModel = silx.gui.hdf5.Hdf5TreeModel(self.__treeview, ownFiles=False)
treeModel.sigH5pyObjectLoaded.connect(self.__h5FileLoaded)
treeModel.sigH5pyObjectRemoved.connect(self.__h5FileRemoved)
treeModel.sigH5pyObjectSynchronized.connect(self.__h5FileSynchonized)
treeModel.setDatasetDragEnabled(True)
self.__treeModelSorted = silx.gui.hdf5.NexusSortFilterProxyModel(
self.__treeview
)
self.__treeModelSorted.setSourceModel(treeModel)
self.__treeModelSorted.sort(0, qt.Qt.AscendingOrder)
self.__treeModelSorted.setSortCaseSensitivity(qt.Qt.CaseInsensitive)

self.__treeview.setModel(self.__treeModelSorted)
rightPanel.addWidget(self.__treeWindow)

self.__customNxdata = CustomNxdataWidget(self)
Expand Down
2 changes: 1 addition & 1 deletion src/silx/gui/dialog/AbstractDataFileDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def _init(self):
self.__fileModel.setReadOnly(True)
self.__fileModel.directoryLoaded.connect(self.__directoryLoaded)

self.__dataModel = Hdf5TreeModel(self)
self.__dataModel = Hdf5TreeModel(self, ownFiles=False)

self.__createWidgets()
self.__initLayout()
Expand Down
17 changes: 9 additions & 8 deletions src/silx/gui/hdf5/Hdf5TreeModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,15 @@ def __init__(self, parent=None, ownFiles=True):
"""Store the list of files opened by the model itself."""
# FIXME: It should be managed one by one by Hdf5Item itself

# It is not possible to override the QObject destructor nor
# to access to the content of the Python object with the `destroyed`
# signal cause the Python method was already removed with the QWidget,
# while the QObject still exists.
# We use a static method plus explicit references to objects to
# release. The callback do not use any ref to self.
onDestroy = functools.partial(self._closeFileList, self.__openedFiles)
self.destroyed.connect(onDestroy)
if self.__ownFiles:
# It is not possible to override the QObject destructor nor
# to access to the content of the Python object with the `destroyed`
# signal cause the Python method was already removed with the QWidget,
# while the QObject still exists.
# We use a static method plus explicit references to objects to
# release. The callback do not use any ref to self.
onDestroy = functools.partial(self._closeFileList, self.__openedFiles)
self.destroyed.connect(onDestroy)

@staticmethod
def _closeFileList(fileList):
Expand Down
9 changes: 7 additions & 2 deletions src/silx/gui/hdf5/Hdf5TreeView.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,20 @@ class Hdf5TreeView(qt.QTreeView):
to the selected objects.
"""

def __init__(self, parent=None):
def __init__(
self,
parent: qt.QWidget | None = None,
model: Hdf5TreeModel | qt.QAbstractProxyModel | None = None,
):
"""
Constructor

:param parent qt.QWidget: The parent widget
"""
qt.QTreeView.__init__(self, parent)

model = self.createDefaultModel()
if model is None:
model = self.createDefaultModel()
self.setModel(model)

self.setHeader(Hdf5HeaderView(qt.Qt.Horizontal, self))
Expand Down
Loading