[master] Make dialog return code checking more robust

mulhern amulhern at redhat.com
Tue Nov 5 22:22:15 UTC 2013


A dialog can return not only the values associated with its buttons but also
some other values. The value that it can certainly return is -4. This value
is most likely to occur when the user presses the escape key, and causes
the dialog to be deleted.

In some cases this possibility is not allowed for and the wrong action is
taken when the escape key is pressed because the code puts the unexpected
value in an equivalence class with some button that actually causes an
action to be taken.

The *.py files in pyanaconda were searched for occurances of the regular
expression =.*run and nearby lines were scrutinized and corrected if
necessary.

In general, the changes make an if condition more restrictive if the then
branch causes an action and less restrictive if it does not.

The changes to summary.glade from a previous commit
are reversed and custom.py
is updated appropriately as using the ResponseType constants would
be inconsistant with the rest of the code.

Related: rhbz#998384

Signed-off-by: mulhern <amulhern at redhat.com>
---
 pyanaconda/ui/gui/spokes/custom.py         | 10 +++++-----
 pyanaconda/ui/gui/spokes/lib/summary.glade |  4 ++--
 pyanaconda/ui/gui/spokes/software.py       |  2 ++
 pyanaconda/ui/gui/spokes/source.py         |  2 +-
 pyanaconda/ui/gui/spokes/storage.py        |  4 +++-
 pyanaconda/ui/gui/spokes/welcome.py        |  4 ++--
 6 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index 7d4e025..a81c72c 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -1869,7 +1869,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             dialog.refresh(self.__storage.devicetree.findActions())
             rc = dialog.run()
 
-        if rc != int(Gtk.ResponseType.ACCEPT): 
+        if rc != 1:
             # Cancel.  Stay on the custom screen.
             return
 
@@ -1882,7 +1882,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             with enlightbox(self.window, dialog.window):
                 rc = dialog.run()
 
-            if rc == 0:
+            if rc != 1:
                 # Cancel. Leave the old passphrase set if there was one.
                 return
 
@@ -2158,7 +2158,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
                                device.name, root_name)
                 rc = dialog.run()
 
-                if rc == 0:
+                if rc != 1:
                     dialog.window.destroy()
                     return
 
@@ -2211,7 +2211,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         with enlightbox(self.window, dialog.window):
             rc = dialog.run()
 
-        if rc == 0:
+        if rc != 1:
             return
 
         disks = dialog.selected
@@ -2260,7 +2260,7 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             rc = dialog.run()
             dialog.window.destroy()
 
-        if rc == 0:
+        if rc != 1:
             return
 
         disks = dialog.selected
diff --git a/pyanaconda/ui/gui/spokes/lib/summary.glade b/pyanaconda/ui/gui/spokes/lib/summary.glade
index aba4914..3d020e8 100644
--- a/pyanaconda/ui/gui/spokes/lib/summary.glade
+++ b/pyanaconda/ui/gui/spokes/lib/summary.glade
@@ -197,8 +197,8 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget response="-6">summaryCancelButton</action-widget>
-      <action-widget response="-3">summaryAcceptButton</action-widget>
+      <action-widget response="0">summaryCancelButton</action-widget>
+      <action-widget response="1">summaryAcceptButton</action-widget>
     </action-widgets>
   </object>
 </interface>
diff --git a/pyanaconda/ui/gui/spokes/software.py b/pyanaconda/ui/gui/spokes/software.py
index 6291fea..9ae146f 100644
--- a/pyanaconda/ui/gui/spokes/software.py
+++ b/pyanaconda/ui/gui/spokes/software.py
@@ -426,3 +426,5 @@ class SoftwareSelectionSpoke(NormalSpoke):
             # Send the user to the installation source spoke.
             self.skipTo = "SourceSpoke"
             self.window.emit("button-clicked")
+        else:
+            pass
diff --git a/pyanaconda/ui/gui/spokes/source.py b/pyanaconda/ui/gui/spokes/source.py
index f9b5658..f71c80b 100644
--- a/pyanaconda/ui/gui/spokes/source.py
+++ b/pyanaconda/ui/gui/spokes/source.py
@@ -237,7 +237,7 @@ class IsoChooser(GUIObject):
 
         # If any directory was chosen, return that.  Otherwise, return None.
         rc = self.window.run()
-        if rc:
+        if rc == 1:
             f = self._chooser.get_filename()
             if f:
                 retval = f.replace(constants.ISO_DIR, "")
diff --git a/pyanaconda/ui/gui/spokes/storage.py b/pyanaconda/ui/gui/spokes/storage.py
index fc5a7aa..6c5372c 100644
--- a/pyanaconda/ui/gui/spokes/storage.py
+++ b/pyanaconda/ui/gui/spokes/storage.py
@@ -755,7 +755,7 @@ class StorageSpoke(NormalSpoke, StorageChecker):
 
         dialog = PassphraseDialog(self.data)
         rc = self.run_lightbox_dialog(dialog)
-        if rc == 0:
+        if rc != 1:
             return False
 
         self.passphrase = dialog.passphrase
@@ -875,6 +875,8 @@ class StorageSpoke(NormalSpoke, StorageChecker):
             self.encrypted = dialog.encrypted
 
             self.skipTo = "CustomPartitioningSpoke"
+        else:
+            return
 
         self.applyOnSkip = True
         NormalSpoke.on_back_clicked(self, button)
diff --git a/pyanaconda/ui/gui/spokes/welcome.py b/pyanaconda/ui/gui/spokes/welcome.py
index 45abe88..86296aa 100644
--- a/pyanaconda/ui/gui/spokes/welcome.py
+++ b/pyanaconda/ui/gui/spokes/welcome.py
@@ -268,7 +268,7 @@ class WelcomeLanguageSpoke(LangLocaleHandler, StandaloneSpoke):
             with enlightbox(self.window, dlg):
                 rc = dlg.run()
                 dlg.destroy()
-            if rc == 0:
+            if rc != 1:
                 sys.exit(0)
 
         if productName.startswith("Red Hat Enterprise Linux") and \
@@ -277,7 +277,7 @@ class WelcomeLanguageSpoke(LangLocaleHandler, StandaloneSpoke):
             with enlightbox(self.window, dlg):
                 rc = dlg.run()
                 dlg.destroy()
-            if rc == 0:
+            if rc != 1:
                 sys.exit(0)
 
         StandaloneSpoke._on_continue_clicked(self, cb)
-- 
1.8.3.1



More information about the anaconda-patches mailing list