Skip to content

Commit

Permalink
Merge pull request #4136 from t20100/fix-ci-pyside
Browse files Browse the repository at this point in the history
silx.gui.plot.PlotWidget: Fixed support of PySide6
  • Loading branch information
vallsv authored Aug 29, 2024
2 parents ac2901a + 70ad770 commit a96820b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 48 deletions.
5 changes: 3 additions & 2 deletions src/silx/gui/dialog/test/test_datafiledialog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# /*##########################################################################
#
# Copyright (c) 2016-2022 European Synchrotron Radiation Facility
# Copyright (c) 2016-2024 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
Expand Down Expand Up @@ -115,10 +115,11 @@ def _deleteDialog(self):
self.qWaitForDestroy(ref)

def qWaitForPendingActions(self, dialog):
self.qapp.processEvents()
for _ in range(20):
if not dialog.hasPendingEvents():
return
self.qWait(10)
self.qWait(100)
raise RuntimeError("Still have pending actions")

def assertSamePath(self, path1, path2):
Expand Down
5 changes: 3 additions & 2 deletions src/silx/gui/dialog/test/test_imagefiledialog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# /*##########################################################################
#
# Copyright (c) 2016-2022 European Synchrotron Radiation Facility
# Copyright (c) 2016-2024 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
Expand Down Expand Up @@ -122,10 +122,11 @@ def _deleteDialog(self):
self.qWaitForDestroy(ref)

def qWaitForPendingActions(self, dialog):
self.qapp.processEvents()
for _ in range(20):
if not dialog.hasPendingEvents():
return
self.qWait(10)
self.qWait(100)
raise RuntimeError("Still have pending actions")

def assertSamePath(self, path1, path2):
Expand Down
6 changes: 3 additions & 3 deletions src/silx/gui/plot/PlotWidget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# /*##########################################################################
#
# Copyright (c) 2004-2023 European Synchrotron Radiation Facility
# Copyright (c) 2004-2024 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
Expand Down Expand Up @@ -828,10 +828,10 @@ def showEvent(self, event):
def hideEvent(self, event):
super(PlotWidget, self).hideEvent(event)
if qt.BINDING == "PySide6":
# Workaround RuntimeError: The SignalInstance object was already deleted
# Workaround RuntimeError/AttributeError: The SignalInstance object was already deleted
try:
self.sigVisibilityChanged.emit(False)
except RuntimeError as e:
except (RuntimeError, AttributeError) as e:
_logger.error(f"Exception occured: {e}")
else:
self.sigVisibilityChanged.emit(False)
Expand Down
22 changes: 5 additions & 17 deletions src/silx/gui/plot/test/testImageView.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# /*##########################################################################
#
# Copyright (c) 2017-2021 European Synchrotron Radiation Facility
# Copyright (c) 2017-2024 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
Expand Down Expand Up @@ -30,30 +30,18 @@

import numpy

from silx.gui import qt
from silx.gui.utils.testutils import TestCaseQt
from silx.gui.plot import items

from silx.gui.plot.ImageView import ImageView
from silx.gui.colors import Colormap
from .utils import PlotWidgetTestCase


class TestImageView(TestCaseQt):
class TestImageView(PlotWidgetTestCase):
"""Tests of ImageView widget."""

def setUp(self):
super(TestImageView, self).setUp()
self.plot = ImageView()
self.plot.show()
self.qWaitForWindowExposed(self.plot)

def tearDown(self):
self.qapp.processEvents()
self.plot.setAttribute(qt.Qt.WA_DeleteOnClose)
self.plot.close()
del self.plot
self.qapp.processEvents()
super(TestImageView, self).tearDown()
def _createPlot(self):
return ImageView()

def testSetImage(self):
"""Test setImage"""
Expand Down
47 changes: 23 additions & 24 deletions src/silx/gui/plot/test/testPixelIntensityHistoAction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# /*##########################################################################
#
# Copyright (c) 2016-2018 European Synchrotron Radiation Facility
# Copyright (c) 2016-2024 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
Expand Down Expand Up @@ -31,31 +31,30 @@
import numpy

