summaryrefslogtreecommitdiff
path: root/examples/printPreview.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/printPreview.py')
-rwxr-xr-xexamples/printPreview.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/examples/printPreview.py b/examples/printPreview.py
index 7567adb..cae1018 100755
--- a/examples/printPreview.py
+++ b/examples/printPreview.py
@@ -1,8 +1,7 @@
#!/usr/bin/env python
-# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2016-2018 European Synchrotron Radiation Facility
+# Copyright (c) 2016-2021 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
@@ -42,27 +41,45 @@ from silx.gui import qt
from silx.gui.plot import PlotWidget
from silx.gui.plot import PrintPreviewToolButton
+
+class MyPrintPreviewButton(PrintPreviewToolButton.PrintPreviewToolButton):
+ """This class illustrates how to subclass PrintPreviewToolButton
+ to add a title and a comment."""
+
+ def getTitle(self):
+ return "Widget 1's plot"
+
+ def getCommentAndPosition(self):
+ legends = self.getPlot().getAllCurves(just_legend=True)
+ comment = "Curves displayed in widget 1:\n\t"
+ if legends:
+ comment += ", ".join(legends)
+ else:
+ comment += "none"
+ return comment, "CENTER"
+
+
app = qt.QApplication([])
x = numpy.arange(1000)
-# first widget has a standalone print preview action
+# first widget has a standalone preview action with custom title and comment
pw1 = PlotWidget()
pw1.setWindowTitle("Widget 1 with standalone print preview")
toolbar1 = qt.QToolBar(pw1)
-toolbutton1 = PrintPreviewToolButton.PrintPreviewToolButton(parent=toolbar1,
- plot=pw1)
+toolbutton1 = MyPrintPreviewButton(parent=toolbar1, plot=pw1)
pw1.addToolBar(toolbar1)
toolbar1.addWidget(toolbutton1)
pw1.show()
pw1.addCurve(x, numpy.tan(x * 2 * numpy.pi / 1000))
-# next two plots share a common print preview
+# next two plots share a common standard print preview
pw2 = PlotWidget()
pw2.setWindowTitle("Widget 2 with shared print preview")
toolbar2 = qt.QToolBar(pw2)
toolbutton2 = PrintPreviewToolButton.SingletonPrintPreviewToolButton(
- parent=toolbar2, plot=pw2)
+ parent=toolbar2, plot=pw2
+)
pw2.addToolBar(toolbar2)
toolbar2.addWidget(toolbutton2)
pw2.show()
@@ -73,11 +90,12 @@ pw3 = PlotWidget()
pw3.setWindowTitle("Widget 3 with shared print preview")
toolbar3 = qt.QToolBar(pw3)
toolbutton3 = PrintPreviewToolButton.SingletonPrintPreviewToolButton(
- parent=toolbar3, plot=pw3)
+ parent=toolbar3, plot=pw3
+)
pw3.addToolBar(toolbar3)
toolbar3.addWidget(toolbutton3)
pw3.show()
pw3.addCurve(x, numpy.cos(x * 2 * numpy.pi / 1000))
-app.exec_()
+app.exec()