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 GraphicsView import *
|
|
|
|
from PlotItem import *
|
|
|
|
import exceptions
|
|
|
|
|
|
|
|
class PlotWidget(GraphicsView):
|
|
|
|
"""Widget implementing a graphicsView with a single PlotItem inside."""
|
2010-07-24 18:29:09 +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)
|
2010-07-24 18:29:09 +00:00
|
|
|
self.plotItem = PlotItem(**kargs)
|
2010-03-22 05:48:52 +00:00
|
|
|
self.setCentralItem(self.plotItem)
|
|
|
|
## Explicitly wrap methods from plotItem
|
2010-07-24 18:29:09 +00:00
|
|
|
for m in ['addItem', 'removeItem', 'autoRange', 'clear', 'setXRange', 'setYRange']:
|
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)
|
|
|
|
|
2010-07-24 18:29:09 +00:00
|
|
|
#def __dtor__(self):
|
|
|
|
##print "Called plotWidget sip destructor"
|
|
|
|
#self.quit()
|
|
|
|
|
|
|
|
|
|
|
|
def quit(self):
|
|
|
|
self.plotItem.clear()
|
|
|
|
self.scene().clear()
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
def viewChanged(self, *args):
|
|
|
|
self.emit(QtCore.SIGNAL('viewChanged'), *args)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2010-07-24 18:29:09 +00:00
|
|
|
def getPlotItem(self):
|
|
|
|
return self.plotItem
|