From 20e4e617c8a0db723d5a1cf100297d11e60b00d8 Mon Sep 17 00:00:00 2001 From: Rebelo Alexis Date: Fri, 14 Jun 2024 13:24:47 +0200 Subject: [PATCH 01/10] Adding docstring and type --- .../app/view/CustomPlotSelectionWindow.py | 121 ++++++++++++++++-- 1 file changed, 112 insertions(+), 9 deletions(-) diff --git a/src/silx/app/view/CustomPlotSelectionWindow.py b/src/silx/app/view/CustomPlotSelectionWindow.py index 8a2d68d938..58ea373375 100644 --- a/src/silx/app/view/CustomPlotSelectionWindow.py +++ b/src/silx/app/view/CustomPlotSelectionWindow.py @@ -20,6 +20,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # ###########################################################################*/ +from __future__ import annotations """""" @@ -38,10 +39,10 @@ class _HashDropZones(qt.QStyledItemDelegate): """Delegate item displaying a drop zone when the item does not contain a dataset.""" - def __init__(self, parent=None): + def __init__(self, parent: qt.QWidget | None = None): super(_HashDropZones, self).__init__(parent) self.__dropPen = qt.QPen(qt.QColor("#D0D0D0"), 2, qt.Qt.DotLine) - self.__highlightDropPen = qt.QPen(qt.QColor("#000000"), 2, qt.Qt.SolidLine) + self.__highlightDropPen = qt.QPen(qt.QColor("#000000"), 2, qt.Qt.DotLine) self.__dropTargetIndex = None def paint(self, painter, option, index): @@ -66,7 +67,7 @@ def paint(self, painter, option, index): if isDropHighlighted: painter.save() painter.setPen(self.__highlightDropPen) - painter.drawRect(option.rect.adjusted(1, 1, -1, -1)) + painter.drawRect(option.rect.adjusted(3, 3, -3, -3)) painter.restore() if displayDropZone: @@ -97,6 +98,12 @@ def paint(self, painter, option, index): class _FileListModel(qt.QStandardItemModel): + """ + A model class for managing and displaying file data in a tree view structure + + :param plot : Plot 1D + """ + def __init__(self, plot, parent=None): super().__init__(parent) root = self.invisibleRootItem() @@ -124,13 +131,23 @@ def __init__(self, plot, parent=None): self.rowsAboutToBeRemoved.connect(self._rowAboutToBeRemoved) - def getXParent(self): + def getXParent(self) -> qt.QStandardItem: + """Returns the X parent item.""" return self._xParent def getYParent(self): + """Returns the Y parent item. + + :rtype: qt.QStandardItem + """ return self._yParent def _setXFile(self, url=None, curve=None): + """Set X file informations to the model + + :param str filename: The file name. + :param curve: The curve data. Defaults to None. + """ if url is None: dataName = "" else: @@ -148,6 +165,10 @@ def _setXFile(self, url=None, curve=None): self.setItem(xIndex, 2, removeItem) def _addYFile(self, url=None, curve=None, node="X"): + """Add Y file to the model + + :param curve : The curve data. Defaults to None. + """ if url is None: dataName = "" else: @@ -167,6 +188,11 @@ def _addYFile(self, url=None, curve=None, node="X"): ) def _findRowContainingText(self, text): + """Find the row containing the specified text. + + :param str text: The text to search for. + """ + for row in range(self.rowCount()): item = self.item(row, 0) if item and item.text() == text: @@ -174,6 +200,11 @@ def _findRowContainingText(self, text): return None def _createRowItems(self, filename, curve): + """Create row items for the file. + + :param str filename : The file name. + :param Curve curve : The curve data + """ fileItem = qt.QStandardItem(filename) fileItem.setData(curve, qt.Qt.UserRole) fileItem.setData(False, _DROP_HIGHLIGHT_ROLE) @@ -187,6 +218,10 @@ def _createRowItems(self, filename, curve): return fileItem, iconItem, removeItem def fileItemExists(self, filename): + """Check if the file already exists in the model. + + :param str filename : The file name. + """ for row in range(self.getYParent().rowCount()): item = self.item(row, 1) if item and item.text() == filename: @@ -194,6 +229,12 @@ def fileItemExists(self, filename): return False def addUrl(self, url, node="X"): + """Add a URL to the model. + + :param url : The data URL. + :param node : The node name. Defaults to "X". + """ + if url.file_path() is not None: file = silx.io.open(url.file_path()) data = file[url.data_path()] @@ -215,7 +256,12 @@ def addUrl(self, url, node="X"): curve = self._addPlot(self._xDataset, data) self._addYFile(url, curve) - def _addPlot(self, x, y): + def _addPlot(self, x: numpy.ndarray, y): + """Add a curve to the plot + + :param x: + :param y: + """ if x is None: x = numpy.arange(len(y)) @@ -228,6 +274,12 @@ def _addPlot(self, x, y): return curve def _rowAboutToBeRemoved(self, parentIndex, first, last): + """Handle the event when rows are about to be removed. + + :param parentIndex : the parent index. + :param int first : the first row to be removed. + :param int last : the last row to be removed. + """ parentItem = self.itemFromIndex(parentIndex) for row in range(first, last + 1): fileItem = parentItem.child(row, 1) @@ -236,6 +288,7 @@ def _rowAboutToBeRemoved(self, parentIndex, first, last): self._plot1D.removeItem(curve) def _updateYCurvesWithDefaultX(self): + """Update Y curves with default X values""" for item in self._plot1D.getItems(): y = item.getInfo() x = numpy.arange(len(y)) @@ -243,6 +296,7 @@ def _updateYCurvesWithDefaultX(self): self._plot1D.resetZoom() def clearAll(self): + """Clear all data from the model""" self._xDataset = None self._yParent.removeRows(0, self._yParent.rowCount()) @@ -280,11 +334,15 @@ def _getBasename(self, text): class _DropTreeView(qt.QTreeView): - """TreeView widget for displaying dropped file names""" + """TreeView widget for displaying dropped file names + + :param model : _FileListModel + """ (_DESCRIPTION_COLUMN, _FILE_COLUMN, _REMOVE_COLUMN) = range(3) def __init__(self, model, parent=None): + """Constructor""" super().__init__(parent) self.setModel(model) @@ -292,9 +350,13 @@ def __init__(self, model, parent=None): header = self.header() header.setStretchLastSection(False) - header.setSectionResizeMode(0, qt.QHeaderView.ResizeToContents) - header.setSectionResizeMode(1, qt.QHeaderView.Stretch) - header.setSectionResizeMode(2, qt.QHeaderView.ResizeToContents) + header.setSectionResizeMode( + _DropTreeView._DESCRIPTION_COLUMN, qt.QHeaderView.ResizeToContents + ) + header.setSectionResizeMode(_DropTreeView._FILE_COLUMN, qt.QHeaderView.Stretch) + header.setSectionResizeMode( + _DropTreeView._REMOVE_COLUMN, qt.QHeaderView.ResizeToContents + ) self.expandAll() self.setSelectionMode(qt.QAbstractItemView.SingleSelection) @@ -307,6 +369,11 @@ def __init__(self, model, parent=None): self.viewport().setAcceptDrops(True) def _createIconWidget(self, row, parentItem): + """Create an icon widget for the specified row. + + :param row : The row index. + :param parentItem : The parent item. + """ fileItem = parentItem.child(row, 1) iconItem = parentItem.child(row, 0) curve = fileItem.data(qt.Qt.UserRole) @@ -321,6 +388,11 @@ def _createIconWidget(self, row, parentItem): self.setIndexWidget(iconItem.index(), widget) def _createRemoveButton(self, row, parentItem): + """Create an remove button for the specified row. + + :param row : The row index. + :param parentItem : The parent item + """ if parentItem is None: parentItem = self.model().getXParent() index = self.model().index(0, 2) @@ -342,6 +414,11 @@ def _createRemoveButton(self, row, parentItem): self.setIndexWidget(removeItem.index(), button) def _removeFile(self, removeItem, parentItem): + """Remove the specified file from the model. + + :param removeItem : The item to be removed. + :param parentItem : The parent item. + """ if removeItem is None: row = 0 removeItem = self.model().getXParent() @@ -399,6 +476,7 @@ def dropEvent(self, event): event.acceptProposedAction() def acceptDragEvent(self, event): + """Accept the drop event if the data is valid.""" if event.mimeData().hasFormat("application/x-silx-uri"): byteString = event.mimeData().data("application/x-silx-uri") url = silx.io.url.DataUrl(byteString.data().decode("utf-8")) @@ -414,6 +492,10 @@ def acceptDragEvent(self, event): event.ignore() def setX(self, url): + """Set the X data from the URL. + + :param url : The data URL. + """ targetNode = "X" node = self.model().getXParent() self.model().addUrl(url, targetNode) @@ -421,6 +503,10 @@ def setX(self, url): self.model()._plot1D.resetZoom() def addY(self, url): + """Add the Y data from the URL. + + :param url : The data URL. + """ targetNode = "Y" node = self.model().getYParent() self.model().addUrl(url, targetNode) @@ -429,11 +515,15 @@ def addY(self, url): self.model()._plot1D.resetZoom() def clear(self): + """Clear all data from the tree view.""" self.model().clearAll() index = self.model().index(0, 2) self.setIndexWidget(index, None) def setDropHighlight(self, value): + """Set the drop highlight for the specified value. + + :param value : The value to highlight ("X" or "Y")""" xDropFileItem = self.model().itemFromIndex( self.model().sibling( 0, 1, self.model().indexFromItem(self.model().getXParent()) @@ -447,12 +537,19 @@ def setDropHighlight(self, value): class _DropPlot1D(plot.Plot1D): + """A plot widget with drag-and-drop functionality for adding data.""" + def __init__(self, parent=None): + """Constructor""" super().__init__(parent) self.setAcceptDrops(True) self._treeView = None def setTreeView(self, treeView): + """Set the tree view for the plot. + + :param treeview : + """ self._treeView = treeView def dragEnterEvent(self, event): @@ -485,10 +582,16 @@ def setXAxisLabel(self, label): class _PlotToolBar(qt.QToolBar): + """""" + def __init__(self, parent=None): super().__init__(parent) def addClearAction(self, treeView): + """Add a clear action to the ToolBar + + :param treeview : + """ icon = self.style().standardIcon(qt.QStyle.SP_TrashIcon) clearAction = qt.QAction(icon, "Clear All", self) clearAction.triggered.connect(treeView.clear) From 8533a204bfe658afbaf462144585612bb2de041e Mon Sep 17 00:00:00 2001 From: Rebelo Alexis Date: Tue, 18 Jun 2024 15:25:01 +0200 Subject: [PATCH 02/10] Adding docString and type --- .../app/view/CustomPlotSelectionWindow.py | 199 +++++++----------- 1 file changed, 73 insertions(+), 126 deletions(-) diff --git a/src/silx/app/view/CustomPlotSelectionWindow.py b/src/silx/app/view/CustomPlotSelectionWindow.py index 58ea373375..cae5b2ed17 100644 --- a/src/silx/app/view/CustomPlotSelectionWindow.py +++ b/src/silx/app/view/CustomPlotSelectionWindow.py @@ -20,19 +20,22 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # ###########################################################################*/ -from __future__ import annotations -"""""" +"""Custom plot selection window for selecting 1D datasets to plot.""" from silx.gui import qt, plot, icons +import silx.gui +import silx.gui.plot +import silx.gui.plot.items import silx.io import numpy import functools from silx.gui.plot.LegendSelector import LegendIcon +import silx.io.url import silx.io.utils from silx.gui.hdf5 import _utils - +# Custom role for highlighting the drop zones _DROP_HIGHLIGHT_ROLE = qt.Qt.UserRole + 1 @@ -42,7 +45,7 @@ class _HashDropZones(qt.QStyledItemDelegate): def __init__(self, parent: qt.QWidget | None = None): super(_HashDropZones, self).__init__(parent) self.__dropPen = qt.QPen(qt.QColor("#D0D0D0"), 2, qt.Qt.DotLine) - self.__highlightDropPen = qt.QPen(qt.QColor("#000000"), 2, qt.Qt.DotLine) + self.__highlightDropPen = qt.QPen(qt.QColor("#000000"), 2, qt.Qt.SolidLine) self.__dropTargetIndex = None def paint(self, painter, option, index): @@ -67,7 +70,7 @@ def paint(self, painter, option, index): if isDropHighlighted: painter.save() painter.setPen(self.__highlightDropPen) - painter.drawRect(option.rect.adjusted(3, 3, -3, -3)) + painter.drawRect(option.rect.adjusted(1, 1, -1, -1)) painter.restore() if displayDropZone: @@ -98,11 +101,7 @@ def paint(self, painter, option, index): class _FileListModel(qt.QStandardItemModel): - """ - A model class for managing and displaying file data in a tree view structure - - :param plot : Plot 1D - """ + """Model for displaying dropped file names in a TreeView widget""" def __init__(self, plot, parent=None): super().__init__(parent) @@ -129,25 +128,18 @@ def __init__(self, plot, parent=None): self.addUrl(silx.io.url.DataUrl()) - self.rowsAboutToBeRemoved.connect(self._rowAboutToBeRemoved) + self.rowsAboutToBeRemoved.connect(self._rowsAboutToBeRemoved) def getXParent(self) -> qt.QStandardItem: - """Returns the X parent item.""" + """Return the parent item for the X dataset""" return self._xParent - def getYParent(self): - """Returns the Y parent item. - - :rtype: qt.QStandardItem - """ + def getYParent(self) -> qt.QStandardItem: + """Return the parent item for the Y datasets""" return self._yParent - def _setXFile(self, url=None, curve=None): - """Set X file informations to the model - - :param str filename: The file name. - :param curve: The curve data. Defaults to None. - """ + def _setXFile(self, url: silx.io.url.DataUrl | None = None, curve: None = None): + """Set the X dataset file in the model""" if url is None: dataName = "" else: @@ -164,17 +156,19 @@ def _setXFile(self, url=None, curve=None): self.setItem(xIndex, 1, fileItem) self.setItem(xIndex, 2, removeItem) - def _addYFile(self, url=None, curve=None, node="X"): - """Add Y file to the model - - :param curve : The curve data. Defaults to None. - """ + def _addYFile( + self, + url: silx.io.url.DataUrl | None = None, + curve: silx.gui.plot.items.Curve | None = None, + ): + """Add a Y dataset file to the model""" if url is None: dataName = "" else: dataName = self._getBasename(url.data_path()) fileItem, iconItem, removeItem = self._createRowItems(dataName, curve) if not dataName: + # provide size hint for 'empty' item fileItem.setData(qt.QSize(0, 30), qt.Qt.SizeHintRole) fileItem.setData(self._createToolTip(url), qt.Qt.ToolTipRole) @@ -187,24 +181,18 @@ def _addYFile(self, url=None, curve=None, node="X"): self.getYParent().rowCount() - 1, [iconItem, fileItem, removeItem] ) - def _findRowContainingText(self, text): - """Find the row containing the specified text. - - :param str text: The text to search for. - """ - + def _findRowContainingText(self, text: str) -> int | None: + """Return the row index containing the given text, or None if not found.""" for row in range(self.rowCount()): item = self.item(row, 0) if item and item.text() == text: return row return None - def _createRowItems(self, filename, curve): - """Create row items for the file. - - :param str filename : The file name. - :param Curve curve : The curve data - """ + def _createRowItems( + self, filename: str, curve: silx.gui.plot.items.Curve + ) -> tuple[qt.QStandardItem, qt.QStandardItem, qt.QStandardItem]: + """Create the items for a row in the model""" fileItem = qt.QStandardItem(filename) fileItem.setData(curve, qt.Qt.UserRole) fileItem.setData(False, _DROP_HIGHLIGHT_ROLE) @@ -217,24 +205,16 @@ def _createRowItems(self, filename, curve): return fileItem, iconItem, removeItem - def fileItemExists(self, filename): - """Check if the file already exists in the model. - - :param str filename : The file name. - """ + def fileItemExists(self, filename: str) -> bool: + """Return if a file item with the given filename exists in the model for the Y datasets.""" for row in range(self.getYParent().rowCount()): item = self.item(row, 1) if item and item.text() == filename: return True return False - def addUrl(self, url, node="X"): - """Add a URL to the model. - - :param url : The data URL. - :param node : The node name. Defaults to "X". - """ - + def addUrl(self, url: silx.io.url.DataUrl, node: str = "X"): + """Add a dataset to the model""" if url.file_path() is not None: file = silx.io.open(url.file_path()) data = file[url.data_path()] @@ -256,12 +236,10 @@ def addUrl(self, url, node="X"): curve = self._addPlot(self._xDataset, data) self._addYFile(url, curve) - def _addPlot(self, x: numpy.ndarray, y): - """Add a curve to the plot - - :param x: - :param y: - """ + def _addPlot( + self, x: numpy.ndarray | None, y: numpy.ndarray + ) -> silx.gui.plot.items.Curve: + """Add a curve to the plot with the given x and y data.""" if x is None: x = numpy.arange(len(y)) @@ -273,13 +251,8 @@ def _addPlot(self, x: numpy.ndarray, y): curve.setInfo(y[()]) return curve - def _rowAboutToBeRemoved(self, parentIndex, first, last): - """Handle the event when rows are about to be removed. - - :param parentIndex : the parent index. - :param int first : the first row to be removed. - :param int last : the last row to be removed. - """ + def _rowsAboutToBeRemoved(self, parentIndex: qt.QModelIndex, first: int, last: int): + """Remove the curves from the plot when a row is removed from the model.""" parentItem = self.itemFromIndex(parentIndex) for row in range(first, last + 1): fileItem = parentItem.child(row, 1) @@ -288,7 +261,7 @@ def _rowAboutToBeRemoved(self, parentIndex, first, last): self._plot1D.removeItem(curve) def _updateYCurvesWithDefaultX(self): - """Update Y curves with default X values""" + """Update the Y curves with the default X dataset.""" for item in self._plot1D.getItems(): y = item.getInfo() x = numpy.arange(len(y)) @@ -296,7 +269,7 @@ def _updateYCurvesWithDefaultX(self): self._plot1D.resetZoom() def clearAll(self): - """Clear all data from the model""" + """Clear all datasets from the model and the plot.""" self._xDataset = None self._yParent.removeRows(0, self._yParent.rowCount()) @@ -311,6 +284,7 @@ def clearAll(self): self._updateYCurvesWithDefaultX() def _reset(self): + """Reset the model to its initial state.""" self._xDataset = None self._setXFile() @@ -334,15 +308,11 @@ def _getBasename(self, text): class _DropTreeView(qt.QTreeView): - """TreeView widget for displaying dropped file names - - :param model : _FileListModel - """ + """TreeView widget for displaying dropped file names""" (_DESCRIPTION_COLUMN, _FILE_COLUMN, _REMOVE_COLUMN) = range(3) def __init__(self, model, parent=None): - """Constructor""" super().__init__(parent) self.setModel(model) @@ -350,13 +320,9 @@ def __init__(self, model, parent=None): header = self.header() header.setStretchLastSection(False) - header.setSectionResizeMode( - _DropTreeView._DESCRIPTION_COLUMN, qt.QHeaderView.ResizeToContents - ) - header.setSectionResizeMode(_DropTreeView._FILE_COLUMN, qt.QHeaderView.Stretch) - header.setSectionResizeMode( - _DropTreeView._REMOVE_COLUMN, qt.QHeaderView.ResizeToContents - ) + header.setSectionResizeMode(0, qt.QHeaderView.ResizeToContents) + header.setSectionResizeMode(1, qt.QHeaderView.Stretch) + header.setSectionResizeMode(2, qt.QHeaderView.ResizeToContents) self.expandAll() self.setSelectionMode(qt.QAbstractItemView.SingleSelection) @@ -368,12 +334,8 @@ def __init__(self, model, parent=None): self.setDragEnabled(False) self.viewport().setAcceptDrops(True) - def _createIconWidget(self, row, parentItem): - """Create an icon widget for the specified row. - - :param row : The row index. - :param parentItem : The parent item. - """ + def _createIconWidget(self, row: int, parentItem: qt.QStandardItem): + """Create the icon widget for a row in the model""" fileItem = parentItem.child(row, 1) iconItem = parentItem.child(row, 0) curve = fileItem.data(qt.Qt.UserRole) @@ -387,12 +349,10 @@ def _createIconWidget(self, row, parentItem): layout.setContentsMargins(4, 0, 4, 0) self.setIndexWidget(iconItem.index(), widget) - def _createRemoveButton(self, row, parentItem): - """Create an remove button for the specified row. + def _createRemoveButton(self, row: int, parentItem: qt.QStandardItem | None): + """Create the remove button for a row in the model""" - :param row : The row index. - :param parentItem : The parent item - """ + # If the parentItem is None, the remove button is for the X dataset if parentItem is None: parentItem = self.model().getXParent() index = self.model().index(0, 2) @@ -404,6 +364,7 @@ def _createRemoveButton(self, row, parentItem): self.setIndexWidget(index, button) return + # If the parentItem is not None, the remove button is for a Y dataset removeItem = parentItem.child(row, 2) if removeItem: button = qt.QToolButton(self) @@ -413,12 +374,12 @@ def _createRemoveButton(self, row, parentItem): ) self.setIndexWidget(removeItem.index(), button) - def _removeFile(self, removeItem, parentItem): - """Remove the specified file from the model. + def _removeFile( + self, removeItem: qt.QStandardItem | None, parentItem: qt.QStandardItem + ): + """Remove a file from the model and the plot.""" - :param removeItem : The item to be removed. - :param parentItem : The parent item. - """ + # If removeItem is None, the file to remove is the X dataset if removeItem is None: row = 0 removeItem = self.model().getXParent() @@ -426,6 +387,7 @@ def _removeFile(self, removeItem, parentItem): if removeItem: row = removeItem.row() + # If the parentItem is None, the file to remove is the X dataset if parentItem is None: parentItem = self.model().getXParent() @@ -476,7 +438,8 @@ def dropEvent(self, event): event.acceptProposedAction() def acceptDragEvent(self, event): - """Accept the drop event if the data is valid.""" + """Accept the drag event if the mime data contains a 1D dataset.""" + if event.mimeData().hasFormat("application/x-silx-uri"): byteString = event.mimeData().data("application/x-silx-uri") url = silx.io.url.DataUrl(byteString.data().decode("utf-8")) @@ -491,22 +454,16 @@ def acceptDragEvent(self, event): else: event.ignore() - def setX(self, url): - """Set the X data from the URL. - - :param url : The data URL. - """ + def setX(self, url: silx.io.url.DataUrl): + """Set the X dataset in the model and the plot.""" targetNode = "X" node = self.model().getXParent() self.model().addUrl(url, targetNode) self._createRemoveButton(node, None) self.model()._plot1D.resetZoom() - def addY(self, url): - """Add the Y data from the URL. - - :param url : The data URL. - """ + def addY(self, url: silx.io.url.DataUrl): + """Add a Y dataset to the model and the plot.""" targetNode = "Y" node = self.model().getYParent() self.model().addUrl(url, targetNode) @@ -515,15 +472,13 @@ def addY(self, url): self.model()._plot1D.resetZoom() def clear(self): - """Clear all data from the tree view.""" + """Clear all datasets from the model and the plot.""" self.model().clearAll() index = self.model().index(0, 2) self.setIndexWidget(index, None) - def setDropHighlight(self, value): - """Set the drop highlight for the specified value. - - :param value : The value to highlight ("X" or "Y")""" + def setDropHighlight(self, value: str | None): + """Set the drop highlight for the X and Y datasets.""" xDropFileItem = self.model().itemFromIndex( self.model().sibling( 0, 1, self.model().indexFromItem(self.model().getXParent()) @@ -537,19 +492,15 @@ def setDropHighlight(self, value): class _DropPlot1D(plot.Plot1D): - """A plot widget with drag-and-drop functionality for adding data.""" + """Plot1D widget for displaying 1D datasets that can accept drops.""" def __init__(self, parent=None): - """Constructor""" super().__init__(parent) self.setAcceptDrops(True) self._treeView = None - def setTreeView(self, treeView): - """Set the tree view for the plot. - - :param treeview : - """ + def setTreeView(self, treeView: qt.QTreeView): + """Set the TreeView widget for the plot.""" self._treeView = treeView def dragEnterEvent(self, event): @@ -576,22 +527,18 @@ def dropEvent(self, event): self.resetZoom() event.acceptProposedAction() - def setXAxisLabel(self, label): + def setXAxisLabel(self, label: str): + """Set the label for the X axis.""" xAxis = self.getXAxis() xAxis.setLabel(label) class _PlotToolBar(qt.QToolBar): - """""" - def __init__(self, parent=None): super().__init__(parent) - def addClearAction(self, treeView): - """Add a clear action to the ToolBar - - :param treeview : - """ + def addClearAction(self, treeView: qt.QTreeView): + """Add the clear action to the toolbar.""" icon = self.style().standardIcon(qt.QStyle.SP_TrashIcon) clearAction = qt.QAction(icon, "Clear All", self) clearAction.triggered.connect(treeView.clear) From 487f56dabd12d419ee036928122e8ebaa6cc6479 Mon Sep 17 00:00:00 2001 From: Rebelo Alexis Date: Wed, 19 Jun 2024 15:05:03 +0200 Subject: [PATCH 03/10] Added missing doc --- src/silx/app/view/CustomPlotSelectionWindow.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/silx/app/view/CustomPlotSelectionWindow.py b/src/silx/app/view/CustomPlotSelectionWindow.py index cae5b2ed17..86a653a2e7 100644 --- a/src/silx/app/view/CustomPlotSelectionWindow.py +++ b/src/silx/app/view/CustomPlotSelectionWindow.py @@ -293,7 +293,8 @@ def _reset(self): self._plot1D.clear() self._updateYCurvesWithDefaultX() - def _createToolTip(self, url): + def _createToolTip(self, url: silx.io.url.DataUrl) -> str: + """Create the tooltip for a dataset.""" if url is None: return "" attrs = { @@ -303,7 +304,8 @@ def _createToolTip(self, url): } return _utils.htmlFromDict(attrs, title="HDF5 Dataset") - def _getBasename(self, text): + def _getBasename(self, text: str) -> str: + """Return the basename of a file path.""" return text.split("/")[-1] From 4f5dc39d89b30eab77413a910cedebae75ffcd25 Mon Sep 17 00:00:00 2001 From: Rebelo Alexis <102356226+RebeloAlexis@users.noreply.github.com> Date: Wed, 19 Jun 2024 15:06:48 +0200 Subject: [PATCH 04/10] Update src/silx/app/view/CustomPlotSelectionWindow.py Co-authored-by: Thomas VINCENT --- src/silx/app/view/CustomPlotSelectionWindow.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/silx/app/view/CustomPlotSelectionWindow.py b/src/silx/app/view/CustomPlotSelectionWindow.py index 86a653a2e7..2e0638bd04 100644 --- a/src/silx/app/view/CustomPlotSelectionWindow.py +++ b/src/silx/app/view/CustomPlotSelectionWindow.py @@ -21,6 +21,7 @@ # THE SOFTWARE. # ###########################################################################*/ +from __future__ import annotations """Custom plot selection window for selecting 1D datasets to plot.""" from silx.gui import qt, plot, icons From 1d58794d6b8c279d928c2b2060f7564979456f46 Mon Sep 17 00:00:00 2001 From: Rebelo Alexis <102356226+RebeloAlexis@users.noreply.github.com> Date: Wed, 19 Jun 2024 15:11:35 +0200 Subject: [PATCH 05/10] Update src/silx/app/view/CustomPlotSelectionWindow.py Co-authored-by: Thomas VINCENT --- src/silx/app/view/CustomPlotSelectionWindow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/silx/app/view/CustomPlotSelectionWindow.py b/src/silx/app/view/CustomPlotSelectionWindow.py index 2e0638bd04..ded8985581 100644 --- a/src/silx/app/view/CustomPlotSelectionWindow.py +++ b/src/silx/app/view/CustomPlotSelectionWindow.py @@ -207,7 +207,7 @@ def _createRowItems( return fileItem, iconItem, removeItem def fileItemExists(self, filename: str) -> bool: - """Return if a file item with the given filename exists in the model for the Y datasets.""" + """Return True if a file item with the given filename exists in the Y datasets of the model.""" for row in range(self.getYParent().rowCount()): item = self.item(row, 1) if item and item.text() == filename: From 84eb170e7ab56eaf78313578d27dfb8eb243bbb3 Mon Sep 17 00:00:00 2001 From: Rebelo Alexis <102356226+RebeloAlexis@users.noreply.github.com> Date: Wed, 19 Jun 2024 15:12:00 +0200 Subject: [PATCH 06/10] Update src/silx/app/view/CustomPlotSelectionWindow.py Co-authored-by: Thomas VINCENT --- src/silx/app/view/CustomPlotSelectionWindow.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/silx/app/view/CustomPlotSelectionWindow.py b/src/silx/app/view/CustomPlotSelectionWindow.py index ded8985581..9737ebd358 100644 --- a/src/silx/app/view/CustomPlotSelectionWindow.py +++ b/src/silx/app/view/CustomPlotSelectionWindow.py @@ -25,8 +25,6 @@ """Custom plot selection window for selecting 1D datasets to plot.""" from silx.gui import qt, plot, icons -import silx.gui -import silx.gui.plot import silx.gui.plot.items import silx.io import numpy From 9f4c116188f5292db7ab119143094b57cb65e094 Mon Sep 17 00:00:00 2001 From: Rebelo Alexis Date: Wed, 19 Jun 2024 15:15:48 +0200 Subject: [PATCH 07/10] Added PR suggestions --- src/silx/app/view/CustomPlotSelectionWindow.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/silx/app/view/CustomPlotSelectionWindow.py b/src/silx/app/view/CustomPlotSelectionWindow.py index 2e0638bd04..26849faeb9 100644 --- a/src/silx/app/view/CustomPlotSelectionWindow.py +++ b/src/silx/app/view/CustomPlotSelectionWindow.py @@ -21,7 +21,6 @@ # THE SOFTWARE. # ###########################################################################*/ -from __future__ import annotations """Custom plot selection window for selecting 1D datasets to plot.""" from silx.gui import qt, plot, icons @@ -139,7 +138,7 @@ def getYParent(self) -> qt.QStandardItem: """Return the parent item for the Y datasets""" return self._yParent - def _setXFile(self, url: silx.io.url.DataUrl | None = None, curve: None = None): + def _setXFile(self, url: silx.io.url.DataUrl | None = None): """Set the X dataset file in the model""" if url is None: dataName = "" @@ -147,7 +146,7 @@ def _setXFile(self, url: silx.io.url.DataUrl | None = None, curve: None = None): dataName = self._getBasename(url.data_path()) self._plot1D.setXAxisLabel(dataName) - fileItem, iconItem, removeItem = self._createRowItems(dataName, curve) + fileItem, iconItem, removeItem = self._createRowItems(dataName, None) fileItem.setData(qt.QSize(0, 30), qt.Qt.SizeHintRole) fileItem.setData(self._createToolTip(url), qt.Qt.ToolTipRole) @@ -191,7 +190,7 @@ def _findRowContainingText(self, text: str) -> int | None: return None def _createRowItems( - self, filename: str, curve: silx.gui.plot.items.Curve + self, filename: str, curve: silx.gui.plot.items.Curve | None ) -> tuple[qt.QStandardItem, qt.QStandardItem, qt.QStandardItem]: """Create the items for a row in the model""" fileItem = qt.QStandardItem(filename) From 39bc37cbd5badaccee5e5134e506053297d9e13b Mon Sep 17 00:00:00 2001 From: Rebelo Alexis Date: Wed, 19 Jun 2024 15:19:22 +0200 Subject: [PATCH 08/10] Added PR suggestions --- src/silx/app/view/CustomPlotSelectionWindow.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/silx/app/view/CustomPlotSelectionWindow.py b/src/silx/app/view/CustomPlotSelectionWindow.py index 5d5661e325..26849faeb9 100644 --- a/src/silx/app/view/CustomPlotSelectionWindow.py +++ b/src/silx/app/view/CustomPlotSelectionWindow.py @@ -24,6 +24,8 @@ """Custom plot selection window for selecting 1D datasets to plot.""" from silx.gui import qt, plot, icons +import silx.gui +import silx.gui.plot import silx.gui.plot.items import silx.io import numpy @@ -204,7 +206,7 @@ def _createRowItems( return fileItem, iconItem, removeItem def fileItemExists(self, filename: str) -> bool: - """Return True if a file item with the given filename exists in the Y datasets of the model.""" + """Return if a file item with the given filename exists in the model for the Y datasets.""" for row in range(self.getYParent().rowCount()): item = self.item(row, 1) if item and item.text() == filename: From a774f640c04e14ed3d8da42f7bc2ded5d6fe6ab5 Mon Sep 17 00:00:00 2001 From: Rebelo Alexis Date: Wed, 19 Jun 2024 15:28:57 +0200 Subject: [PATCH 09/10] Adding import annotations --- src/silx/app/view/CustomPlotSelectionWindow.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/silx/app/view/CustomPlotSelectionWindow.py b/src/silx/app/view/CustomPlotSelectionWindow.py index 26849faeb9..0baca585b8 100644 --- a/src/silx/app/view/CustomPlotSelectionWindow.py +++ b/src/silx/app/view/CustomPlotSelectionWindow.py @@ -22,6 +22,7 @@ # ###########################################################################*/ """Custom plot selection window for selecting 1D datasets to plot.""" +from __future__ import annotations from silx.gui import qt, plot, icons import silx.gui From 1d9d779413e376cfdabf76f6fa3c69d8842106bd Mon Sep 17 00:00:00 2001 From: Rebelo Alexis Date: Mon, 24 Jun 2024 11:26:42 +0200 Subject: [PATCH 10/10] Added short description of CustomPlotSelectionWindow --- src/silx/app/view/CustomPlotSelectionWindow.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/silx/app/view/CustomPlotSelectionWindow.py b/src/silx/app/view/CustomPlotSelectionWindow.py index 0baca585b8..8c722dd2da 100644 --- a/src/silx/app/view/CustomPlotSelectionWindow.py +++ b/src/silx/app/view/CustomPlotSelectionWindow.py @@ -549,6 +549,8 @@ def addClearAction(self, treeView: qt.QTreeView): class CustomPlotSelectionWindow(qt.QMainWindow): + """A customized plot selection window allowing the user to select and display 1D data sets.""" + sigVisibilityChanged = qt.Signal(bool) def __init__(self, parent=None):