summaryrefslogtreecommitdiff
path: root/examples/printPreview.py
blob: 187ad845f319f0e282fc89ad1c8c0cffe1ba4fff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 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
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
"""This script illustrates how to add a print preview tool button to any plot
widget inheriting :class:`PlotWidget`.

Three plot widgets are instantiated. One of them uses a standalone
:class:`PrintPreviewToolButton`, while the other two use a
:class:`SingletonPrintPreviewToolButton` which allows them to send their content
to the same print preview page.
"""
__authors__ = ["P. Knobel"]
__license__ = "MIT"
__date__ = "25/07/2017"

import numpy

from silx.gui import qt
from silx.gui.plot import PlotWidget
from silx.gui.plot import PrintPreviewToolButton

app = qt.QApplication([])

x = numpy.arange(1000)

# first widget has a standalone print preview action
pw1 = PlotWidget()
pw1.setWindowTitle("Widget 1 with standalone print preview")
toolbar1 = qt.QToolBar(pw1)
toolbutton1 = PrintPreviewToolButton.PrintPreviewToolButton(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
pw2 = PlotWidget()
pw2.setWindowTitle("Widget 2 with shared print preview")
toolbar2 = qt.QToolBar(pw2)
toolbutton2 = PrintPreviewToolButton.SingletonPrintPreviewToolButton(
        parent=toolbar2, plot=pw2)
pw2.addToolBar(toolbar2)
toolbar2.addWidget(toolbutton2)
pw2.show()
pw2.addCurve(x, numpy.sin(x * 2 * numpy.pi / 1000))


pw3 = PlotWidget()
pw3.setWindowTitle("Widget 3 with shared print preview")
toolbar3 = qt.QToolBar(pw3)
toolbutton3 = PrintPreviewToolButton.SingletonPrintPreviewToolButton(
        parent=toolbar3, plot=pw3)
pw3.addToolBar(toolbar3)
toolbar3.addWidget(toolbutton3)
pw3.show()
pw3.addCurve(x, numpy.cos(x * 2 * numpy.pi / 1000))


app.exec_()