<s> from __future__ import with_statement <EOL> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> class BoolPlugValueWidget ( GafferUI . PlugValueWidget ) : <EOL> def __init__ ( self , plug , displayMode = GafferUI . BoolWidget . DisplayMode . CheckBox , parenting = None ) : <EOL> self . __boolWidget = GafferUI . BoolWidget ( displayMode = displayMode ) <EOL> GafferUI . PlugValueWidget . __init__ ( self , self . __boolWidget , plug , parenting = parenting ) <EOL> self . _addPopupMenu ( self . __boolWidget ) <EOL> self . __stateChangedConnection = self . __boolWidget . stateChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __stateChanged ) ) <EOL> self . _updateFromPlug ( ) <EOL> def setHighlighted ( self , highlighted ) : <EOL> GafferUI . PlugValueWidget . setHighlighted ( self , highlighted ) <EOL> self . __boolWidget . setHighlighted ( highlighted ) <EOL> def _updateFromPlug ( self ) : <EOL> if self . getPlug ( ) is not None : <EOL> value = None <EOL> with self . getContext ( ) : <EOL> with IECore . IgnoredExceptions ( Exception ) : <EOL> value = self . getPlug ( ) . getValue ( ) <EOL> if value is not None : <EOL> with Gaffer . BlockedConnection ( self . __stateChangedConnection ) : <EOL> self . __boolWidget . setState ( value ) <EOL> displayMode = Gaffer . Metadata . plugValue ( self . getPlug ( ) , "<STR_LIT>" ) <EOL> if displayMode is not None : <EOL> self . __boolWidget . setDisplayMode ( self . __boolWidget . DisplayMode . Switch if displayMode == "<STR_LIT>" else self . __boolWidget . DisplayMode . CheckBox ) <EOL> self . __boolWidget . setEnabled ( self . _editable ( canEditAnimation = True ) ) <EOL> def __stateChanged ( self , widget ) : <EOL> self . __setPlugValue ( ) <EOL> return False <EOL> def __setPlugValue ( self ) : <EOL> with Gaffer . UndoContext ( self . getPlug ( ) . ancestor ( Gaffer . ScriptNode ) ) : <EOL> if Gaffer . Animation . isAnimated ( self . getPlug ( ) ) : <EOL> curve = Gaffer . Animation . acquire ( self . getPlug ( ) ) <EOL> curve . addKey ( <EOL> Gaffer . Animation . Key ( <EOL> time = self . getContext ( ) . getTime ( ) , <EOL> value = self . __boolWidget . getState ( ) , <EOL> type = Gaffer . Animation . Type . Step <EOL> ) <EOL> ) <EOL> else : <EOL> self . getPlug ( ) . setValue ( self . __boolWidget . getState ( ) ) <EOL> GafferUI . PlugValueWidget . registerType ( Gaffer . BoolPlug , BoolPlugValueWidget ) </s>
