def preferences(menu): scriptWindow = menu.ancestor(GafferUI.ScriptWindow) application = scriptWindow.scriptNode().ancestor(Gaffer.ApplicationRoot) global __preferencesWindows window = __preferencesWindows.get(application, None) if window is not None and window(): window = window() else: window = GafferUI.Dialogue("Preferences") closeButton = window._addButton("Close") window.__closeButtonConnection = closeButton.clickedSignal().connect( __closePreferences) saveButton = window._addButton("Save") window.__saveButtonConnection = saveButton.clickedSignal().connect( __savePreferences) with GafferUI.ListContainer() as column: GafferUI.NodeUI.create(application["preferences"]) GafferUI.Spacer(IECore.V2i(0), parenting={"expand": True}) window._setWidget(column) __preferencesWindows[application] = weakref.ref(window) scriptWindow.addChildWindow(window) window.setVisible(True)
def preferences(menu): scriptWindow = menu.ancestor(GafferUI.ScriptWindow) application = scriptWindow.scriptNode().ancestor(Gaffer.ApplicationRoot) global __preferencesWindows window = __preferencesWindows.get(application, None) if window is not None and window(): window = window() else: window = GafferUI.Dialogue("Preferences") closeButton = window._addButton("Close") window.__closeButtonConnection = closeButton.clickedSignal().connect( __closePreferences) saveButton = window._addButton("Save") window.__saveButtonConnection = saveButton.clickedSignal().connect( __savePreferences) window._setWidget(GafferUI.NodeUI.create(application["preferences"])) __preferencesWindows[application] = weakref.ref(window) scriptWindow.addChildWindow(window) window.setVisible(True)
def preferences(menu): scriptWindow = menu.ancestor(GafferUI.ScriptWindow) application = scriptWindow.scriptNode().ancestor(Gaffer.ApplicationRoot) global __preferencesWindows window = __preferencesWindows.get(application, None) if window is not None and window(): window = window() else: window = GafferUI.Dialogue("Preferences") closeButton = window._addButton("Close") window.__closeButtonConnection = closeButton.clickedSignal().connect( __closePreferences) saveButton = window._addButton("Save") window.__saveButtonConnection = saveButton.clickedSignal().connect( __savePreferences) window._setWidget(GafferUI.NodeUI.create(application["preferences"])) __preferencesWindows[application] = weakref.ref(window) # The NodeUI builds lazily, so we force it to build now so we can # resize the window to fit. Since the plugs are configured per # application, we need to build them all. for plug in application["preferences"].children(Gaffer.Plug): window._getWidget().plugValueWidget(plug, lazy=False) window.resizeToFitChild() scriptWindow.addChildWindow(window) window.setVisible(True)
def __open(currentScript, fileName): application = currentScript.ancestor(Gaffer.ApplicationRoot) script = Gaffer.ScriptNode() script["fileName"].setValue(fileName) messageWidget = GafferUI.MessageWidget() with messageWidget.messageHandler(): script.load(continueOnError=True) application["scripts"].addChild(script) addRecentFile(application, fileName) removeCurrentScript = False if not currentScript["fileName"].getValue( ) and not currentScript["unsavedChanges"].getValue(): # the current script is empty - the user will think of the operation as loading # the new script into the current window, rather than adding a new window. so make it # look like that. currentWindow = GafferUI.ScriptWindow.acquire(currentScript) newWindow = GafferUI.ScriptWindow.acquire(script) ## \todo We probably want a way of querying and setting geometry in the public API newWindow._qtWidget().restoreGeometry( currentWindow._qtWidget().saveGeometry()) currentWindow.setVisible(False) removeCurrentScript = True if sum([ messageWidget.messageCount(level) for level in (IECore.Msg.Level.Error, IECore.Msg.Level.Warning) ]): dialogue = GafferUI.Dialogue("Errors Occurred During Loading") ## \todo These dialogue methods should be available publicly. dialogue._setWidget(messageWidget) dialogue._addButton("Oy vey") dialogue.waitForButton( parentWindow=GafferUI.ScriptWindow.acquire(currentScript)) # We must defer the removal of the old script because otherwise we trigger a crash bug # in PySide - I think this is because the menu item that invokes us is a child of # currentWindow, and that will get deleted immediately when the script is removed. if removeCurrentScript: GafferUI.EventLoop.addIdleCallback( IECore.curry(__removeScript, application, currentScript))
def _load(node, fileName, parentWindow): messageWidget = GafferUI.MessageWidget() with messageWidget.messageHandler() as mh: try: node.load(fileName) except Exception as e: mh.handle(mh.Level.Error, "Loading Reference", str(e)) if sum([ messageWidget.messageCount(level) for level in (IECore.Msg.Level.Error, IECore.Msg.Level.Warning) ]): dialogue = GafferUI.Dialogue("Errors Occurred During Loading") ## \todo These dialogue methods should be available publicly. # Alternatively, we could make the ErrorDialogue class handle # messages as well as exceptions and use that here. Bear in mind # that we're doing the same thing in FileMenu.__open(), so we # definitely have a need for something like this. dialogue._setWidget(messageWidget) dialogue._addButton("Oy vey") dialogue.waitForButton(parentWindow=parentWindow)