summaryrefslogtreecommitdiff
path: root/src/silx/gui/plot/PlotToolButtons.py
diff options
context:
space:
mode:
authorPicca Frédéric-Emmanuel <picca@debian.org>2024-02-05 16:30:07 +0100
committerPicca Frédéric-Emmanuel <picca@debian.org>2024-02-05 16:30:07 +0100
commit04095a69f18767d222b16fae5b40f2b712cd6f7e (patch)
treed20abd3ee2f237319443e9dfd7500ad55d29a33d /src/silx/gui/plot/PlotToolButtons.py
parent3427caf0e96690e56aac6231a91df8f0f7a64fc2 (diff)
New upstream version 2.0.0+dfsg
Diffstat (limited to 'src/silx/gui/plot/PlotToolButtons.py')
-rw-r--r--src/silx/gui/plot/PlotToolButtons.py163
1 files changed, 63 insertions, 100 deletions
diff --git a/src/silx/gui/plot/PlotToolButtons.py b/src/silx/gui/plot/PlotToolButtons.py
index a810ce1..e132877 100644
--- a/src/silx/gui/plot/PlotToolButtons.py
+++ b/src/silx/gui/plot/PlotToolButtons.py
@@ -29,6 +29,7 @@ The following QToolButton are available:
- :class:`.AspectToolButton`
- :class:`.YAxisOriginToolButton`
- :class:`.ProfileToolButton`
+- :class:`.RulerToolButton`
- :class:`.SymbolToolButton`
"""
@@ -40,11 +41,11 @@ __date__ = "27/06/2017"
import functools
import logging
-import weakref
from .. import icons
from .. import qt
from ... import config
+from .tools.PlotToolButton import PlotToolButton
from .items import SymbolMixIn, Scatter
@@ -52,58 +53,6 @@ from .items import SymbolMixIn, Scatter
_logger = logging.getLogger(__name__)
-class PlotToolButton(qt.QToolButton):
- """A QToolButton connected to a :class:`~silx.gui.plot.PlotWidget`.
- """
-
- def __init__(self, parent=None, plot=None):
- super(PlotToolButton, self).__init__(parent)
- self._plotRef = None
- if plot is not None:
- self.setPlot(plot)
-
- def plot(self):
- """
- Returns the plot connected to the widget.
- """
- return None if self._plotRef is None else self._plotRef()
-
- def setPlot(self, plot):
- """
- Set the plot connected to the widget
-
- :param plot: :class:`.PlotWidget` instance on which to operate.
- """
- previousPlot = self.plot()
-
- if previousPlot is plot:
- return
- if previousPlot is not None:
- self._disconnectPlot(previousPlot)
-
- if plot is None:
- self._plotRef = None
- else:
- self._plotRef = weakref.ref(plot)
- self._connectPlot(plot)
-
- def _connectPlot(self, plot):
- """
- Called when the plot is connected to the widget
-
- :param plot: :class:`.PlotWidget` instance
- """
- pass
-
- def _disconnectPlot(self, plot):
- """
- Called when the plot is disconnected from the widget
-
- :param plot: :class:`.PlotWidget` instance
- """
- pass
-
-
class AspectToolButton(PlotToolButton):
"""Tool button to switch keep aspect ratio of a plot"""
@@ -114,11 +63,11 @@ class AspectToolButton(PlotToolButton):
if self.STATE is None:
self.STATE = {}
# dont keep ratio
- self.STATE[False, "icon"] = icons.getQIcon('shape-ellipse-solid')
+ self.STATE[False, "icon"] = icons.getQIcon("shape-ellipse-solid")
self.STATE[False, "state"] = "Aspect ratio is not kept"
self.STATE[False, "action"] = "Do no keep data aspect ratio"
# keep ratio
- self.STATE[True, "icon"] = icons.getQIcon('shape-circle-solid')
+ self.STATE[True, "icon"] = icons.getQIcon("shape-circle-solid")
self.STATE[True, "state"] = "Aspect ratio is kept"
self.STATE[True, "action"] = "Keep data aspect ratio"
@@ -166,7 +115,10 @@ class AspectToolButton(PlotToolButton):
def _keepDataAspectRatioChanged(self, aspectRatio):
"""Handle Plot set keep aspect ratio signal"""
- icon, toolTip = self.STATE[aspectRatio, "icon"], self.STATE[aspectRatio, "state"]
+ icon, toolTip = (
+ self.STATE[aspectRatio, "icon"],
+ self.STATE[aspectRatio, "state"],
+ )
self.setIcon(icon)
self.setToolTip(toolTip)
@@ -181,11 +133,11 @@ class YAxisOriginToolButton(PlotToolButton):
if self.STATE is None:
self.STATE = {}
# is down
- self.STATE[False, "icon"] = icons.getQIcon('plot-ydown')
+ self.STATE[False, "icon"] = icons.getQIcon("plot-ydown")
self.STATE[False, "state"] = "Y-axis is oriented downward"
self.STATE[False, "action"] = "Orient Y-axis downward"
# keep ration
- self.STATE[True, "icon"] = icons.getQIcon('plot-yup')
+ self.STATE[True, "icon"] = icons.getQIcon("plot-yup")
self.STATE[True, "state"] = "Y-axis is oriented upward"
self.STATE[True, "action"] = "Orient Y-axis upward"
@@ -242,28 +194,29 @@ class YAxisOriginToolButton(PlotToolButton):
class ProfileOptionToolButton(PlotToolButton):
"""Button to define option on the profile"""
+
sigMethodChanged = qt.Signal(str)
-
+
def __init__(self, parent=None, plot=None):
PlotToolButton.__init__(self, parent=parent, plot=plot)
self.STATE = {}
# is down
- self.STATE['sum', "icon"] = icons.getQIcon('math-sigma')
- self.STATE['sum', "state"] = "Compute profile sum"
- self.STATE['sum', "action"] = "Compute profile sum"
+ self.STATE["sum", "icon"] = icons.getQIcon("math-sigma")
+ self.STATE["sum", "state"] = "Compute profile sum"
+ self.STATE["sum", "action"] = "Compute profile sum"
# keep ration
- self.STATE['mean', "icon"] = icons.getQIcon('math-mean')
- self.STATE['mean', "state"] = "Compute profile mean"
- self.STATE['mean', "action"] = "Compute profile mean"
+ self.STATE["mean", "icon"] = icons.getQIcon("math-mean")
+ self.STATE["mean", "state"] = "Compute profile mean"
+ self.STATE["mean", "action"] = "Compute profile mean"
- self.sumAction = self._createAction('sum')
+ self.sumAction = self._createAction("sum")
self.sumAction.triggered.connect(self.setSum)
self.sumAction.setIconVisibleInMenu(True)
self.sumAction.setCheckable(True)
self.sumAction.setChecked(True)
- self.meanAction = self._createAction('mean')
+ self.meanAction = self._createAction("mean")
self.meanAction.triggered.connect(self.setMean)
self.meanAction.setIconVisibleInMenu(True)
self.meanAction.setCheckable(True)
@@ -273,7 +226,7 @@ class ProfileOptionToolButton(PlotToolButton):
menu.addAction(self.meanAction)
self.setMenu(menu)
self.setPopupMode(qt.QToolButton.InstantPopup)
- self._method = 'mean'
+ self._method = "mean"
self._update()
def _createAction(self, method):
@@ -282,7 +235,7 @@ class ProfileOptionToolButton(PlotToolButton):
return qt.QAction(icon, text, self)
def setSum(self):
- self.setMethod('sum')
+ self.setMethod("sum")
def _update(self):
icon = self.STATE[self._method, "icon"]
@@ -293,7 +246,7 @@ class ProfileOptionToolButton(PlotToolButton):
self.meanAction.setChecked(self._method == "mean")
def setMean(self):
- self.setMethod('mean')
+ self.setMethod("mean")
def setMethod(self, method):
"""Set the method to use.
@@ -301,13 +254,12 @@ class ProfileOptionToolButton(PlotToolButton):
:param str method: Either 'sum' or 'mean'
"""
if method != self._method:
- if method in ('sum', 'mean'):
+ if method in ("sum", "mean"):
self._method = method
self.sigMethodChanged.emit(self._method)
self._update()
else:
- _logger.warning(
- "Unsupported method '%s'. Setting ignored.", method)
+ _logger.warning("Unsupported method '%s'. Setting ignored.", method)
def getMethod(self):
"""Returns the current method in use (See :meth:`setMethod`).
@@ -320,6 +272,7 @@ class ProfileOptionToolButton(PlotToolButton):
class ProfileToolButton(PlotToolButton):
"""Button used in Profile3DToolbar to switch between 2D profile
and 1D profile."""
+
STATE = None
"""Lazy loaded states used to feed ProfileToolButton"""
@@ -328,12 +281,16 @@ class ProfileToolButton(PlotToolButton):
def __init__(self, parent=None, plot=None):
if self.STATE is None:
self.STATE = {
- (1, "icon"): icons.getQIcon('profile1D'),
+ (1, "icon"): icons.getQIcon("profile1D"),
(1, "state"): "1D profile is computed on visible image",
(1, "action"): "1D profile on visible image",
- (2, "icon"): icons.getQIcon('profile2D'),
- (2, "state"): "2D profile is computed, one 1D profile for each image in the stack",
- (2, "action"): "2D profile on image stack"}
+ (2, "icon"): icons.getQIcon("profile2D"),
+ (
+ 2,
+ "state",
+ ): "2D profile is computed, one 1D profile for each image in the stack",
+ (2, "action"): "2D profile on image stack",
+ }
# Compute 1D profile
# Compute 2D profile
@@ -359,7 +316,7 @@ class ProfileToolButton(PlotToolButton):
menu.addAction(profile2DAction)
self.setMenu(menu)
self.setPopupMode(qt.QToolButton.InstantPopup)
- menu.setTitle('Select profile dimension')
+ menu.setTitle("Select profile dimension")
self.computeProfileIn1D()
def _createAction(self, profileDimension):
@@ -431,12 +388,12 @@ class _SymbolToolButtonBase(PlotToolButton):
:param QMenu menu:
"""
- for marker, name in zip(SymbolMixIn.getSupportedSymbols(),
- SymbolMixIn.getSupportedSymbolNames()):
+ for marker, name in zip(
+ SymbolMixIn.getSupportedSymbols(), SymbolMixIn.getSupportedSymbolNames()
+ ):
action = qt.QAction(name, menu)
action.setCheckable(False)
- action.triggered.connect(
- functools.partial(self._markerChanged, marker))
+ action.triggered.connect(functools.partial(self._markerChanged, marker))
menu.addAction(action)
def _sizeChanged(self, value):
@@ -476,8 +433,8 @@ class SymbolToolButton(_SymbolToolButtonBase):
def __init__(self, parent=None, plot=None):
super(SymbolToolButton, self).__init__(parent=parent, plot=plot)
- self.setToolTip('Set symbol size and marker')
- self.setIcon(icons.getQIcon('plot-symbols'))
+ self.setToolTip("Set symbol size and marker")
+ self.setIcon(icons.getQIcon("plot-symbols"))
menu = qt.QMenu(self)
self._addSizeSliderToMenu(menu)
@@ -496,12 +453,10 @@ class ScatterVisualizationToolButton(_SymbolToolButtonBase):
"""
def __init__(self, parent=None, plot=None):
- super(ScatterVisualizationToolButton, self).__init__(
- parent=parent, plot=plot)
+ super(ScatterVisualizationToolButton, self).__init__(parent=parent, plot=plot)
- self.setToolTip(
- 'Set scatter visualization mode, symbol marker and size')
- self.setIcon(icons.getQIcon('eye'))
+ self.setToolTip("Set scatter visualization mode, symbol marker and size")
+ self.setIcon(icons.getQIcon("eye"))
menu = qt.QMenu(self)
@@ -513,26 +468,33 @@ class ScatterVisualizationToolButton(_SymbolToolButtonBase):
action = qt.QAction(name, menu)
action.setCheckable(False)
action.triggered.connect(
- functools.partial(self._visualizationChanged, mode, None))
+ functools.partial(self._visualizationChanged, mode, None)
+ )
menu.addAction(action)
if Scatter.Visualization.BINNED_STATISTIC in Scatter.supportedVisualizations():
reductions = Scatter.supportedVisualizationParameterValues(
- Scatter.VisualizationParameter.BINNED_STATISTIC_FUNCTION)
+ Scatter.VisualizationParameter.BINNED_STATISTIC_FUNCTION
+ )
if reductions:
- submenu = menu.addMenu('Binned Statistic')
+ submenu = menu.addMenu("Binned Statistic")
for reduction in reductions:
name = reduction.capitalize()
action = qt.QAction(name, menu)
action.setCheckable(False)
- action.triggered.connect(functools.partial(
- self._visualizationChanged,
- Scatter.Visualization.BINNED_STATISTIC,
- {Scatter.VisualizationParameter.BINNED_STATISTIC_FUNCTION: reduction}))
+ action.triggered.connect(
+ functools.partial(
+ self._visualizationChanged,
+ Scatter.Visualization.BINNED_STATISTIC,
+ {
+ Scatter.VisualizationParameter.BINNED_STATISTIC_FUNCTION: reduction
+ },
+ )
+ )
submenu.addAction(action)
submenu.addSeparator()
- binsmenu = submenu.addMenu('N Bins')
+ binsmenu = submenu.addMenu("N Bins")
slider = qt.QSlider(qt.Qt.Horizontal)
slider.setRange(10, 1000)
@@ -545,10 +507,10 @@ class ScatterVisualizationToolButton(_SymbolToolButtonBase):
menu.addSeparator()
- submenu = menu.addMenu(icons.getQIcon('plot-symbols'), "Symbol")
+ submenu = menu.addMenu(icons.getQIcon("plot-symbols"), "Symbol")
self._addSymbolsToMenu(submenu)
- submenu = menu.addMenu(icons.getQIcon('plot-symbols'), "Symbol Size")
+ submenu = menu.addMenu(icons.getQIcon("plot-symbols"), "Symbol Size")
self._addSizeSliderToMenu(submenu)
self.setMenu(menu)
@@ -587,5 +549,6 @@ class ScatterVisualizationToolButton(_SymbolToolButtonBase):
if isinstance(item, Scatter):
item.setVisualizationParameter(
Scatter.VisualizationParameter.BINNED_STATISTIC_SHAPE,
- (value, value))
+ (value, value),
+ )
item.setVisualization(Scatter.Visualization.BINNED_STATISTIC)