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

Issue with DataViewer when removing views #4130

Closed
malte-storm opened this issue Jun 12, 2024 · 1 comment
Closed

Issue with DataViewer when removing views #4130

malte-storm opened this issue Jun 12, 2024 · 1 comment
Milestone

Comments

@malte-storm
Copy link
Contributor

When I remove a registered view from the silx.gui.data.DataViewer.DataViewer using the removeView method, the display breaks down after switching between views, see the image below for the display of an 3D volume as image stack

A minimum code example is given below (with debugging prints). The reason is that the DataViewer.__getStackIndex method always calls the __stack.addWidget method of the QStackedWidget when the view is not listed in the __index (which is invalidated after the call to removeView). The addWidget always appends the given widget to the end of the QStackedWidgets list which moves all other widgets "up" in the list without updating the index.

from qtpy import QtWidgets

from silx.gui.data.DataViewer import DataViewer
from silx.gui.data import DataViews
import numpy as np


def get_view_indices(viewer):
    return {
        v.__class__.__name__: (
            viewer._DataViewer__stack.indexOf(v.getWidget()),
            viewer._DataViewer__index.get(v, "None"),
        ) for v in viewer.availableViews()
    }


if __name__ == "__main__":
    data = np.random.random((100, 100, 10))
    app = QtWidgets.QApplication([])
    viewer = DataViewer()

    viewer.setData(data)
    # Force creation of views
    for v in viewer.currentAvailableViews():
        viewer.setDisplayedView(v)

    for v in viewer.availableViews():
        if v.__class__.__name__ == "_ImageView":
            viewer.removeView(v)

    viewer.show()

    viewer.setData(data)
    print(get_view_indices(viewer))
    viewer.setDisplayMode(DataViews.STACK_MODE)
    print(get_view_indices(viewer))
    viewer.setDisplayMode(DataViews.PLOT1D_MODE)
    print(get_view_indices(viewer))
    viewer.setDisplayMode(DataViews.STACK_MODE)
    print(get_view_indices(viewer))
    app.exec()

grafik

@t20100
Copy link
Member

t20100 commented Jul 9, 2024

closed by #4131

@t20100 t20100 closed this as completed Jul 9, 2024
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

No branches or pull requests

2 participants