diff options
Diffstat (limited to 'examples/plotContextMenu.py')
-rw-r--r-- | examples/plotContextMenu.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/examples/plotContextMenu.py b/examples/plotContextMenu.py index 5f02f5f..4ade196 100644 --- a/examples/plotContextMenu.py +++ b/examples/plotContextMenu.py @@ -1,8 +1,7 @@ #!/usr/bin/env python -# coding: utf-8 # /*########################################################################## # -# Copyright (c) 2017-2018 European Synchrotron Radiation Facility +# Copyright (c) 2017-2023 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -44,6 +43,7 @@ from silx.gui import qt from silx.gui.plot import PlotWidget from silx.gui.plot.actions.control import ZoomBackAction, CrosshairAction from silx.gui.plot.actions.io import SaveAction, PrintAction +from silx.gui.plot.tools.menus import ZoomEnabledAxesMenu class PlotWidgetWithContextMenu(PlotWidget): @@ -51,8 +51,8 @@ class PlotWidgetWithContextMenu(PlotWidget): def __init__(self, *args, **kwargs): super(PlotWidgetWithContextMenu, self).__init__(*args, **kwargs) - self.setWindowTitle('PlotWidget with a context menu') - self.setGraphTitle('Right-click on the plot to access context menu') + self.setWindowTitle("PlotWidget with a context menu") + self.setGraphTitle("Right-click on the plot to access context menu") # Create QAction for the context menu once for all self._zoomBackAction = ZoomBackAction(plot=self, parent=self) @@ -60,6 +60,8 @@ class PlotWidgetWithContextMenu(PlotWidget): self._saveAction = SaveAction(plot=self, parent=self) self._printAction = PrintAction(plot=self, parent=self) + self._zoomEnabledAxesMenu = ZoomEnabledAxesMenu(plot=self, parent=self) + # Retrieve PlotWidget's plot area widget plotArea = self.getWidgetHandle() @@ -75,6 +77,7 @@ class PlotWidgetWithContextMenu(PlotWidget): # Create the context menu menu = qt.QMenu(self) menu.addAction(self._zoomBackAction) + menu.addMenu(self._zoomEnabledAxesMenu) menu.addSeparator() menu.addAction(self._crosshairAction) menu.addSeparator() @@ -87,7 +90,7 @@ class PlotWidgetWithContextMenu(PlotWidget): # plot area, and thus needs to be converted. plotArea = self.getWidgetHandle() globalPosition = plotArea.mapToGlobal(pos) - menu.exec_(globalPosition) + menu.exec(globalPosition) # Start the QApplication @@ -96,8 +99,8 @@ plot = PlotWidgetWithContextMenu() # Create the widget # Add content to the plot x = numpy.linspace(0, 2 * numpy.pi, 1000) -plot.addCurve(x, numpy.sin(x), legend='sin') +plot.addCurve(x, numpy.sin(x), legend="sin") # Show the widget and start the application plot.show() -app.exec_() +app.exec() |