Skip to content

Commit

Permalink
Merge pull request #3890 from vallsv/added-backend-signal
Browse files Browse the repository at this point in the history
PlotWidget: Added sigBackendChanged
  • Loading branch information
vallsv authored Jul 10, 2023
2 parents b64664a + bbe5a47 commit 577d260
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
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()

0 comments on commit 577d260

Please sign in to comment.