diff options
author | Picca Frédéric-Emmanuel <picca@debian.org> | 2021-01-06 14:10:12 +0100 |
---|---|---|
committer | Picca Frédéric-Emmanuel <picca@debian.org> | 2021-01-06 14:10:12 +0100 |
commit | b3bea947efa55d2c0f198b6c6795b3177be27f45 (patch) | |
tree | 4116758aafe4483bf472c1d54b519e685737fd77 /silx/gui/plot/PlotWindow.py | |
parent | 5ad425ff4e62f5e003178813ebd073577679a00e (diff) |
New upstream version 0.14.0+dfsg
Diffstat (limited to 'silx/gui/plot/PlotWindow.py')
-rw-r--r-- | silx/gui/plot/PlotWindow.py | 107 |
1 files changed, 59 insertions, 48 deletions
diff --git a/silx/gui/plot/PlotWindow.py b/silx/gui/plot/PlotWindow.py index a3b70c6..3cd605f 100644 --- a/silx/gui/plot/PlotWindow.py +++ b/silx/gui/plot/PlotWindow.py @@ -224,6 +224,56 @@ class PlotWindow(PlotWidget): self._sigAxesVisibilityChanged.connect(self._updateColorBarBackground) self._updateColorBarBackground() + if control: # Create control button only if requested + self.controlButton = qt.QToolButton() + self.controlButton.setText("Options") + self.controlButton.setToolButtonStyle(qt.Qt.ToolButtonTextBesideIcon) + self.controlButton.setAutoRaise(True) + self.controlButton.setPopupMode(qt.QToolButton.InstantPopup) + menu = qt.QMenu(self) + menu.aboutToShow.connect(self._customControlButtonMenu) + self.controlButton.setMenu(menu) + + self._positionWidget = None + if position: # Add PositionInfo widget to the bottom of the plot + if isinstance(position, abc.Iterable): + # Use position as a set of converters + converters = position + else: + converters = None + self._positionWidget = tools.PositionInfo( + plot=self, converters=converters) + # Set a snapping mode that is consistent with legacy one + self._positionWidget.setSnappingMode( + tools.PositionInfo.SNAPPING_CROSSHAIR | + tools.PositionInfo.SNAPPING_ACTIVE_ONLY | + tools.PositionInfo.SNAPPING_SYMBOLS_ONLY | + tools.PositionInfo.SNAPPING_CURVE | + tools.PositionInfo.SNAPPING_SCATTER) + + self.__setCentralWidget() + + # Creating the toolbar also create actions for toolbuttons + self._interactiveModeToolBar = tools.InteractiveModeToolBar( + parent=self, plot=self) + self.addToolBar(self._interactiveModeToolBar) + + self._toolbar = self._createToolBar(title='Plot', parent=self) + self.addToolBar(self._toolbar) + + self._outputToolBar = tools.OutputToolBar(parent=self, plot=self) + self._outputToolBar.getCopyAction().setVisible(copy) + self._outputToolBar.getSaveAction().setVisible(save) + self._outputToolBar.getPrintAction().setVisible(print_) + self.addToolBar(self._outputToolBar) + + # Activate shortcuts in PlotWindow widget: + for toolbar in (self._interactiveModeToolBar, self._outputToolBar): + for action in toolbar.actions(): + self.addAction(action) + + def __setCentralWidget(self): + """Set central widget to host plot backend, colorbar, and bottom bar""" gridLayout = qt.QGridLayout() gridLayout.setSpacing(0) gridLayout.setContentsMargins(0, 0, 0, 0) @@ -233,42 +283,15 @@ class PlotWindow(PlotWidget): gridLayout.setColumnStretch(0, 1) centralWidget = qt.QWidget(self) centralWidget.setLayout(gridLayout) - self.setCentralWidget(centralWidget) - self._positionWidget = None - - if control or position: + if hasattr(self, "controlButton") or self._positionWidget is not None: hbox = qt.QHBoxLayout() hbox.setContentsMargins(0, 0, 0, 0) - if control: - self.controlButton = qt.QToolButton() - self.controlButton.setText("Options") - self.controlButton.setToolButtonStyle(qt.Qt.ToolButtonTextBesideIcon) - self.controlButton.setAutoRaise(True) - self.controlButton.setPopupMode(qt.QToolButton.InstantPopup) - menu = qt.QMenu(self) - menu.aboutToShow.connect(self._customControlButtonMenu) - self.controlButton.setMenu(menu) - + if hasattr(self, "controlButton"): hbox.addWidget(self.controlButton) - if position: # Add PositionInfo widget to the bottom of the plot - if isinstance(position, abc.Iterable): - # Use position as a set of converters - converters = position - else: - converters = None - self._positionWidget = tools.PositionInfo( - plot=self, converters=converters) - # Set a snapping mode that is consistent with legacy one - self._positionWidget.setSnappingMode( - tools.PositionInfo.SNAPPING_CROSSHAIR | - tools.PositionInfo.SNAPPING_ACTIVE_ONLY | - tools.PositionInfo.SNAPPING_SYMBOLS_ONLY | - tools.PositionInfo.SNAPPING_CURVE | - tools.PositionInfo.SNAPPING_SCATTER) - + if self._positionWidget is not None: hbox.addWidget(self._positionWidget) hbox.addStretch(1) @@ -277,24 +300,12 @@ class PlotWindow(PlotWidget): gridLayout.addWidget(bottomBar, 1, 0, 1, -1) - # Creating the toolbar also create actions for toolbuttons - self._interactiveModeToolBar = tools.InteractiveModeToolBar( - parent=self, plot=self) - self.addToolBar(self._interactiveModeToolBar) - - self._toolbar = self._createToolBar(title='Plot', parent=self) - self.addToolBar(self._toolbar) - - self._outputToolBar = tools.OutputToolBar(parent=self, plot=self) - self._outputToolBar.getCopyAction().setVisible(copy) - self._outputToolBar.getSaveAction().setVisible(save) - self._outputToolBar.getPrintAction().setVisible(print_) - self.addToolBar(self._outputToolBar) + self.setCentralWidget(centralWidget) - # Activate shortcuts in PlotWindow widget: - for toolbar in (self._interactiveModeToolBar, self._outputToolBar): - for action in toolbar.actions(): - self.addAction(action) + @docstring(PlotWidget) + def setBackend(self, backend): + super(PlotWindow, self).setBackend(backend) + self.__setCentralWidget() # Recreate PlotWindow's central widget @docstring(PlotWidget) def setBackgroundColor(self, color): @@ -313,7 +324,7 @@ class PlotWindow(PlotWidget): def _updateColorBarBackground(self): """Update the colorbar background according to the state of the plot""" - if self._isAxesDisplayed(): + if self.isAxesDisplayed(): color = self.getBackgroundColor() else: color = self.getDataBackgroundColor() |