<s> import sys <EOL> import warnings <EOL> import IECore <EOL> import GafferUI <EOL> import Gaffer <EOL> QtCore = GafferUI . _qtImport ( "<STR_LIT>" ) <EOL> QtGui = GafferUI . _qtImport ( "<STR_LIT>" ) <EOL> class Window ( GafferUI . ContainerWidget ) : <EOL> SizeMode = IECore . Enum . create ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def __init__ ( self , title = "<STR_LIT>" , borderWidth = <NUM_LIT:0> , resizeable = None , child = None , sizeMode = SizeMode . Manual , icon = "<STR_LIT>" , parenting = None ) : <EOL> GafferUI . ContainerWidget . __init__ ( <EOL> self , <EOL> QtGui . QWidget ( None , QtCore . Qt . WindowFlags ( QtCore . Qt . Window ) ) , <EOL> parenting = parenting <EOL> ) <EOL> self . __child = None <EOL> self . __childWindows = set ( ) <EOL> self . __qtLayout = QtGui . QGridLayout ( ) <EOL> self . __qtLayout . setContentsMargins ( borderWidth , borderWidth , borderWidth , borderWidth ) <EOL> self . __qtLayout . setSizeConstraint ( QtGui . QLayout . SetMinAndMaxSize ) <EOL> self . __sizeValid = False <EOL> if len ( self . __caughtKeys ( ) ) : <EOL> self . __keyPressConnection = self . keyPressSignal ( ) . connect ( Gaffer . WeakMethod ( self . __keyPress ) ) <EOL> self . _qtWidget ( ) . setFocusPolicy ( QtCore . Qt . ClickFocus ) <EOL> self . _qtWidget ( ) . setLayout ( self . __qtLayout ) <EOL> self . _qtWidget ( ) . installEventFilter ( _windowEventFilter ) <EOL> self . _qtWidget ( ) . setObjectName ( "<STR_LIT>" ) <EOL> self . _setStyleSheet ( ) <EOL> self . setTitle ( title ) <EOL> self . setIcon ( icon ) <EOL> if resizeable is not None : <EOL> self . setResizeable ( resizeable ) <EOL> else : <EOL> self . setSizeMode ( sizeMode ) <EOL> self . __closedSignal = GafferUI . WidgetSignal ( ) <EOL> self . setChild ( child ) <EOL> def setTitle ( self , title ) : <EOL> self . _qtWidget ( ) . setWindowTitle ( title ) <EOL> def getTitle ( self ) : <EOL> return self . _qtWidget ( ) . windowTitle ( ) <EOL> def setVisible ( self , visible ) : <EOL> GafferUI . Widget . setVisible ( self , visible ) <EOL> if self . visible ( ) : <EOL> if self . _qtWidget ( ) . isMinimized ( ) : <EOL> self . _qtWidget ( ) . showNormal ( ) <EOL> self . _qtWidget ( ) . raise_ ( ) <EOL> def removeChild ( self , child ) : <EOL> assert ( child is self . __child or child in self . __childWindows ) <EOL> child . _qtWidget ( ) . setParent ( None ) <EOL> child . _applyVisibility ( ) <EOL> if child is self . __child : <EOL> self . __child = None <EOL> else : <EOL> self . __childWindows . remove ( child ) <EOL> def addChild ( self , child ) : <EOL> if isinstance ( child , Window ) : <EOL> self . addChildWindow ( child ) <EOL> else : <EOL> if self . getChild ( ) is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . setChild ( child ) <EOL> def setChild ( self , child ) : <EOL> oldChild = self . getChild ( ) <EOL> if oldChild is not None : <EOL> self . removeChild ( oldChild ) <EOL> if child is not None : <EOL> oldParent = child . parent ( ) <EOL> if oldParent is not None : <EOL> oldParent . removeChild ( child ) <EOL> self . __child = child <EOL> self . __qtLayout . addWidget ( child . _qtWidget ( ) , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> child . _applyVisibility ( ) <EOL> def getChild ( self ) : <EOL> return self . __child <EOL> def addChildWindow ( self , childWindow , removeOnClose = False ) : <EOL> assert ( isinstance ( childWindow , Window ) ) <EOL> oldParent = childWindow . parent ( ) <EOL> if oldParent is not None : <EOL> oldParent . removeChild ( childWindow ) <EOL> self . __childWindows . add ( childWindow ) <EOL> childWindowType = QtCore . Qt . Tool if sys . platform == "<STR_LIT>" else QtCore . Qt . Dialog <EOL> childWindowFlags = ( childWindow . _qtWidget ( ) . windowFlags ( ) & ~ QtCore . Qt . WindowType_Mask ) | childWindowType <EOL> childWindow . _qtWidget ( ) . setParent ( self . _qtWidget ( ) , childWindowFlags ) <EOL> childWindow . _applyVisibility ( ) <EOL> if removeOnClose : <EOL> childWindow . __removeOnCloseConnection = childWindow . closedSignal ( ) . connect ( lambda w : w . parent ( ) . removeChild ( w ) ) <EOL> def childWindows ( self ) : <EOL> return list ( self . __childWindows ) <EOL> def setResizeable ( self , resizeable ) : <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning , <NUM_LIT:2> ) <EOL> if resizeable : <EOL> self . setSizeMode ( self . SizeMode . Manual ) <EOL> else : <EOL> self . setSizeMode ( self . SizeMode . Fixed ) <EOL> def getResizeable ( self ) : <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning , <NUM_LIT:2> ) <EOL> return self . getSizeMode ( ) == self . SizeMode . Manual <EOL> def setSizeMode ( self , sizeMode ) : <EOL> self . __sizeMode = sizeMode <EOL> if sizeMode == self . SizeMode . Manual : <EOL> self . __qtLayout . setSizeConstraint ( QtGui . QLayout . SetDefaultConstraint ) <EOL> else : <EOL> self . __qtLayout . setSizeConstraint ( QtGui . QLayout . SetFixedSize ) <EOL> def getSizeMode ( self ) : <EOL> return self . __sizeMode <EOL> def resizeToFitChild ( self , shrink = True , expand = True ) : <EOL> s = self . _qtWidget ( ) . size ( ) <EOL> sizeHint = self . _qtWidget ( ) . sizeHint ( ) <EOL> if expand or not self . __sizeValid : <EOL> s = s . expandedTo ( sizeHint ) <EOL> if shrink or not self . __sizeValid : <EOL> s = s . boundedTo ( sizeHint ) <EOL> self . _qtWidget ( ) . resize ( s ) <EOL> def setPosition ( self , position ) : <EOL> self . _qtWidget ( ) . move ( position . x , position . y ) <EOL> def getPosition ( self ) : <EOL> return IECore . V2i ( self . _qtWidget ( ) . x ( ) , self . _qtWidget ( ) . y ( ) ) <EOL> def setFullScreen ( self , fullScreen ) : <EOL> if fullScreen : <EOL> self . _qtWidget ( ) . showFullScreen ( ) <EOL> else : <EOL> self . _qtWidget ( ) . showNormal ( ) <EOL> def getFullScreen ( self ) : <EOL> return self . _qtWidget ( ) . isFullScreen ( ) <EOL> def setIcon ( self , imageOrImageFileName ) : <EOL> if isinstance ( imageOrImageFileName , basestring ) : <EOL> self . __image = GafferUI . Image ( imageOrImageFileName ) <EOL> else : <EOL> self . __image = imageOrImageFileName <EOL> self . _qtWidget ( ) . setWindowIcon ( QtGui . QIcon ( self . __image . _qtPixmap ( ) ) ) <EOL> def getIcon ( self ) : <EOL> return self . __image <EOL> def close ( self ) : <EOL> if not self . getVisible ( ) : <EOL> return False <EOL> if self . _acceptsClose ( ) : <EOL> self . setVisible ( False ) <EOL> self . closedSignal ( ) ( self ) <EOL> return True <EOL> else : <EOL> return False <EOL> def _acceptsClose ( self ) : <EOL> return True <EOL> def closedSignal ( self ) : <EOL> return self . __closedSignal <EOL> __caughtKeysSet = None <EOL> @ classmethod <EOL> def __caughtKeys ( cls ) : <EOL> if cls . __caughtKeysSet is None : <EOL> try : <EOL> import maya <EOL> cls . __caughtKeysSet = set ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> except ImportError : <EOL> cls . __caughtKeysSet = set ( ) <EOL> return cls . __caughtKeysSet <EOL> def __keyPress ( self , widget , event ) : <EOL> return event . key in self . __caughtKeys ( ) <EOL> class _WindowEventFilter ( QtCore . QObject ) : <EOL> def __init__ ( self ) : <EOL> QtCore . QObject . __init__ ( self ) <EOL> def eventFilter ( self , qObject , qEvent ) : <EOL> type = qEvent . type ( ) <EOL> if type == QtCore . QEvent . Close : <EOL> widget = GafferUI . Widget . _owner ( qObject ) <EOL> closed = widget . close ( ) <EOL> if closed : <EOL> qEvent . accept ( ) <EOL> else : <EOL> qEvent . ignore ( ) <EOL> return True <EOL> elif type == QtCore . QEvent . LayoutRequest : <EOL> widget = GafferUI . Widget . _owner ( qObject ) <EOL> if widget . getSizeMode ( ) == widget . SizeMode . Automatic : <EOL> widget . resizeToFitChild ( ) <EOL> return True <EOL> elif type == QtCore . QEvent . Resize : <EOL> widget = GafferUI . Widget . _owner ( qObject ) <EOL> widget . _Window__sizeValid = True <EOL> return False <EOL> _windowEventFilter = _WindowEventFilter ( ) </s>
