Skip to content

Commit

Permalink
ScriptWindow : Add "Save" option to "Discard Changes?" dialogue
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Dec 13, 2023
1 parent d00da75 commit 9a13360
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Improvements
- Incomplete jobs are now killed automatically when the application is closed, after prompting to confirm that shutdown should go ahead.
- Cache : Increased default computation cache size to 8Gb. Call `Gaffer.ValuePlug.setCacheMemoryLimit()` from a startup file to override this.
- Dispatcher : Reduced internal overhead of `dispatch()` call, with one benchmark showing around a 3x speedup.
- ScriptWindow : Added "Save" option to dialogue shown when closing a window containing unsaved changes.

Fixes
-----
Expand Down
43 changes: 39 additions & 4 deletions python/GafferUI/ScriptWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,22 @@ def _acceptsClose( self ) :
f = self.__script["fileName"].getValue()
f = f.rpartition( "/" )[2] if f else "untitled"

dialogue = GafferUI.ConfirmationDialogue(
dialogue = _ChoiceDialogue(
"Discard Unsaved Changes?",
"The file %s has unsaved changes. Do you want to discard them?" % f,
confirmLabel = "Discard"
f"The file \"{f}\" has unsaved changes. Do you want to discard them?",
choices = [ "Cancel", "Save", "Discard" ]
)
return dialogue.waitForConfirmation( parentWindow=self )
choice = dialogue.waitForChoice( parentWindow=self )

if choice == "Discard" :
return True
elif choice == "Save" :
## \todo Is it a bit odd that ScriptWindow should depend on FileMenu
# like this? Should the code be moved somewhere else?
GafferUI.FileMenu.save( self.menuBar() )
return True
else :
return False

def __closed( self, widget ) :

Expand Down Expand Up @@ -194,6 +204,31 @@ def __staticScriptRemoved( scriptContainer, script ) :
if not len( scriptContainer.children() ) and GafferUI.EventLoop.mainEventLoop().running() :
GafferUI.EventLoop.mainEventLoop().stop()

## \todo Would this be worthy of inclusion in GafferUI?
class _ChoiceDialogue( GafferUI.Dialogue ) :

def __init__( self, title, message, choices, **kw ) :

GafferUI.Dialogue.__init__( self, title, sizeMode=GafferUI.Window.SizeMode.Automatic, **kw )

with GafferUI.ListContainer( GafferUI.ListContainer.Orientation.Vertical, spacing = 8 ) as column :

GafferUI.Label( message )

self._setWidget( column )

for choice in choices :
self.__lastButton = self._addButton( choice )

def waitForChoice( self, **kw ) :

self.__lastButton._qtWidget().setFocus()
button = self.waitForButton( **kw )

if button is None :
return None
else :
return button.getText()

class _WindowTitleBehaviour :

Expand Down

0 comments on commit 9a13360

Please sign in to comment.