commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r8051 - trunk/gnue-forms/src/GFObjects


From: jamest
Subject: [gnue] r8051 - trunk/gnue-forms/src/GFObjects
Date: Wed, 12 Oct 2005 11:28:28 -0500 (CDT)

Author: jamest
Date: 2005-10-12 11:28:28 -0500 (Wed, 12 Oct 2005)
New Revision: 8051

Modified:
   trunk/gnue-forms/src/GFObjects/GFContainer.py
Log:
reworked the GFContainer to deal with non sequential focusorder settings
which designer seems to produce in some instances


Modified: trunk/gnue-forms/src/GFObjects/GFContainer.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFContainer.py       2005-10-12 07:50:49 UTC 
(rev 8050)
+++ trunk/gnue-forms/src/GFObjects/GFContainer.py       2005-10-12 16:28:28 UTC 
(rev 8051)
@@ -25,52 +25,77 @@
 """
 A base class for all GFObjects that can be containers
 """
+__revision__ = "$Id$"
 
 from GFObj import GFObj
 from GFTabStop import GFTabStop
 
 class GFContainer(GFObj):
+  """
+  A base class for all GFObjects that can be containers
+  """
   def __init__(self, parent=None, type='GFContainer'):
+    """
+    Constructor
+    """
     GFObj.__init__(self, parent, type)
 
-
-  # Build a "focus order" from all our children
-  # (and, recursively, any child containers)
-  # TODO: This assumes sane focusstop values; no sanity checks!
   def getFocusOrder(self, list=None):
-    specificFocusStops = {}
-    allFocusStops = []
-    if not list:
+    """
+    Builds a list of objects ordered in the way in which they
+    should receive focus.
+    
+    @param list: An optional list of objects to scan for focus
+    @return: A list of objects in the order that they should receive focus
+    """
+    
+    missingFocusOrder = [] # A list of tab stops in the form that do not have 
+                           # a focus order
+    hasFocusOrder = []     # A list of tab stops in the form that have a 
+                           # focus order.  stored in the format 
+                           # [focusOrder, [tabstops]]
+    
+    # If no list passed then use the instances built in children list
+    if list is None:
       list = self._children
+
+    # Build the missing and has focus lists          
     for child in list:
       if isinstance(child,GFContainer):
         tabStops = child.getFocusOrder()
-        if len(tabStops):
-          allFocusStops.append(tabStops)
-          try:
-            specificFocusStops[child.focusorder-1] = tabStops
-          except AttributeError:
-            pass
       elif isinstance(child,GFTabStop):
-        allFocusStops.append([child])
+        tabStops = [child]
+                
+      if bool(tabStops):
         try:
-          specificFocusStops[child.focusorder-1] = [child]
+          index = child.focusorder - 1
+          hasFocusOrder.append([index, tabStops])
         except AttributeError:
-          pass
+          missingFocusOrder.append(tabStops)
 
-    rv = [None] * len(allFocusStops)
-    for key in specificFocusStops.keys():
-      rv.pop(key)
-      rv[key:key] = specificFocusStops[key]
-      allFocusStops.pop(allFocusStops.index(specificFocusStops[key]))
+    # Sort the focus stops on items that had defined focus order
+    hasFocusOrder.sort()
 
-    focusStop = 0
-    maxStops = len(rv)
-    while focusStop < maxStops:
-      if not rv[focusStop]:
-        rv.pop(focusStop)
-        rv[focusStop:focusStop] = allFocusStops[0]
-        allFocusStops.pop(0)
-      focusStop += 1
+    # Create a None filled list that will contain all the tab stops
+    maxFocusIndex = hasFocusOrder[-1][0]
+    totalLength = len(hasFocusOrder) + len(missingFocusOrder)    
+    workingList = [None] * max(maxFocusIndex + 1, totalLength)
+    
+    # Merge in the items with defined focus orders
+    for index, tabStop in hasFocusOrder:
+      workingList[index] = tabStop
+      
+    # Merge in the items missing defined focus orders 
+    # where ever there is a gap
+    while bool(missingFocusOrder):
+      tabStop = missingFocusOrder.pop(0)
+      workingList[workingList.index(None)] = tabStop
+    
+    # Remove any None entries in the list.  This would 
+    # happen if the focusorder settings skipped numbers  
+    returnValue = []
+    for tabStop in workingList:
+      if tabStop is not None:
+        returnValue.extend(tabStop)
 
-    return rv
+    return returnValue
\ No newline at end of file





reply via email to

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