commit-gnue
[Top][All Lists]
Advanced

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

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


From: reinhard
Subject: [gnue] r8767 - trunk/gnue-forms/src/GFObjects
Date: Thu, 12 Oct 2006 07:08:16 -0500 (CDT)

Author: reinhard
Date: 2006-10-12 07:08:15 -0500 (Thu, 12 Oct 2006)
New Revision: 8767

Modified:
   trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
Restructuring in scrolling logic.


Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py   2006-10-12 11:12:07 UTC (rev 
8766)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py   2006-10-12 12:08:15 UTC (rev 
8767)
@@ -93,8 +93,9 @@
     # differ per entry)
     self.__visibleStart = 0
 
-    # Are we scrolling the visible portion along with record movement?
-    self.__scrolling = False
+    # If this is true, notifying attached objects of current record changes is
+    # temporarily blocked
+    self.__scrolling_blocked = False
 
     # Has the result set changed since the last refresh?
     self.__has_resultset_changed = False
@@ -271,19 +272,22 @@
 
     self._resultSet = event.resultSet
 
-    self.__has_resultset_changed = True
-
     # FIXME: during commit, master datasources navigate the current record
     # through the dirty record list and cause the detail blocks to follow
     # through this event. However, in that case, we wouldn't want the UI to
     # follow, so we wouldn't want to run the following lines in that case.
     recno = self._resultSet.getRecordNumber ()
     if recno == -1:
-      if not self._resultSet.firstRecord ():
-        self._resultSet.insertRecord(self._lastValues)
-    else:
-      self.__switch_record (recno - self._currentRecord)
+      self.__scrolling_blocked = True
+      try:
+        if not self._resultSet.firstRecord ():
+          self._resultSet.insertRecord(self._lastValues)
+      finally:
+        self.__scrolling_blocked = False
 
+    self.__has_resultset_changed = True
+    self.__switch_record (recno - self._currentRecord)
+
     self._form.update_record_counter()
     self._form.update_record_status()
 
@@ -292,13 +296,13 @@
 
   def __dsCursorMoved (self, event):
 
+    if self.__scrolling_blocked:
+        return
+
     # Blocks can't cope with current record #-1
     recno = self._resultSet.getRecordNumber ()
     if recno != -1:
-      if self.__scrolling:
-        self.__switch_record (0)
-      else:
-        self.__switch_record (recno - self._currentRecord)
+      self.__switch_record (recno - self._currentRecord)
 
   # ---------------------------------------------------------------------------
 
@@ -390,42 +394,37 @@
   # ---------------------------------------------------------------------------
 
   def _event_scroll_to_record (self, position):
-    """
-    Scrolls the block to the given position.
+        """
+        Scrolls the block to the given position.
 
-    @param position: the record number to scroll to. This record will become
-      the first visible record.
-    """
+        @param position: the record number to scroll to. This record will
+            become the first visible record.
+        """
 
-    if position < 0:
-      position = 0
-    elif position > self._resultSet.getRecordCount() - self._rows:
-      position = self._resultSet.getRecordCount() - self._rows
+        # Make sure we don't scroll outside the available records
+        position = min(position, self._resultSet.getRecordCount() - self._rows)
+        position = max(position, 0)
 
-    # First, scroll as far as possible without moving the record pointer
-    newVisibleStart = position
+        # Got anything to do at all?
+        if position == self.__visibleStart:
+            return
 
-    if newVisibleStart > self._currentRecord:
-      newVisibleStart = self._currentRecord
-    if newVisibleStart < self._currentRecord - self._rows + 1:
-      newVisibleStart = self._currentRecord - self._rows + 1
+        # Jump to another record if necessary
+        self.__scrolling_blocked = True
+        try:
+            if self._currentRecord < position:
+                self.goto_record(position)
+            elif self._currentRecord > position + self._rows -1:
+                self.goto_record(position + self._rows - 1)
+        finally:
+            self.__scrolling_blocked = False
 
-    if newVisibleStart != self.__visibleStart:
-      self.__switch_record (self.__visibleStart - newVisibleStart)
+        # And now scroll the entries
+        self.__switch_record(self.__visibleStart - position)
+        if getattr(self._form._currentEntry, '_block', None) == self:
+            self._form.adjust_ui_focus()
 
-    # Now we have to move the record pointer to keep it in the visible portion
-    if position != self.__visibleStart:
-      self.__scrolling = True
-      try:
-        self.jump_records (position - self.__visibleStart)
-      finally:
-        self.__scrolling = False
-    else:
-      # If we didn't move the cursor, we have to update cursor position in UI
-      if getattr(self._form._currentEntry, '_block', None) == self:
-          self._form.adjust_ui_focus()
 
-
   # ---------------------------------------------------------------------------
   # Field access
   # ---------------------------------------------------------------------------
@@ -1125,13 +1124,10 @@
 
 
   # ---------------------------------------------------------------------------
-  # Helper Functions
+  # Switch the proper record into editing position
   # ---------------------------------------------------------------------------
 
   def __switch_record (self, adjustment):
-    """
-    Moves the proper record into editing position
-    """
 
     if self.mode == 'query':
         newRecord = 0





reply via email to

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