2010-03-22 05:48:52 +00:00
# -*- coding: utf-8 -*-
"""
MultiPlotWidget . py - Convenience class - - GraphicsView widget displaying a MultiPlotItem
Copyright 2010 Luke Campagnola
2017-11-20 10:20:17 +00:00
Distributed under MIT / X11 license . See license . txt for more information .
2010-03-22 05:48:52 +00:00
"""
2014-01-25 13:50:31 +00:00
from . . Qt import QtCore
2012-05-11 22:05:41 +00:00
from . GraphicsView import GraphicsView
2013-12-22 07:18:37 +00:00
from . . graphicsItems import MultiPlotItem as MultiPlotItem
2010-03-22 05:48:52 +00:00
2012-03-02 02:55:32 +00:00
__all__ = [ ' MultiPlotWidget ' ]
2010-03-22 05:48:52 +00:00
class MultiPlotWidget ( GraphicsView ) :
2020-07-19 21:26:02 +00:00
""" Widget implementing a :class:`~pyqtgraph.GraphicsView` with a single
: class : ` ~ pyqtgraph . MultiPlotItem ` inside . """
2010-03-22 05:48:52 +00:00
def __init__ ( self , parent = None ) :
2014-01-25 13:58:54 +00:00
self . minPlotHeight = 50
2014-01-25 13:50:31 +00:00
self . mPlotItem = MultiPlotItem . MultiPlotItem ( )
2010-03-22 05:48:52 +00:00
GraphicsView . __init__ ( self , parent )
self . enableMouse ( False )
self . setCentralItem ( self . mPlotItem )
## Explicitly wrap methods from mPlotItem
#for m in ['setData']:
#setattr(self, m, getattr(self.mPlotItem, m))
2014-01-25 13:50:31 +00:00
self . setVerticalScrollBarPolicy ( QtCore . Qt . ScrollBarAsNeeded )
self . setHorizontalScrollBarPolicy ( QtCore . Qt . ScrollBarAsNeeded )
2010-03-22 05:48:52 +00:00
def __getattr__ ( self , attr ) : ## implicitly wrap methods from plotItem
if hasattr ( self . mPlotItem , attr ) :
m = getattr ( self . mPlotItem , attr )
if hasattr ( m , ' __call__ ' ) :
return m
2014-01-25 12:37:04 +00:00
raise AttributeError ( attr )
2014-01-25 13:58:54 +00:00
def setMinimumPlotHeight ( self , min ) :
""" Set the minimum height for each sub-plot displayed.
If the total height of all plots is greater than the height of the
widget , then a scroll bar will appear to provide access to the entire
set of plots .
2014-04-11 14:54:21 +00:00
Added in version 0.9 .9
2014-01-25 13:58:54 +00:00
"""
self . minPlotHeight = min
self . resizeEvent ( None )
2010-03-22 05:48:52 +00:00
def widgetGroupInterface ( self ) :
return ( None , MultiPlotWidget . saveState , MultiPlotWidget . restoreState )
def saveState ( self ) :
return { }
#return self.plotItem.saveState()
def restoreState ( self , state ) :
pass
#return self.plotItem.restoreState(state)
2011-04-05 14:35:50 +00:00
def close ( self ) :
self . mPlotItem . close ( )
2011-04-25 12:51:18 +00:00
self . mPlotItem = None
self . setParent ( None )
2013-12-22 07:18:37 +00:00
GraphicsView . close ( self )
2014-01-25 13:50:31 +00:00
def setRange ( self , * args , * * kwds ) :
GraphicsView . setRange ( self , * args , * * kwds )
if self . centralWidget is not None :
r = self . range
minHeight = len ( self . mPlotItem . plots ) * self . minPlotHeight
if r . height ( ) < minHeight :
r . setHeight ( minHeight )
2014-01-25 13:58:54 +00:00
r . setWidth ( r . width ( ) - self . verticalScrollBar ( ) . width ( ) )
2014-01-25 13:50:31 +00:00
self . centralWidget . setGeometry ( r )
def resizeEvent ( self , ev ) :
if self . closed :
return
if self . autoPixelRange :
self . range = QtCore . QRectF ( 0 , 0 , self . size ( ) . width ( ) , self . size ( ) . height ( ) )
MultiPlotWidget . setRange ( self , self . range , padding = 0 , disableAutoPixel = False ) ## we do this because some subclasses like to redefine setRange in an incompatible way.
self . updateMatrix ( )