diff options
author | Picca Frédéric-Emmanuel <picca@debian.org> | 2021-01-06 14:10:23 +0100 |
---|---|---|
committer | Picca Frédéric-Emmanuel <picca@debian.org> | 2021-01-06 14:10:23 +0100 |
commit | 002ed7b38ea6faabaf5c38d72b7feb613a06bf18 (patch) | |
tree | 95017e251453fea7bc4cdee1f8c7948db5bcbb1e /examples/plotInteractiveImageROI.py | |
parent | 67d50044ca7c19d729e97856afdbb820554de27f (diff) | |
parent | b3bea947efa55d2c0f198b6c6795b3177be27f45 (diff) |
Update upstream source from tag 'upstream/0.14.0+dfsg'
Update to upstream version '0.14.0+dfsg'
with Debian dir 4d37469f6d6ee58a6bdbac36ff5fed8399b69383
Diffstat (limited to 'examples/plotInteractiveImageROI.py')
-rw-r--r-- | examples/plotInteractiveImageROI.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/examples/plotInteractiveImageROI.py b/examples/plotInteractiveImageROI.py index c10bbf3..7254b7e 100644 --- a/examples/plotInteractiveImageROI.py +++ b/examples/plotInteractiveImageROI.py @@ -38,8 +38,10 @@ from silx.gui import qt from silx.gui.plot import Plot2D from silx.gui.plot.tools.roi import RegionOfInterestManager from silx.gui.plot.tools.roi import RegionOfInterestTableWidget +from silx.gui.plot.tools.roi import RoiModeSelectorAction from silx.gui.plot.items.roi import RectangleROI from silx.gui.plot.items import LineMixIn, SymbolMixIn +from silx.gui.plot.actions import control as control_actions def dummy_image(): @@ -54,16 +56,16 @@ def dummy_image(): app = qt.QApplication([]) # Start QApplication -backend = "matplotlib" -if "--opengl" in sys.argv: - backend = "opengl" - # Create the plot widget and add an image -plot = Plot2D(backend=backend) +plot = Plot2D() plot.getDefaultColormap().setName('viridis') plot.setKeepDataAspectRatio(True) plot.addImage(dummy_image()) +toolbar = qt.QToolBar() +toolbar.addAction(control_actions.OpenGLAction(parent=toolbar, plot=plot)) +plot.addToolBar(toolbar) + # Create the object controlling the ROIs and set it up roiManager = RegionOfInterestManager(plot) roiManager.setColor('pink') # Set the color of ROI @@ -105,11 +107,33 @@ for roiClass in roiManager.getSupportedRoiClasses(): action = roiManager.getInteractionModeAction(roiClass) roiToolbar.addAction(action) +class AutoHideToolBar(qt.QToolBar): + """A toolbar which hide itself if no actions are visible""" + + def actionEvent(self, event): + if event.type() == qt.QEvent.ActionChanged: + self._updateVisibility() + return qt.QToolBar.actionEvent(self, event) + + def _updateVisibility(self): + visible = False + for action in self.actions(): + if action.isVisible(): + visible = True + break + self.setVisible(visible) + +roiToolbarEdit = AutoHideToolBar() +modeSelectorAction = RoiModeSelectorAction() +modeSelectorAction.setRoiManager(roiManager) +roiToolbarEdit.addAction(modeSelectorAction) + # Add the region of interest table and the buttons to a dock widget widget = qt.QWidget() layout = qt.QVBoxLayout() widget.setLayout(layout) layout.addWidget(roiToolbar) +layout.addWidget(roiToolbarEdit) layout.addWidget(roiTable) |