<s> import os <EOL> import weakref <EOL> import IECore <EOL> import Gaffer <EOL> import GafferUI <EOL> def appendDefinitions ( menuDefinition , prefix ) : <EOL> menuDefinition . append ( prefix + "<STR_LIT>" , { "<STR_LIT>" : about } ) <EOL> menuDefinition . append ( prefix + "<STR_LIT>" , { "<STR_LIT>" : preferences } ) <EOL> menuDefinition . append ( prefix + "<STR_LIT>" , { "<STR_LIT>" : IECore . curry ( GafferUI . showURL , os . path . expandvars ( "<STR_LIT>" ) ) } ) <EOL> menuDefinition . append ( prefix + "<STR_LIT>" , { "<STR_LIT>" : quit , "<STR_LIT>" : "<STR_LIT>" } ) <EOL> def quit ( menu ) : <EOL> scriptWindow = menu . ancestor ( GafferUI . ScriptWindow ) <EOL> application = scriptWindow . scriptNode ( ) . ancestor ( Gaffer . ApplicationRoot ) <EOL> unsavedNames = [ ] <EOL> for script in application [ "<STR_LIT>" ] . children ( ) : <EOL> if script [ "<STR_LIT>" ] . getValue ( ) : <EOL> f = script [ "<STR_LIT>" ] . getValue ( ) <EOL> f = f . rpartition ( "<STR_LIT:/>" ) [ <NUM_LIT:2> ] if f else "<STR_LIT>" <EOL> unsavedNames . append ( f ) <EOL> if unsavedNames : <EOL> dialogue = GafferUI . ConfirmationDialogue ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" + <EOL> "<STR_LIT:\n>" . join ( [ "<STR_LIT>" + n for n in unsavedNames ] ) + <EOL> "<STR_LIT>" , <EOL> confirmLabel = "<STR_LIT>" <EOL> ) <EOL> if not dialogue . waitForConfirmation ( parentWindow = scriptWindow ) : <EOL> return <EOL> GafferUI . EventLoop . addIdleCallback ( IECore . curry ( __removeAllScripts , application ) ) <EOL> def __removeAllScripts ( application ) : <EOL> for script in application [ "<STR_LIT>" ] . children ( ) : <EOL> application [ "<STR_LIT>" ] . removeChild ( script ) <EOL> return False <EOL> __aboutWindow = None <EOL> def about ( menu ) : <EOL> global __aboutWindow <EOL> if __aboutWindow is not None and __aboutWindow ( ) : <EOL> window = __aboutWindow ( ) <EOL> else : <EOL> window = GafferUI . AboutWindow ( Gaffer . About ) <EOL> __aboutWindow = weakref . ref ( window ) <EOL> scriptWindow = menu . ancestor ( GafferUI . ScriptWindow ) <EOL> scriptWindow . addChildWindow ( window ) <EOL> window . setVisible ( True ) <EOL> __preferencesWindows = weakref . WeakKeyDictionary ( ) <EOL> def preferences ( menu ) : <EOL> scriptWindow = menu . ancestor ( GafferUI . ScriptWindow ) <EOL> application = scriptWindow . scriptNode ( ) . ancestor ( Gaffer . ApplicationRoot ) <EOL> global __preferencesWindows <EOL> window = __preferencesWindows . get ( application , None ) <EOL> if window is not None and window ( ) : <EOL> window = window ( ) <EOL> else : <EOL> window = GafferUI . Dialogue ( "<STR_LIT>" ) <EOL> closeButton = window . _addButton ( "<STR_LIT>" ) <EOL> window . __closeButtonConnection = closeButton . clickedSignal ( ) . connect ( __closePreferences ) <EOL> saveButton = window . _addButton ( "<STR_LIT>" ) <EOL> window . __saveButtonConnection = saveButton . clickedSignal ( ) . connect ( __savePreferences ) <EOL> with GafferUI . ListContainer ( ) as column : <EOL> GafferUI . NodeUI . create ( application [ "<STR_LIT>" ] ) <EOL> GafferUI . Spacer ( IECore . V2i ( <NUM_LIT:0> ) , parenting = { "<STR_LIT>" : True } ) <EOL> window . _setWidget ( column ) <EOL> __preferencesWindows [ application ] = weakref . ref ( window ) <EOL> scriptWindow . addChildWindow ( window ) <EOL> window . setVisible ( True ) <EOL> def __closePreferences ( button ) : <EOL> button . ancestor ( type = GafferUI . Window ) . setVisible ( False ) <EOL> def __savePreferences ( button ) : <EOL> scriptWindow = button . ancestor ( GafferUI . ScriptWindow ) <EOL> application = scriptWindow . scriptNode ( ) . ancestor ( Gaffer . ApplicationRoot ) <EOL> application . savePreferences ( ) <EOL> button . ancestor ( type = GafferUI . Window ) . setVisible ( False ) </s>
