commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 20/43: grc: Reworked save confirmation dial


From: git
Subject: [Commit-gnuradio] [gnuradio] 20/43: grc: Reworked save confirmation dialog to allow cancel option
Date: Thu, 2 Apr 2015 19:15:51 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 4c12e49b899dfa2067d84b2466502e45c34787de
Author: Ethan Trewhitt <address@hidden>
Date:   Tue Feb 17 16:11:45 2015 -0500

    grc: Reworked save confirmation dialog to allow cancel option
---
 grc/gui/Dialogs.py    |  6 ++++--
 grc/gui/MainWindow.py | 26 ++++++++++++++++++--------
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/grc/gui/Dialogs.py b/grc/gui/Dialogs.py
index eb0a6c1..cf0ca02 100644
--- a/grc/gui/Dialogs.py
+++ b/grc/gui/Dialogs.py
@@ -116,7 +116,7 @@ class TextDisplay(gtk.TextView):
         menu.show_all()
         return False
 
-def MessageDialogHelper(type, buttons, title=None, markup=None):
+def MessageDialogHelper(type, buttons, title=None, markup=None, 
extra_buttons=None):
     """
     Create a modal message dialog and run it.
 
@@ -126,8 +126,9 @@ def MessageDialogHelper(type, buttons, title=None, 
markup=None):
         gtk.BUTTONS_NONE, gtk.BUTTONS_OK, gtk.BUTTONS_CLOSE, 
gtk.BUTTONS_CANCEL, gtk.BUTTONS_YES_NO, gtk.BUTTONS_OK_CANCEL
 
     Args:
-        tittle: the title of the window (string)
+        title: the title of the window (string)
         markup: the message text with pango markup
+        extra_buttons: a tuple containing pairs of values; each value is the 
button's text and the button's return value
 
     Returns:
         the gtk response from run()
@@ -135,6 +136,7 @@ def MessageDialogHelper(type, buttons, title=None, 
markup=None):
     message_dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, type, buttons)
     if title: message_dialog.set_title(title)
     if markup: message_dialog.set_markup(markup)
+    if extra_buttons: message_dialog.add_buttons(*extra_buttons)
     response = message_dialog.run()
     message_dialog.destroy()
     return response
diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py
index d1cf866..f26f30e 100644
--- a/grc/gui/MainWindow.py
+++ b/grc/gui/MainWindow.py
@@ -236,10 +236,15 @@ class MainWindow(gtk.Window):
         if self.page_to_be_closed.get_proc() or not 
self.page_to_be_closed.get_saved():
             self._set_page(self.page_to_be_closed)
         #unsaved? ask the user
-        if not self.page_to_be_closed.get_saved() and self._save_changes():
-            Actions.FLOW_GRAPH_SAVE() #try to save
-            if not self.page_to_be_closed.get_saved(): #still unsaved?
-                self.page_to_be_closed = None #set the page to be closed back 
to None
+        if not self.page_to_be_closed.get_saved():
+            response = self._save_changes() # return value is either OK, 
CLOSE, or CANCEL
+            if response == gtk.RESPONSE_OK:
+                Actions.FLOW_GRAPH_SAVE() #try to save
+                if not self.page_to_be_closed.get_saved(): #still unsaved?
+                    self.page_to_be_closed = None #set the page to be closed 
back to None
+                    return
+            elif response == gtk.RESPONSE_CANCEL:
+                self.page_to_be_closed = None
                 return
         #stop the flow graph if executing
         if self.page_to_be_closed.get_proc(): Actions.FLOW_GRAPH_KILL()
@@ -337,12 +342,17 @@ class MainWindow(gtk.Window):
         Save changes to flow graph?
 
         Returns:
-            true if yes
+            the response_id (see buttons variable below)
         """
+        buttons = (
+            'Close without saving', gtk.RESPONSE_CLOSE,
+            gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
+            gtk.STOCK_SAVE, gtk.RESPONSE_OK
+        )
         return MessageDialogHelper(
-            gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, 'Unsaved Changes!',
-            'Would you like to save changes before closing?'
-        ) == gtk.RESPONSE_YES
+            gtk.MESSAGE_QUESTION, gtk.BUTTONS_NONE, 'Unsaved Changes!',
+            'Would you like to save changes before closing?', buttons
+        )
 
     def _get_files(self):
         """



reply via email to

[Prev in Thread] Current Thread [Next in Thread]