def quit(menu): scriptWindow = menu.ancestor(GafferUI.ScriptWindow) application = scriptWindow.scriptNode().ancestor( Gaffer.ApplicationRoot.staticTypeId()) unsavedNames = [] for script in application["scripts"].children(): if script["unsavedChanges"].getValue(): f = script["fileName"].getValue() f = f.rpartition("/")[2] if f else "untitled" unsavedNames.append(f) if unsavedNames: dialogue = GafferUI.ConfirmationDialogue( "Discard Unsaved Changes?", "The following files have unsaved changes : \n\n" + "\n".join([" - " + n for n in unsavedNames]) + "\n\nDo you want to discard the changes and quit?", confirmLabel="Discard and Quit") if not dialogue.waitForConfirmation(): return for script in application["scripts"].children(): application["scripts"].removeChild(script)
def quit(menu): scriptWindow = menu.ancestor(GafferUI.ScriptWindow) application = scriptWindow.scriptNode().ancestor(Gaffer.ApplicationRoot) unsavedNames = [] for script in application["scripts"].children(): if script["unsavedChanges"].getValue(): f = script["fileName"].getValue() f = f.rpartition("/")[2] if f else "untitled" unsavedNames.append(f) if unsavedNames: dialogue = GafferUI.ConfirmationDialogue( "Discard Unsaved Changes?", "The following files have unsaved changes : \n\n" + "\n".join([" - " + n for n in unsavedNames]) + "\n\nDo you want to discard the changes and quit?", confirmLabel="Discard and Quit") if not dialogue.waitForConfirmation(parentWindow=scriptWindow): return # Defer the actual removal of scripts till an idle event - removing all # the scripts will result in the removal of the window our menu item is # parented to, which would cause a crash as it's deleted away from over us. GafferUI.EventLoop.addIdleCallback( IECore.curry(__removeAllScripts, application))
def connectPlugToRowNames(activeRowNamesConnection, selectorContextVariablePlug, selectorValue, spreadsheet, menu): node = activeRowNamesConnection.node() # We defer locking the plug until we know we're going ahead lockSelectorVarPlug = False if selectorValue is None: selectorValue = "${" + selectorContextVariablePlug.getValue() + "}" lockSelectorVarPlug = True # Check that the sheet's selector meets requirements before making any changes existingSelector = spreadsheet["selector"].getValue() if existingSelector and selectorValue and existingSelector != selectorValue: message = "{sheetName}'s selector is set to: '{sheetSelector}'.\n\n" + \ "The '{plugName}' plug requires a different selector to work\n" + \ "properly. Continuing will reset the selector to '{selector}'." confirm = GafferUI.ConfirmationDialogue( "Invalid Selector", message.format(sheetName=spreadsheet.getName(), sheetSelector=existingSelector, plugName=activeRowNamesConnection.getName(), selector=selectorValue), confirmLabel="Continue") if not confirm.waitForConfirmation( parentWindow=menu.ancestor(GafferUI.Window)): return with Gaffer.UndoScope(node.scriptNode()): if lockSelectorVarPlug: Gaffer.MetadataAlgo.setReadOnly(selectorContextVariablePlug, True) if selectorValue: spreadsheet["selector"].setValue(selectorValue) Gaffer.MetadataAlgo.setReadOnly(spreadsheet["selector"], True) with node.scriptNode().context(): rowNames = activeRowNamesConnection.getValue() activeRowNamesConnection.setInput(spreadsheet["activeRowNames"]) if rowNames: for rowName in rowNames: spreadsheet["rows"].addRow()["name"].setValue(rowName) else: # Only a new row to an empty spreadsheet if len(spreadsheet["rows"].children()) == 1: spreadsheet["rows"].addRow() node.parent().addChild(spreadsheet)
def _acceptsClose(self): if not self.__script["unsavedChanges"].getValue(): return True f = self.__script["fileName"].getValue() f = f.rpartition("/")[2] if f else "untitled" dialogue = GafferUI.ConfirmationDialogue( "Discard Unsaved Changes?", "The file %s has unsaved changes. Do you want to discard them?" % f, confirmLabel="Discard") return dialogue.waitForConfirmation(parentWindow=self)
def __addScript(application, fileName, dialogueParentWindow=None, asNew=False): recoveryFileName = None backups = GafferUI.Backups.acquire(application, createIfNecessary=False) if backups is not None: recoveryFileName = backups.recoveryFile(fileName) if recoveryFileName: dialogue = GafferUI.ConfirmationDialogue( title="Backup Available", message= "A more recent backup is available. Open backup instead?", confirmLabel="Open Backup", cancelLabel="Open", ) useBackup = dialogue.waitForConfirmation( parentWindow=dialogueParentWindow) if useBackup is None: return elif not useBackup: recoveryFileName = None dialogue.setVisible(False) script = Gaffer.ScriptNode() script["fileName"].setValue(recoveryFileName or fileName) dialogue = GafferUI.BackgroundTaskDialogue("Loading") result = dialogue.waitForBackgroundTask( functools.partial( script.load, continueOnError=True, ), dialogueParentWindow) if isinstance(result, IECore.Cancelled): return if asNew or recoveryFileName: # If we loaded a backup (or as new), rename the script to the old # filename (or nothing) so the user can resave and continue as before. script["fileName"].setValue("" if asNew else fileName) script["unsavedChanges"].setValue(True) application["scripts"].addChild(script) if not asNew: addRecentFile(application, fileName) return script
def revertToSaved(menu): scriptWindow = menu.ancestor(GafferUI.ScriptWindow) dialogue = GafferUI.ConfirmationDialogue( title="Discard Unsaved Changes?", message="There are unsaved changes which will be lost." "Discard them and revert?", confirmLabel="Revert", cancelLabel="Cancel", ) if not dialogue.waitForConfirmation(parentWindow=scriptWindow): return with GafferUI.ErrorDialogue.ErrorHandler( title="Errors Occurred During Loading", closeLabel="Oy vey", parentWindow=scriptWindow): scriptWindow.scriptNode().load(continueOnError=True)
def __exportForReferencing( menu, node ) : nonDefaultPlugs = __nonDefaultPlugs( node ) if len( nonDefaultPlugs ) : dialogue = GafferUI.ConfirmationDialogue( title = "Export without current values?", message = inspect.cleandoc( """ Not all plugs are at their default values, and non-default values will not be exported. Export anyway? """ ), details = __formatPlugs( node, nonDefaultPlugs ) + "\n\n" + inspect.cleandoc( """ Defaults can be reset for the whole node using "Reset Default Values" in the NodeEditor tool menu or for individual plugs using "Reset Default Value" in the plug context menu. """ ).replace( "\n", " " ), confirmLabel = "Export" ) if not dialogue.waitForConfirmation() : return bookmarks = GafferUI.Bookmarks.acquire( node, category="reference" ) path = Gaffer.FileSystemPath( bookmarks.getDefault( menu ) ) path.setFilter( Gaffer.FileSystemPath.createStandardFilter( [ "grf" ] ) ) dialogue = GafferUI.PathChooserDialogue( path, title="Export reference", confirmLabel="Export", leaf=True, bookmarks=bookmarks ) path = dialogue.waitForPath( parentWindow = menu.ancestor( GafferUI.Window ) ) if not path : return path = str( path ) if not path.endswith( ".grf" ) : path += ".grf" node.exportForReference( path )
def __addScript( application, fileName, dialogueParentWindow = None ) : recoveryFileName = None backups = GafferUI.Backups.acquire( application, createIfNecessary = False ) if backups is not None : recoveryFileName = backups.recoveryFile( fileName ) if recoveryFileName : dialogue = GafferUI.ConfirmationDialogue( title = "Backup Available", message = "A more recent backup is available. Open backup instead?", confirmLabel = "Open Backup", cancelLabel = "Open", ) useBackup = dialogue.waitForConfirmation( parentWindow = dialogueParentWindow ) if useBackup is None : return elif not useBackup : recoveryFileName = None dialogue.setVisible( False ) script = Gaffer.ScriptNode() script["fileName"].setValue( recoveryFileName or fileName ) with GafferUI.ErrorDialogue.ErrorHandler( title = "Errors Occurred During Loading", closeLabel = "Oy vey", parentWindow = dialogueParentWindow ) : script.load( continueOnError = True ) if recoveryFileName : # If we loaded a backup, give the script the original # filename so the user can resave and continue as before. script["fileName"].setValue( fileName ) script["unsavedChanges"].setValue( True ) application["scripts"].addChild( script ) addRecentFile( application, fileName ) return script
def __save( self ) : self._parameterHandler.setParameterValue() parameterised = self._parameterHandler.plug().node().getParameterised()[0] preset = IECore.BasicPreset( parameterised, self._parameterHandler.parameter(), self.__selectedParameters() ) presetLocation = self._locationMenu().getCurrentItem() # append the name of the class to the location, so that presets with # identical names (but for different classes) don't overwrite each # other. presetLocation = presetLocation + "/" + parameterised.typeName() presetName = self.__presetNameWidget.getText() # make a filename by sanitising the preset name. fileName = presetName.replace( " ", "_" ) fileName = re.sub( '[^a-zA-Z0-9_]*', "", fileName ) # We have to also make sure that the name doesn't begin with a number, # as it wouldn't be a legal class name in the resulting py stub. fileName = re.sub( '^[0-9]+', "", fileName ) if os.path.exists( presetLocation + "/" + fileName ) : dialogue = GafferUI.ConfirmationDialogue( "Preset already exists!", "A preset named \"%s\" already exists.\nReplace it?" % presetName, confirmLabel = "Replace" ) if not dialogue.waitForConfirmation( parentWindow = self ) : return False presetDescription = self.__presetDescriptionWidget.getText() preset.save( presetLocation, fileName, presetName, presetDescription ) return True