summaryrefslogtreecommitdiff
path: root/silx/gui/plot/PlotWindow.py
diff options
context:
space:
mode:
Diffstat (limited to 'silx/gui/plot/PlotWindow.py')
-rw-r--r--silx/gui/plot/PlotWindow.py63
1 files changed, 40 insertions, 23 deletions
diff --git a/silx/gui/plot/PlotWindow.py b/silx/gui/plot/PlotWindow.py
index a23db04..5c7e661 100644
--- a/silx/gui/plot/PlotWindow.py
+++ b/silx/gui/plot/PlotWindow.py
@@ -29,7 +29,7 @@ The :class:`PlotWindow` is a subclass of :class:`.PlotWidget`.
__authors__ = ["V.A. Sole", "T. Vincent"]
__license__ = "MIT"
-__date__ = "17/08/2017"
+__date__ = "15/02/2018"
import collections
import logging
@@ -41,6 +41,7 @@ from . import actions
from . import items
from .actions import medfilt as actions_medfilt
from .actions import fit as actions_fit
+from .actions import control as actions_control
from .actions import histogram as actions_histogram
from . import PlotToolButtons
from .PlotTools import PositionInfo
@@ -112,6 +113,10 @@ class PlotWindow(PlotWidget):
self._legendsDockWidget = None
self._curvesROIDockWidget = None
self._maskToolsDockWidget = None
+ self._consoleDockWidget = None
+
+ # Create color bar, hidden by default for backward compatibility
+ self._colorbar = ColorBarWidget(parent=self, plot=self)
# Init actions
self.group = qt.QActionGroup(self)
@@ -168,6 +173,12 @@ class PlotWindow(PlotWidget):
self.colormapAction.setVisible(colormap)
self.addAction(self.colormapAction)
+ self.colorbarAction = self.group.addAction(
+ actions_control.ColorBarAction(self, self))
+ self.colorbarAction.setVisible(False)
+ self.addAction(self.colorbarAction)
+ self._colorbar.setVisible(False)
+
self.keepDataAspectRatioButton = PlotToolButtons.AspectToolButton(
parent=self, plot=self)
self.keepDataAspectRatioButton.setVisible(aspectRatio)
@@ -219,10 +230,6 @@ class PlotWindow(PlotWidget):
self._panWithArrowKeysAction = None
self._crosshairAction = None
- # Create color bar, hidden by default for backward compatibility
- self._colorbar = ColorBarWidget(parent=self, plot=self)
- self._colorbar.setVisible(False)
-
# Make colorbar background white
self._colorbar.setAutoFillBackground(True)
palette = self._colorbar.palette()
@@ -301,11 +308,11 @@ class PlotWindow(PlotWidget):
"""
return bool(self.getMaskToolsDockWidget().setSelectionMask(mask))
- def _toggleConsoleVisibility(self, is_checked=False):
+ def _toggleConsoleVisibility(self, isChecked=False):
"""Create IPythonDockWidget if needed,
show it or hide it."""
# create widget if needed (first call)
- if not hasattr(self, '_consoleDockWidget'):
+ if self._consoleDockWidget is None:
available_vars = {"plt": self}
banner = "The variable 'plt' is available. Use the 'whos' "
banner += "and 'help(plt)' commands for more information.\n\n"
@@ -314,10 +321,11 @@ class PlotWindow(PlotWidget):
custom_banner=banner,
parent=self)
self.addTabbedDockWidget(self._consoleDockWidget)
- self._consoleDockWidget.visibilityChanged.connect(
+ # self._consoleDockWidget.setVisible(True)
+ self._consoleDockWidget.toggleViewAction().toggled.connect(
self.getConsoleAction().setChecked)
- self._consoleDockWidget.setVisible(is_checked)
+ self._consoleDockWidget.setVisible(isChecked)
def _createToolBar(self, title, parent):
"""Create a QToolBar from the QAction of the PlotWindow.
@@ -427,16 +435,22 @@ class PlotWindow(PlotWidget):
return self._legendsDockWidget
@property
- @deprecated(replacement="getCurvesRoiDockWidget()", since_version="0.4.0")
+ @deprecated(replacement="getCurvesRoiWidget()", since_version="0.4.0")
def curvesROIDockWidget(self):
return self.getCurvesRoiDockWidget()
def getCurvesRoiDockWidget(self):
- """DockWidget with curves' ROI panel (lazy-loaded).
+ # Undocumented for a "soft deprecation" in version 0.7.0
+ # (still used internally for lazy loading)
+ if self._curvesROIDockWidget is None:
+ self._curvesROIDockWidget = CurvesROIDockWidget(
+ plot=self, name='Regions Of Interest')
+ self._curvesROIDockWidget.hide()
+ self.addTabbedDockWidget(self._curvesROIDockWidget)
+ return self._curvesROIDockWidget
- The widget returned is a :class:`CurvesROIDockWidget`.
- Its central widget is a :class:`CurvesROIWidget`
- accessible as :attr:`CurvesROIDockWidget.roiWidget`.
+ def getCurvesRoiWidget(self):
+ """Return the :class:`CurvesROIWidget`.
:class:`silx.gui.plot.CurvesROIWidget.CurvesROIWidget` offers a getter
and a setter for the ROI data:
@@ -444,12 +458,7 @@ class PlotWindow(PlotWidget):
- :meth:`CurvesROIWidget.getRois`
- :meth:`CurvesROIWidget.setRois`
"""
- if self._curvesROIDockWidget is None:
- self._curvesROIDockWidget = CurvesROIDockWidget(
- plot=self, name='Regions Of Interest')
- self._curvesROIDockWidget.hide()
- self.addTabbedDockWidget(self._curvesROIDockWidget)
- return self._curvesROIDockWidget
+ return self.getCurvesRoiDockWidget().roiWidget
@property
@deprecated(replacement="getMaskToolsDockWidget()", since_version="0.4.0")
@@ -695,6 +704,16 @@ class PlotWindow(PlotWidget):
"""
return self._medianFilter2DAction
+ def getColorBarAction(self):
+ """Action toggling the colorbar show/hide action
+
+ .. warning:: to show/hide the plot colorbar call directly the ColorBar
+ widget using getColorBarWidget()
+
+ :rtype: actions.PlotAction
+ """
+ return self.colorbarAction
+
class Plot1D(PlotWindow):
"""PlotWindow with tools specific for curves.
@@ -756,6 +775,7 @@ class Plot2D(PlotWindow):
self.profile = ProfileToolBar(plot=self)
self.addToolBar(self.profile)
+ self.colorbarAction.setVisible(True)
self.getColorBarWidget().setVisible(True)
# Put colorbar action after colormap action
@@ -763,9 +783,6 @@ class Plot2D(PlotWindow):
for index, action in enumerate(actions):
if action is self.getColormapAction():
break
- self.toolBar().insertAction(
- actions[index + 1],
- self.getColorBarWidget().getToggleViewAction())
def _getImageValue(self, x, y):
"""Get status bar value of top most image at position (x, y)