[PATCH 08/11] Make choosing an auto-selected page after refresh slightly less fallible.

David Lehman dlehman at redhat.com
Thu Aug 16 21:48:47 UTC 2012


Build a list, in decreasing order of preference, of pages that make sense
to initially have selected. If a page was selected at the time of the
refresh, it should probably be still selected afterwards. If that page is
no longer present, no problem. Move on to the next one in the list.
---
 pyanaconda/ui/gui/spokes/custom.py        |   31 ++++++++++++++++++----------
 pyanaconda/ui/gui/spokes/lib/accordion.py |    5 +++-
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/custom.py b/pyanaconda/ui/gui/spokes/custom.py
index 9f3a72b..ec26137 100644
--- a/pyanaconda/ui/gui/spokes/custom.py
+++ b/pyanaconda/ui/gui/spokes/custom.py
@@ -365,6 +365,11 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
         self._updateSpaceDisplay()
 
     def _do_refresh(self):
+        # We can only have one page expanded at a time.
+        page_order = []
+        if self._accordion.currentPage():
+            page_order.append(self._accordion.currentPage().pageTitle)
+
         # Make sure we start with a clean slate.
         self._accordion.removeAllPages()
 
@@ -374,9 +379,6 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
 
         # Now it's time to populate the accordion.
 
-        # We can only have one page expanded at a time.
-        did_expand = False
-
         unused = [d for d in self.unusedDevices if d.isleaf and d in self._devices]
         new_devices = [d for d in self._devices if not d.exists]
 
@@ -391,8 +393,9 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             page = CreateNewPage(self.on_create_clicked)
             page.pageTitle = new_install_name
             self._accordion.addPage(page, cb=self.on_page_clicked)
-            self._accordion.expandPage(page.pageTitle)
-            did_expand = True
+
+            if page.pageTitle not in page_order:
+                page_order.append(page.pageTitle)
 
             self._partitionsNotebook.set_current_page(0)
             label = self.builder.get_object("whenCreateLabel")
@@ -435,9 +438,8 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             page.show_all()
             self._accordion.addPage(page, cb=self.on_page_clicked)
 
-            if not did_expand:
-                did_expand = True
-                self._accordion.expandPage(root.name)
+            if root.name not in page_order:
+                page_order.append(root.name)
 
         # Anything that doesn't go with an OS we understand?  Put it in the Other box.
         if unused:
@@ -452,9 +454,16 @@ class CustomPartitioningSpoke(NormalSpoke, StorageChecker):
             page.show_all()
             self._accordion.addPage(page, cb=self.on_page_clicked)
 
-            if not did_expand:
-                did_expand = True
-                self._accordion.expandPage(page.pageTitle)
+            if page.pageTitle not in page_order:
+                page_order.append(page.pageTitle)
+
+        for page_name in page_order:
+            try:
+                self._accordion.expandPage(page_name)
+            except LookupError:
+                continue
+            else:
+                break
 
     ###
     ### RIGHT HAND SIDE METHODS
diff --git a/pyanaconda/ui/gui/spokes/lib/accordion.py b/pyanaconda/ui/gui/spokes/lib/accordion.py
index 593d4d5..4bbc097 100644
--- a/pyanaconda/ui/gui/spokes/lib/accordion.py
+++ b/pyanaconda/ui/gui/spokes/lib/accordion.py
@@ -74,7 +74,10 @@ class Accordion(Gtk.Box):
 
     def expandPage(self, pageTitle):
         page = self._find_by_title(pageTitle)
-        if page and not page.get_expanded():
+        if not page:
+            raise LookupError()
+
+        if not page.get_expanded():
             page.emit("activate")
 
     def removePage(self, pageTitle):
-- 
1.7.7.6



More information about the anaconda-patches mailing list