def exportSelection(menu): scriptWindow = menu.ancestor(GafferUI.ScriptWindow) script = scriptWindow.scriptNode() path, bookmarks = __pathAndBookmarks(scriptWindow) selection = script.selection() parent = selection[0].parent() for node in selection: if not parent.isAncestorOf(node): assert (node.parent().isAncestorOf(parent)) parent = node.parent() dialogue = GafferUI.PathChooserDialogue(path, title="Export selection", confirmLabel="Export", leaf=True, bookmarks=bookmarks) path = dialogue.waitForPath(parentWindow=scriptWindow) if not path: return path = str(path) if not path.endswith(".gfr"): path += ".gfr" dialogue = GafferUI.BackgroundTaskDialogue("Saving File") dialogue.waitForBackgroundTask(functools.partial(script.serialiseToFile, path, parent, script.selection()), parentWindow=scriptWindow)
def saveAs(menu): scriptWindow = menu.ancestor(GafferUI.ScriptWindow) script = scriptWindow.scriptNode() path, bookmarks = __pathAndBookmarks(scriptWindow) dialogue = GafferUI.PathChooserDialogue(path, title="Save script", confirmLabel="Save", leaf=True, bookmarks=bookmarks) path = dialogue.waitForPath(parentWindow=scriptWindow) if not path: return path = str(path) if not path.endswith(".gfr"): path += ".gfr" dialogue = GafferUI.BackgroundTaskDialogue("Saving File") result = dialogue.waitForBackgroundTask(functools.partial( script.serialiseToFile, path), parentWindow=scriptWindow) if not isinstance(result, Exception): script["fileName"].setValue(path) script["unsavedChanges"].setValue(False) application = script.ancestor(Gaffer.ApplicationRoot) addRecentFile(application, path)
def save(menu): scriptWindow = menu.ancestor(GafferUI.ScriptWindow) script = scriptWindow.scriptNode() if script["fileName"].getValue(): dialogue = GafferUI.BackgroundTaskDialogue("Saving File") dialogue.waitForBackgroundTask(script.save, parentWindow=scriptWindow) else: saveAs(menu)
def __selectLinked(menu, context, title, linkingQuery): dialogue = GafferUI.BackgroundTaskDialogue(title) with context: result = dialogue.waitForBackgroundTask(linkingQuery, parentWindow=menu.ancestor( GafferUI.Window)) if not isinstance(result, Exception): GafferSceneUI.ContextAlgo.setSelectedPaths(context, result)
def save( menu ) : scriptWindow = menu.ancestor( GafferUI.ScriptWindow ) script = scriptWindow.scriptNode() if script["fileName"].getValue() : dialogue = GafferUI.BackgroundTaskDialogue( "Saving File" ) # Really we want to call `script.save()` here, but that would # create an edit to the `unsavedChanges` plug from the background # thread, which is problematic for any connected UIs on the main # thread. So instead we use `serialiseToFile()` and manage # `unsavedChanges` ourselves. result = dialogue.waitForBackgroundTask( functools.partial( script.serialiseToFile, script["fileName"].getValue() ), parentWindow = scriptWindow ) if not isinstance( result, Exception ) : script["unsavedChanges"].setValue( False ) else : saveAs( menu )
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