Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

silx.view.Viewer : New feature to display multiple curves in a new window #4132

Merged
merged 12 commits into from
Jun 14, 2024

Conversation

RebeloAlexis
Copy link
Contributor

@RebeloAlexis RebeloAlexis commented Jun 12, 2024

A new feature has been added, allowing the display of multiple curves by selecting values for X or Y. Only 1D files are taken into account.
How to access :

    - Open silx view
    - Select a file
    - Open the 'plot selection' window (View -> plot selection)
    - Drag and drop dataset to the new window
    - Admire the results :)

All the code is in silx.view.CustomPlotSelectionWindow
image

Copy link
Member

@t20100 t20100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I left a few suggestions.

There is an issue with test with PySide6, I guess None is not accepted byt QStandardItem.appendRow:

/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/silx/app/view/test/test_view.py:89: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/silx/app/view/Viewer.py:120: in __init__
    self._customPlotSelectionWindow = CustomPlotSelectionWindow(self)
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/silx/app/view/CustomPlotSelectionWindow.py:460: in __init__
    model = _FileListModel(self.plot1D)
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/site-packages/silx/app/view/CustomPlotSelectionWindow.py:118: in __init__
    self._addYFile("")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <silx.app.view.CustomPlotSelectionWindow._FileListModel(0x5585b7632640) at 0x7f4d1daa2480>
filename = '', curve = None, node = 'X'

    def _addYFile(self, filename, curve=None, node="X"):
        fileItem, iconItem, removeItem = self._createRowItems(filename, curve)
        if not filename:
            fileItem.setData(qt.QSize(0, 30), qt.Qt.SizeHintRole)
    
        if self.getYParent().rowCount() == 0:
>           self.getYParent().appendRow([None, fileItem])
E           TypeError: 'PySide6.QtGui.QStandardItem.appendRow' called with wrong argument types:
E             PySide6.QtGui.QStandardItem.appendRow(list)
E           Supported signatures:
E             PySide6.QtGui.QStandardItem.appendRow(PySide6.QtGui.QStandardItem)
E             PySide6.QtGui.QStandardItem.appendRow(Sequence[PySide6.QtGui.QStandardItem])

src/silx/app/view/Viewer.py Outdated Show resolved Hide resolved
src/silx/app/view/CustomPlotSelectionWindow.py Outdated Show resolved Hide resolved
src/silx/app/view/CustomPlotSelectionWindow.py Outdated Show resolved Hide resolved
src/silx/app/view/CustomPlotSelectionWindow.py Outdated Show resolved Hide resolved
src/silx/app/view/CustomPlotSelectionWindow.py Outdated Show resolved Hide resolved
src/silx/app/view/CustomPlotSelectionWindow.py Outdated Show resolved Hide resolved
Copy link
Member

@payno payno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice PR 💪
Minor comments.

If we want to be picky a couple of lines could be added to the PR to explain how to use it:

  • open silx view
  • select a file
  • open the 'plot selection' window (Views -> plot selection)
  • drag and drop dataset to the new window
  • admire the results :)

But I think the documentation part will come in another PR right ?.
Else nice user experience 😄

Comment on lines +66 to +69
painter.save()
painter.setPen(self.__highlightDropPen)
painter.drawRect(option.rect.adjusted(1, 1, -1, -1))
painter.restore()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a 'painter' context would be more pythonic. Something which handle the save and the restore function

with painter_state_context(painter):  # not very inspired by the name
    painter.setPen(self.__highlightDropPen)
    painter.drawRect(option.rect.adjusted(1, 1, -1, -1))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about it, and I'm not used to using "with", so for the moment I'll leave it at that.

src/silx/app/view/CustomPlotSelectionWindow.py Outdated Show resolved Hide resolved

def _addYFile(self, filename, curve=None, node="X"):
fileItem, iconItem, removeItem = self._createRowItems(filename, curve)
if not filename:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition was not 'straightforward' for me (maybe I am tired).
Anyway to help understanding here are options:

  1. add typing to filename.
    because from outside for this condition, according to the context we can consider filename to be a string or None. If you provide
def _addYFile(self, filename: str, curve=None, node="X"):

Then this will allow us to remove one use case
2. provide a simple comment

        if not filename:
            # provide size hint for 'empty' item

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, typing and docString will be added to the next PR.

src/silx/app/view/CustomPlotSelectionWindow.py Outdated Show resolved Hide resolved
src/silx/app/view/CustomPlotSelectionWindow.py Outdated Show resolved Hide resolved
src/silx/app/view/CustomPlotSelectionWindow.py Outdated Show resolved Hide resolved
src/silx/app/view/CustomPlotSelectionWindow.py Outdated Show resolved Hide resolved
@t20100 t20100 merged commit eb24975 into silx-kit:main Jun 14, 2024
7 of 8 checks passed
@RebeloAlexis RebeloAlexis deleted the customPlot branch June 28, 2024 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants