[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9081 - trunk/gnue-forms/src
From: |
reinhard |
Subject: |
[gnue] r9081 - trunk/gnue-forms/src |
Date: |
Tue, 28 Nov 2006 11:24:59 -0600 (CST) |
Author: reinhard
Date: 2006-11-28 11:24:58 -0600 (Tue, 28 Nov 2006)
New Revision: 9081
Modified:
trunk/gnue-forms/src/GFForm.py
Log:
Cleaned up find_focus and find_and_change_focus.
Modified: trunk/gnue-forms/src/GFForm.py
===================================================================
--- trunk/gnue-forms/src/GFForm.py 2006-11-28 16:38:29 UTC (rev 9080)
+++ trunk/gnue-forms/src/GFForm.py 2006-11-28 17:24:58 UTC (rev 9081)
@@ -304,7 +304,7 @@
# of the datasource), otherwise a dropdown will be set to edit mode
# before it has been populated with the allowed values, in case the
# first entry on the form is a dropdown.
- self.findAndChangeFocus(self)
+ self.__find_and_change_focus(self, False)
self.update_insert_status()
@@ -383,7 +383,7 @@
self._currentPage = self._layout._pageList[page_number]
self._currentPage.focus_in()
- self.findAndChangeFocus(self._currentPage)
+ self.__find_and_change_focus(self._currentPage, False)
# -------------------------------------------------------------------------
@@ -491,7 +491,7 @@
self._in_trigger_lock = True
try:
- self.findAndChangeFocus(object._object)
+ self.__find_and_change_focus(object._object, False)
finally:
self._in_trigger_lock = False
@@ -887,14 +887,13 @@
dest = self._layout._pageList[i - 1]
except IndexError:
dest = self._layout._pageList[-1]
- # TODO: this fails if last entry is not navigable
- self.findAndChangeFocus(dest._entryList[-1])
+ self.__find_and_change_focus(dest, True)
else:
try:
dest = self._layout._pageList[i + 1]
except IndexError:
dest = self._layout._pageList[0]
- self.findAndChangeFocus(dest)
+ self.__find_and_change_focus(dest, False)
else:
self.change_focus(nextEntry, 0)
@@ -929,9 +928,9 @@
next_index = 0
else:
next_index = current_index + 1
- self.findAndChangeFocus(blocks[next_index])
+ self.__find_and_change_focus(blocks[next_index], False)
else:
- self.findAndChangeFocus(blocks[0])
+ self.__find_and_change_focus(blocks[0], False)
# -------------------------------------------------------------------------
@@ -943,10 +942,10 @@
blocks = self._logic._blockList
if self._currentBlock is not None:
- self.findAndChangeFocus(blocks[blocks.index(
- self._currentBlock) - 1])
+ self.__find_and_change_focus(blocks[blocks.index(
+ self._currentBlock) - 1], False)
else:
- self.findAndChangeFocus(blocks[-1])
+ self.__find_and_change_focus(blocks[-1], False)
# -------------------------------------------------------------------------
@@ -964,7 +963,7 @@
next_index = 0
else:
next_index = current_index + 1
- self.findAndChangeFocus(pages[next_index])
+ self.__find_and_change_focus(pages[next_index], False)
# -------------------------------------------------------------------------
@@ -974,71 +973,62 @@
"""
pages = self._layout._pageList
- self.findAndChangeFocus(pages[pages.index(self._currentPage) - 1])
+ self.__find_and_change_focus(pages[pages.index(self._currentPage) - 1],
+ False)
# -------------------------------------------------------------------------
# Move the focus to a new object
# -------------------------------------------------------------------------
- def findAndChangeFocus(self, object):
- """
- Change the focus to the first focusable element of the given object.
+ def __find_and_change_focus(self, object, last):
- The object passed can be a page or a block (in which case the first
- entry on that page/block will be focused) or an entry (in which case
- exactly this entry will be focused).
-
- The focus will be set on GF and on UI layer.
-
- @param: Object from the GF layer
- """
-
- entry = self.findFocus(object)
+ entry = self.__find_focus(object, last)
if entry:
self.change_focus(entry, 0)
# -------------------------------------------------------------------------
- # Find the next focusable item starting at a given GFObject
+ # Find the next focusable item within a container
# -------------------------------------------------------------------------
- def findFocus(self, object):
- """
- Finds the next focusable item of a page, a block or an entry.
+ def __find_focus(self, object, last):
- @param: object (page, block or entry) to find next focus for.
- @return: None or entry with next focus
- """
-
- if object._type == 'GFField':
- assert gDebug(5, "GFField was passed to 'findFocus'.")
- try:
- object = object._entryList[0]
- except IndexError:
- return None
-
if isinstance(object, GFTabStop):
+ # Trivial case: the focus object itself.
if object.is_navigable(self.getCurrentMode()):
return object
+ else:
+ return None
-
elif isinstance(object, GFContainer):
- for child in object.get_focus_order():
- return self.findFocus(child)
+ # Container: search for the first focusable object.
+ list = object.get_focus_order()
+ elif isinstance(object, GFField):
+ # Field: search for the first focusable entry attached to it.
+ list = object._entryList
+
else:
# If the object is neither a TabStop or a Container search for a
# container object and try to retrieve a focus object from it. We
# are looking for the visual items first, and then fall back to the
# blocks.
- container = ['GFPage', 'GFBox', 'GFBlock']
- for item in container:
- for child in object.findChildrenOfType (item, False, True):
- entry = self.findFocus (child)
- if entry:
- return entry
+ list = object.findChildrenOfType('GFPage', False, True) \
+ + object.findChildrenOfType('GFBox', False, True) \
+ + object.findChildrenOfType('GFBlock', False, True)
+ # Reverse the list to search if we are searching the last entry.
+ if last:
+ list.reverse()
+
+ # Return the first object that can receive the focus.
+ for item in list:
+ new_focus = self.__find_focus(item, last)
+ if new_focus:
+ return new_focus
+
+ # Nothing found.
return None
@@ -1494,7 +1484,7 @@
# FIXME: does not work with master/detail, always moves the
# focus to master record.
if block != self._currentBlock:
- self.findAndChangeFocus(block)
+ self.__find_and_change_focus(block, False)
raise
finally:
for block in self._logic._blockList:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9081 - trunk/gnue-forms/src,
reinhard <=