2 ## This file is part of the sigrok-meter project.
4 ## Copyright (C) 2015 Jens Steinhauser <jens.steinhauser@gmail.com>
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, write to the Free Software
18 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 QtCore = qtcompat.QtCore
24 QtGui = qtcompat.QtGui
25 pyqtgraph = qtcompat.pyqtgraph
27 # black foreground on white background
28 pyqtgraph.setConfigOption('background', 'w')
29 pyqtgraph.setConfigOption('foreground', 'k')
31 class MultiPlotItem(pyqtgraph.GraphicsWidget):
34 def __init__(self, view, xaxis, yaxis):
39 def __init__(self, parent=None):
40 pyqtgraph.GraphicsWidget.__init__(self, parent)
42 self.layout = QtGui.QGraphicsGridLayout()
43 self.layout.setContentsMargins(10, 10, 10, 1)
44 self.layout.setHorizontalSpacing(0)
45 self.layout.setVerticalSpacing(0)
46 self.setLayout(self.layout)
51 self.layout.setColumnPreferredWidth(i, 0)
52 self.layout.setColumnMinimumWidth(i, 0)
53 self.layout.setColumnSpacing(i, 0)
55 self.layout.setColumnStretchFactor(0, 0)
56 self.layout.setColumnStretchFactor(1, 100)
59 row = self.layout.rowCount()
61 view = pyqtgraph.ViewBox(parent=self)
63 view.setXLink(self._plots[-1].view)
64 self.layout.addItem(view, row, 1)
66 yaxis = pyqtgraph.AxisItem(parent=self, orientation='left')
67 yaxis.linkToView(view)
69 self.layout.addItem(yaxis, row, 0, QtCore.Qt.AlignRight)
71 xaxis = pyqtgraph.AxisItem(parent=self, orientation='bottom')
72 xaxis.linkToView(view)
74 self.layout.addItem(xaxis, row + 1, 1)
76 for i in range(row, row + 2):
77 self.layout.setRowPreferredHeight(i, 0)
78 self.layout.setRowMinimumHeight(i, 0)
79 self.layout.setRowSpacing(i, 0)
81 self.layout.setRowStretchFactor(row, 100)
82 self.layout.setRowStretchFactor(row + 1, 0)
84 p = MultiPlotItem.Plot(view, xaxis, yaxis)
88 class MultiPlotWidget(pyqtgraph.GraphicsView):
89 '''Widget that aligns multiple plots on top of each other.
91 (The built in classes fail at doing this correctly when the axis grow,
92 just try zooming in the "GraphicsLayout" or the "Linked View" examples.)'''
94 def __init__(self, parent=None):
95 pyqtgraph.GraphicsView.__init__(self, parent)
97 self.multiPlotItem = MultiPlotItem()
98 self.setCentralItem(self.multiPlotItem)
103 setattr(self, m, getattr(self.multiPlotItem, m))