from silx.utils.testutils import ParametricTestCase
from silx.gui.utils.testutils import TestCaseQt, getQToolButtonFromAction
from silx.gui.utils.testutils import getQToolButtonFromAction
from silx.gui import qt
from silx.gui.plot import Plot2D
from .utils import PlotWidgetTestCase


class TestPixelIntensitiesHisto(TestCaseQt, ParametricTestCase):
class TestPixelIntensitiesHisto(PlotWidgetTestCase, ParametricTestCase):
"""Tests for PixelIntensitiesHistoAction widget."""

def _createPlot(self):
return Plot2D()

def setUp(self):
super(TestPixelIntensitiesHisto, self).setUp()
self.image = numpy.random.rand(10, 10)
self.plotImage = Plot2D()
self.plotImage.getIntensityHistogramAction().setVisible(True)

def tearDown(self):
del self.plotImage
super(TestPixelIntensitiesHisto, self).tearDown()
self.plot.getIntensityHistogramAction().setVisible(True)

def testShowAndHide(self):
"""Simple test that the plot is showing and hiding when activating the
action"""
self.plotImage.addImage(self.image, origin=(0, 0), legend="sino")
self.plotImage.show()
self.plot.addImage(self.image, origin=(0, 0), legend="sino")
self.plot.show()

histoAction = self.plotImage.getIntensityHistogramAction()
histoAction = self.plot.getIntensityHistogramAction()

# test the pixel intensity diagram is showing
button = getQToolButtonFromAction(histoAction)
Expand All @@ -66,7 +65,7 @@ def testShowAndHide(self):
self.assertTrue(histoAction.getHistogramWidget().isVisible())

# test the pixel intensity diagram is hiding
self.plotImage.activateWindow()
self.plot.activateWindow()
self.qapp.processEvents()
self.mouseMove(button)
self.mouseClick(button, qt.Qt.LeftButton)
Expand All @@ -83,15 +82,15 @@ def testImageFormatInput(self):
numpy.float32,
numpy.float64,
]
self.plotImage.addImage(self.image, origin=(0, 0), legend="sino")
self.plotImage.show()
button = getQToolButtonFromAction(self.plotImage.getIntensityHistogramAction())
self.plot.addImage(self.image, origin=(0, 0), legend="sino")
self.plot.show()
button = getQToolButtonFromAction(self.plot.getIntensityHistogramAction())
self.mouseMove(button)
self.mouseClick(button, qt.Qt.LeftButton)
self.qapp.processEvents()
for typeToTest in typesToTest:
with self.subTest(typeToTest=typeToTest):
self.plotImage.addImage(
self.plot.addImage(
self.image.astype(typeToTest), origin=(0, 0), legend="sino"
)

Expand All @@ -100,10 +99,10 @@ def testScatter(self):
xx = numpy.arange(10)
yy = numpy.arange(10)
value = numpy.sin(xx)
self.plotImage.addScatter(xx, yy, value)
self.plotImage.show()
self.plot.addScatter(xx, yy, value)
self.plot.show()

histoAction = self.plotImage.getIntensityHistogramAction()
histoAction = self.plot.getIntensityHistogramAction()

# test the pixel intensity diagram is showing
button = getQToolButtonFromAction(histoAction)
Expand All @@ -122,10 +121,10 @@ def testChangeItem(self):
xx = numpy.arange(10)
yy = numpy.arange(10)
value = numpy.sin(xx)
self.plotImage.addScatter(xx, yy, value)
self.plotImage.show()
self.plot.addScatter(xx, yy, value)
self.plot.show()

histoAction = self.plotImage.getIntensityHistogramAction()
histoAction = self.plot.getIntensityHistogramAction()

# test the pixel intensity diagram is showing
button = getQToolButtonFromAction(histoAction)
Expand All @@ -141,7 +140,7 @@ def testChangeItem(self):
data1 = items[0].getValueData(copy=False)

# Set another item to the plot
self.plotImage.addImage(self.image, origin=(0, 0), legend="sino")
self.plot.addImage(self.image, origin=(0, 0), legend="sino")
self.qapp.processEvents()
data2 = items[0].getValueData(copy=False)

Expand Down

0 comments on commit a96820b

Please sign in to comment.