<s> from __future__ import with_statement <EOL> import Gaffer <EOL> import GafferUI <EOL> class NumericPlugValueWidget ( GafferUI . PlugValueWidget ) : <EOL> def __init__ ( self , plug , parenting = None ) : <EOL> self . __numericWidget = GafferUI . NumericWidget ( <NUM_LIT:0> ) <EOL> GafferUI . PlugValueWidget . __init__ ( self , self . __numericWidget , plug , parenting = parenting ) <EOL> self . _addPopupMenu ( self . __numericWidget ) <EOL> self . __lastChangedReason = None <EOL> self . __mergeGroupId = <NUM_LIT:0> <EOL> self . __keyPressConnection = self . __numericWidget . keyPressSignal ( ) . connect ( Gaffer . WeakMethod ( self . __keyPress ) ) <EOL> self . __valueChangedConnection = self . __numericWidget . valueChangedSignal ( ) . connect ( Gaffer . WeakMethod ( self . __valueChanged ) ) <EOL> self . _updateFromPlug ( ) <EOL> self . __updateWidth ( ) <EOL> def setPlug ( self , plug ) : <EOL> GafferUI . PlugValueWidget . setPlug ( self , plug ) <EOL> self . __updateWidth ( ) <EOL> def numericWidget ( self ) : <EOL> return self . __numericWidget <EOL> def setHighlighted ( self , highlighted ) : <EOL> GafferUI . PlugValueWidget . setHighlighted ( self , highlighted ) <EOL> self . numericWidget ( ) . setHighlighted ( highlighted ) <EOL> def getToolTip ( self ) : <EOL> result = GafferUI . PlugValueWidget . getToolTip ( self ) <EOL> if self . getPlug ( ) is not None : <EOL> result += "<STR_LIT>" <EOL> result += "<STR_LIT>" <EOL> result += "<STR_LIT>" <EOL> return result <EOL> def _updateFromPlug ( self ) : <EOL> plug = self . getPlug ( ) <EOL> if plug is not None : <EOL> with self . getContext ( ) : <EOL> try : <EOL> value = plug . getValue ( ) <EOL> except : <EOL> value = None <EOL> if value is not None : <EOL> with Gaffer . BlockedConnection ( self . __valueChangedConnection ) : <EOL> self . __numericWidget . setValue ( value ) <EOL> self . __numericWidget . setErrored ( value is None ) <EOL> animated = Gaffer . Animation . isAnimated ( plug ) <EOL> widgetAnimated = GafferUI . _Variant . fromVariant ( self . __numericWidget . _qtWidget ( ) . property ( "<STR_LIT>" ) ) or False <EOL> if widgetAnimated != animated : <EOL> self . __numericWidget . _qtWidget ( ) . setProperty ( "<STR_LIT>" , GafferUI . _Variant . toVariant ( bool ( animated ) ) ) <EOL> self . __numericWidget . _repolish ( ) <EOL> self . __numericWidget . setEditable ( self . _editable ( canEditAnimation = True ) ) <EOL> def __keyPress ( self , widget , event ) : <EOL> assert ( widget is self . __numericWidget ) <EOL> if not self . __numericWidget . getEditable ( ) : <EOL> return False <EOL> if event . key == "<STR_LIT>" : <EOL> self . _updateFromPlug ( ) <EOL> return True <EOL> return False <EOL> def __valueChanged ( self , widget , reason ) : <EOL> if self . _editable ( canEditAnimation = True ) : <EOL> if not widget . changesShouldBeMerged ( self . __lastChangedReason , reason ) : <EOL> self . __mergeGroupId += <NUM_LIT:1> <EOL> self . __lastChangedReason = reason <EOL> self . __setPlugValue ( mergeGroup = "<STR_LIT>" % ( id ( self , ) , self . __mergeGroupId ) ) <EOL> return False <EOL> def __setPlugValue ( self , mergeGroup = "<STR_LIT>" ) : <EOL> with Gaffer . UndoContext ( self . getPlug ( ) . ancestor ( Gaffer . ScriptNode ) , mergeGroup = mergeGroup ) : <EOL> with Gaffer . BlockedConnection ( self . _plugConnections ( ) ) : <EOL> if Gaffer . Animation . isAnimated ( self . getPlug ( ) ) : <EOL> curve = Gaffer . Animation . acquire ( self . getPlug ( ) ) <EOL> if self . __numericWidget . getText ( ) != self . __numericWidget . valueToString ( curve . evaluate ( self . getContext ( ) . getTime ( ) ) ) : <EOL> curve . addKey ( <EOL> Gaffer . Animation . Key ( <EOL> self . getContext ( ) . getTime ( ) , <EOL> self . __numericWidget . getValue ( ) , <EOL> Gaffer . Animation . Type . Linear <EOL> ) <EOL> ) <EOL> else : <EOL> try : <EOL> self . getPlug ( ) . setValue ( self . __numericWidget . getValue ( ) ) <EOL> except : <EOL> pass <EOL> self . __numericWidget . clearUndo ( ) <EOL> self . _updateFromPlug ( ) <EOL> def __updateWidth ( self ) : <EOL> charWidth = None <EOL> if self . getPlug ( ) is not None : <EOL> charWidth = Gaffer . Metadata . plugValue ( self . getPlug ( ) , "<STR_LIT>" ) <EOL> if charWidth is None and isinstance ( self . getPlug ( ) , Gaffer . IntPlug ) and self . getPlug ( ) . hasMaxValue ( ) : <EOL> charWidth = len ( str ( self . getPlug ( ) . maxValue ( ) ) ) <EOL> self . __numericWidget . setFixedCharacterWidth ( charWidth ) <EOL> GafferUI . PlugValueWidget . registerType ( Gaffer . FloatPlug , NumericPlugValueWidget ) <EOL> GafferUI . PlugValueWidget . registerType ( Gaffer . IntPlug , NumericPlugValueWidget ) </s>
