<s> import logging <EOL> logging . getLogger ( "<STR_LIT>" ) . setLevel ( logging . WARNING ) <EOL> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> import _GafferUI <EOL> GL = Gaffer . lazyImport ( "<STR_LIT>" ) <EOL> IECoreGL = Gaffer . lazyImport ( "<STR_LIT>" ) <EOL> QtCore = GafferUI . _qtImport ( "<STR_LIT>" ) <EOL> QtGui = GafferUI . _qtImport ( "<STR_LIT>" ) <EOL> QtOpenGL = GafferUI . _qtImport ( "<STR_LIT>" , lazy = True ) <EOL> class GLWidget ( GafferUI . Widget ) : <EOL> BufferOptions = IECore . Enum . create ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ) <EOL> def __init__ ( self , bufferOptions = set ( ) , parenting = None ) : <EOL> format = QtOpenGL . QGLFormat ( ) <EOL> format . setRgba ( True ) <EOL> format . setAlpha ( self . BufferOptions . Alpha in bufferOptions ) <EOL> format . setDepth ( self . BufferOptions . Depth in bufferOptions ) <EOL> format . setDoubleBuffer ( self . BufferOptions . Double in bufferOptions ) <EOL> if hasattr ( format , "<STR_LIT>" ) : <EOL> format . setVersion ( <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> graphicsView = _GLGraphicsView ( format ) <EOL> self . __graphicsScene = _GLGraphicsScene ( graphicsView , Gaffer . WeakMethod ( self . __draw ) ) <EOL> graphicsView . setScene ( self . __graphicsScene ) <EOL> GafferUI . Widget . __init__ ( self , graphicsView , parenting = parenting ) <EOL> self . __overlay = None <EOL> def setOverlay ( self , overlay ) : <EOL> if overlay is self . __overlay : <EOL> return <EOL> if self . __overlay is not None : <EOL> self . removeChild ( self . __overlay ) <EOL> if overlay is not None : <EOL> oldParent = overlay . parent ( ) <EOL> if oldParent is not None : <EOL> oldParent . removeChild ( child ) <EOL> self . __overlay = overlay <EOL> self . __overlay . _setStyleSheet ( ) <EOL> self . __graphicsScene . setOverlay ( self . __overlay ) <EOL> def getOverlay ( self ) : <EOL> return self . __overlay <EOL> def removeChild ( self , child ) : <EOL> assert ( child is self . __overlay ) <EOL> self . __overlay = None <EOL> self . __graphicsScene . setOverlay ( None ) <EOL> def _resize ( self , size ) : <EOL> GL . glViewport ( <NUM_LIT:0> , <NUM_LIT:0> , size . x , size . y ) <EOL> def _draw ( self ) : <EOL> pass <EOL> def _redraw ( self ) : <EOL> self . _glWidget ( ) . update ( ) <EOL> def _glWidget ( self ) : <EOL> return self . _qtWidget ( ) . viewport ( ) <EOL> def _makeCurrent ( self ) : <EOL> self . _qtWidget ( ) . viewport ( ) . makeCurrent ( ) <EOL> return self . __framebufferValid ( ) <EOL> def __framebufferValid ( self ) : <EOL> import OpenGL . GL . framebufferobjects <EOL> return GL . framebufferobjects . glCheckFramebufferStatus ( GL . framebufferobjects . GL_FRAMEBUFFER ) == GL . framebufferobjects . GL_FRAMEBUFFER_COMPLETE <EOL> def __draw ( self ) : <EOL> while GL . glGetError ( ) : <EOL> pass <EOL> if not self . __framebufferValid ( ) : <EOL> return <EOL> IECoreGL . init ( True ) <EOL> self . _draw ( ) <EOL> class _GLGraphicsView ( QtGui . QGraphicsView ) : <EOL> def __init__ ( self , format ) : <EOL> QtGui . QGraphicsView . __init__ ( self ) <EOL> self . setObjectName ( "<STR_LIT>" ) <EOL> self . setHorizontalScrollBarPolicy ( QtCore . Qt . ScrollBarAlwaysOff ) <EOL> self . setVerticalScrollBarPolicy ( QtCore . Qt . ScrollBarAlwaysOff ) <EOL> glWidget = self . __createQGLWidget ( format ) <EOL> glWidget . hide ( ) <EOL> self . setViewport ( glWidget ) <EOL> self . setViewportUpdateMode ( self . FullViewportUpdate ) <EOL> def minimumSizeHint ( self ) : <EOL> return QtCore . QSize ( ) <EOL> def event ( self , event ) : <EOL> if event . type ( ) == event . PolishRequest : <EOL> self . viewport ( ) . show ( ) <EOL> return QtGui . QGraphicsView . event ( self , event ) <EOL> def resizeEvent ( self , event ) : <EOL> if self . scene ( ) is not None : <EOL> self . scene ( ) . setSceneRect ( <NUM_LIT:0> , <NUM_LIT:0> , event . size ( ) . width ( ) , event . size ( ) . height ( ) ) <EOL> owner = GafferUI . Widget . _owner ( self ) <EOL> while GL . glGetError ( ) : <EOL> pass <EOL> owner . _makeCurrent ( ) <EOL> owner . _resize ( IECore . V2i ( event . size ( ) . width ( ) , event . size ( ) . height ( ) ) ) <EOL> def keyPressEvent ( self , event ) : <EOL> if self . scene ( ) is not None and self . isInteractive ( ) : <EOL> QtGui . QApplication . sendEvent ( self . scene ( ) , event ) <EOL> if event . isAccepted ( ) : <EOL> return <EOL> QtGui . QFrame . keyPressEvent ( self , event ) <EOL> __shareWidget = None <EOL> @ classmethod <EOL> def __createQGLWidget ( cls , format ) : <EOL> result = cls . __createMayaQGLWidget ( format ) <EOL> if result is not None : <EOL> return result <EOL> result = cls . __createHoudiniQGLWidget ( format ) <EOL> if result is not None : <EOL> return result <EOL> if cls . __shareWidget is None : <EOL> cls . __shareWidget = QtOpenGL . QGLWidget ( ) <EOL> return QtOpenGL . QGLWidget ( format , shareWidget = cls . __shareWidget ) <EOL> @ classmethod <EOL> def __createHostedQGLWidget ( cls , format ) : <EOL> result = QtOpenGL . QGLWidget ( ) <EOL> _GafferUI . _glWidgetSetHostedContext ( GafferUI . _qtAddress ( result ) , GafferUI . _qtAddress ( format ) ) <EOL> return result <EOL> @ classmethod <EOL> def __createMayaQGLWidget ( cls , format ) : <EOL> try : <EOL> import maya . OpenMayaRender <EOL> except ImportError : <EOL> return None <EOL> mayaRenderer = maya . OpenMayaRender . MHardwareRenderer . theRenderer ( ) <EOL> mayaRenderer . makeResourceContextCurrent ( mayaRenderer . backEndString ( ) ) <EOL> return cls . __createHostedQGLWidget ( format ) <EOL> @ classmethod <EOL> def __createHoudiniQGLWidget ( cls , format ) : <EOL> try : <EOL> import hou <EOL> except ImportError : <EOL> return None <EOL> import IECoreHoudini <EOL> if hou . applicationVersion ( ) [ <NUM_LIT:0> ] < <NUM_LIT> : <EOL> IECoreHoudini . makeMainGLContextCurrent ( ) <EOL> return cls . __createHostedQGLWidget ( format ) <EOL> return QtOpenGL . QGLWidget ( format , shareWidget = GafferUI . _qtObject ( IECoreHoudini . sharedGLWidget ( ) , QtOpenGL . QGLWidget ) ) <EOL> class _GLGraphicsScene ( QtGui . QGraphicsScene ) : <EOL> def __init__ ( self , parent , backgroundDrawFunction ) : <EOL> QtGui . QGraphicsScene . __init__ ( self , parent ) <EOL> self . __backgroundDrawFunction = backgroundDrawFunction <EOL> self . sceneRectChanged . connect ( self . __sceneRectChanged ) <EOL> self . __overlay = None <EOL> self . __overlayProxy = None <EOL> def setOverlay ( self , widget ) : <EOL> if self . __overlay is not None : <EOL> self . __overlayProxy . setWidget ( None ) <EOL> self . removeItem ( self . __overlayProxy ) <EOL> self . __overlay = None <EOL> self . __overlayProxy = None <EOL> if widget is None : <EOL> return <EOL> self . __overlay = widget <EOL> if widget . _qtWidget ( ) . layout ( ) is not None : <EOL> widget . _qtWidget ( ) . layout ( ) . setSizeConstraint ( QtGui . QLayout . SetNoConstraint ) <EOL> self . __overlayProxy = _OverlayProxyWidget ( ) <EOL> self . __overlayProxy . setWidget ( self . __overlay . _qtWidget ( ) ) <EOL> self . addItem ( self . __overlayProxy ) <EOL> self . __updateItemGeometry ( self . __overlayProxy , self . sceneRect ( ) ) <EOL> def drawBackground ( self , painter , rect ) : <EOL> self . __backgroundDrawFunction ( ) <EOL> GL . glPixelStorei ( GL . GL_UNPACK_ALIGNMENT , <NUM_LIT:4> ) ; <EOL> def __sceneRectChanged ( self , sceneRect ) : <EOL> if self . __overlayProxy is not None : <EOL> self . __updateItemGeometry ( self . __overlayProxy , sceneRect ) <EOL> def __updateItemGeometry ( self , item , sceneRect ) : <EOL> geometry = item . widget ( ) . geometry ( ) <EOL> item . widget ( ) . setGeometry ( QtCore . QRect ( <NUM_LIT:0> , <NUM_LIT:0> , sceneRect . width ( ) , sceneRect . height ( ) ) ) <EOL> class _OverlayProxyWidget ( QtGui . QGraphicsProxyWidget ) : <EOL> def __init__ ( self ) : <EOL> QtGui . QGraphicsProxyWidget . __init__ ( self ) <EOL> def shape ( self ) : <EOL> path = QtGui . QPainterPath ( ) <EOL> path . addRegion ( self . widget ( ) . childrenRegion ( ) ) <EOL> return path </s>
