pyqtgraph/widgets/PlotWidget.py

90 lines
3.5 KiB
Python
Raw Normal View History

2010-03-22 05:48:52 +00:00
# -*- coding: utf-8 -*-
"""
PlotWidget.py - Convenience class--GraphicsView widget displaying a single PlotItem
Copyright 2010 Luke Campagnola
Distributed under MIT/X11 license. See license.txt for more infomation.
"""
from pyqtgraph.Qt import QtCore, QtGui
2010-03-22 05:48:52 +00:00
from GraphicsView import *
from pyqtgraph.graphicsItems.PlotItem import *
2010-03-22 05:48:52 +00:00
import exceptions
__all__ = ['PlotWidget']
2010-03-22 05:48:52 +00:00
class PlotWidget(GraphicsView):
#sigRangeChanged = QtCore.Signal(object, object) ## already defined in GraphicsView
2012-04-15 14:20:07 +00:00
"""
2012-04-18 04:02:15 +00:00
:class:`GraphicsView <pyqtgraph.GraphicsView>` widget with a single
:class:`PlotItem <pyqtgraph.PlotItem>` inside.
2012-04-15 14:20:07 +00:00
2012-04-18 04:02:15 +00:00
The following methods are wrapped directly from PlotItem:
:func:`addItem <pyqtgraph.PlotItem.addItem>`,
:func:`removeItem <pyqtgraph.PlotItem.removeItem>`,
:func:`clear <pyqtgraph.PlotItem.clear>`,
:func:`setXRange <pyqtgraph.ViewBox.setXRange>`,
:func:`setYRange <pyqtgraph.ViewBox.setYRange>`,
:func:`setRange <pyqtgraph.ViewBox.setRange>`,
:func:`autoRange <pyqtgraph.ViewBox.autoRange>`,
:func:`setXLink <pyqtgraph.ViewBox.setXLink>`,
:func:`setYLink <pyqtgraph.ViewBox.setYLink>`,
:func:`viewRect <pyqtgraph.ViewBox.viewRect>`,
:func:`setMouseEnabled <pyqtgraph.ViewBox.setMouseEnabled>`,
:func:`enableAutoRange <pyqtgraph.ViewBox.enableAutoRange>`,
:func:`disableAutoRange <pyqtgraph.ViewBox.disableAutoRange>`,
:func:`setAspectLocked <pyqtgraph.ViewBox.setAspectLocked>`,
:func:`register <pyqtgraph.ViewBox.register>`,
:func:`unregister <pyqtgraph.ViewBox.unregister>`
For all
other methods, use :func:`getPlotItem <pyqtgraph.PlotWidget.getPlotItem>`.
2012-04-15 14:20:07 +00:00
"""
def __init__(self, parent=None, **kargs):
2010-03-22 05:48:52 +00:00
GraphicsView.__init__(self, parent)
self.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.enableMouse(False)
self.plotItem = PlotItem(**kargs)
2010-03-22 05:48:52 +00:00
self.setCentralItem(self.plotItem)
## Explicitly wrap methods from plotItem
2012-04-18 04:02:15 +00:00
## NOTE: If you change this list, update the documentation above as well.
for m in ['addItem', 'removeItem', 'autoRange', 'clear', 'setXRange', 'setYRange', 'setRange', 'setAspectLocked', 'setMouseEnabled', 'setXLink', 'setYLink', 'enableAutoRange', 'disableAutoRange', 'register', 'unregister', 'viewRect']:
2010-03-22 05:48:52 +00:00
setattr(self, m, getattr(self.plotItem, m))
#QtCore.QObject.connect(self.plotItem, QtCore.SIGNAL('viewChanged'), self.viewChanged)
self.plotItem.sigRangeChanged.connect(self.viewRangeChanged)
2012-04-15 14:20:07 +00:00
def close(self):
self.plotItem.close()
self.plotItem = None
#self.scene().clear()
#self.mPlotItem.close()
self.setParent(None)
GraphicsView.close(self)
2010-03-22 05:48:52 +00:00
def __getattr__(self, attr): ## implicitly wrap methods from plotItem
if hasattr(self.plotItem, attr):
m = getattr(self.plotItem, attr)
if hasattr(m, '__call__'):
return m
raise exceptions.NameError(attr)
2012-04-15 14:20:07 +00:00
def viewRangeChanged(self, view, range):
#self.emit(QtCore.SIGNAL('viewChanged'), *args)
self.sigRangeChanged.emit(self, range)
2010-03-22 05:48:52 +00:00
def widgetGroupInterface(self):
return (None, PlotWidget.saveState, PlotWidget.restoreState)
def saveState(self):
return self.plotItem.saveState()
def restoreState(self, state):
return self.plotItem.restoreState(state)
def getPlotItem(self):
2012-04-15 14:20:07 +00:00
"""Return the PlotItem contained within."""
return self.plotItem