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

PlotWidget: Added sigBackendChanged #3890

Merged
merged 3 commits into from
Jul 10, 2023
Merged
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
5 changes: 5 additions & 0 deletions src/silx/gui/plot/PlotWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ class PlotWidget(qt.QMainWindow):
It provides the menu which will be displayed.
"""

sigBackendChanged = qt.Signal()
"""Signal emitted when the backend have changed."""

def __init__(self, parent=None, backend=None):
self._autoreplot = False
self._dirty = False
Expand Down Expand Up @@ -623,6 +626,8 @@ def setBackend(self, backend):
for item in self.getItems():
item._updated()

self.sigBackendChanged.emit()

def getBackend(self):
"""Returns the backend currently used by :class:`PlotWidget`.

Expand Down
14 changes: 2 additions & 12 deletions src/silx/gui/plot/actions/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ def __init__(self, plot, parent=None):
}

name = self._getBackendName(plot)
self.__state = name
icon, tooltip = self._states[name]
super(OpenGLAction, self).__init__(
plot,
Expand All @@ -649,10 +648,10 @@ def __init__(self, plot, parent=None):
triggered=self._actionTriggered,
checkable=True,
parent=parent)
plot.sigBackendChanged.connect(self._backendUpdated)

def _backendUpdated(self):
name = self._getBackendName(self.plot)
self.__state = name
icon, tooltip = self._states[name]
self.setIcon(icon)
self.setToolTip(tooltip)
Expand All @@ -671,21 +670,12 @@ def _getBackendName(self, plot):
def _actionTriggered(self, checked=False):
plot = self.plot
name = self._getBackendName(self.plot)
if self.__state != name:
# THere is no event to know the backend was updated
# So here we check if there is a mismatch between the displayed state
# and the real state of the widget
self._backendUpdated()
return
if name != "opengl":
from silx.gui.utils import glutils
result = glutils.isOpenGLAvailable()
if not result:
qt.QMessageBox.critical(plot, "OpenGL rendering not available", result.error)
# Uncheck if needed
self._backendUpdated()
qt.QMessageBox.critical(plot, "OpenGL rendering is not available", result.error)
return
plot.setBackend("opengl")
else:
plot.setBackend("matplotlib")
self._backendUpdated()