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.
|
|
|
|
"""
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
2010-03-22 05:48:52 +00:00
|
|
|
from GraphicsView import *
|
2012-03-02 02:55:32 +00:00
|
|
|
from pyqtgraph.graphicsItems.PlotItem import *
|
2010-03-22 05:48:52 +00:00
|
|
|
import exceptions
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
__all__ = ['PlotWidget']
|
2010-03-22 05:48:52 +00:00
|
|
|
class PlotWidget(GraphicsView):
|
2011-04-05 14:35:50 +00:00
|
|
|
|
2011-06-14 23:47:52 +00:00
|
|
|
#sigRangeChanged = QtCore.Signal(object, object) ## already defined in GraphicsView
|
2011-04-05 14:35:50 +00:00
|
|
|
|
2010-03-22 05:48:52 +00:00
|
|
|
"""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
|
2012-03-12 16:23:25 +00:00
|
|
|
for m in ['addItem', 'removeItem', 'autoRange', 'clear', 'setXRange', 'setYRange', 'setRange']:
|
2010-03-22 05:48:52 +00:00
|
|
|
setattr(self, m, getattr(self.plotItem, m))
|
2011-04-05 14:35:50 +00:00
|
|
|
#QtCore.QObject.connect(self.plotItem, QtCore.SIGNAL('viewChanged'), self.viewChanged)
|
|
|
|
self.plotItem.sigRangeChanged.connect(self.viewRangeChanged)
|
2010-03-22 05:48:52 +00:00
|
|
|
|
2010-07-24 18:29:09 +00:00
|
|
|
#def __dtor__(self):
|
|
|
|
##print "Called plotWidget sip destructor"
|
|
|
|
#self.quit()
|
|
|
|
|
|
|
|
|
2011-04-05 14:35:50 +00:00
|
|
|
#def quit(self):
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
self.plotItem.close()
|
|
|
|
self.plotItem = None
|
|
|
|
#self.scene().clear()
|
|
|
|
#self.mPlotItem.close()
|
|
|
|
self.setParent(None)
|
2011-04-25 12:51:18 +00:00
|
|
|
GraphicsView.close(self)
|
2011-04-05 14:35:50 +00:00
|
|
|
|
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)
|
|
|
|
|
2011-04-05 14:35:50 +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)
|
|
|
|
|
2010-07-24 18:29:09 +00:00
|
|
|
def getPlotItem(self):
|
2011-02-08 00:40:38 +00:00
|
|
|
return self.plotItem
|
|
|
|
|
|
|
|
|
|
|
|
|