commit-gnue
[Top][All Lists]
Advanced

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

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


From: johannes
Subject: [gnue] r8352 - trunk/gnue-forms/src/GFObjects
Date: Tue, 4 Apr 2006 03:25:02 -0500 (CDT)

Author: johannes
Date: 2006-04-04 03:25:01 -0500 (Tue, 04 Apr 2006)
New Revision: 8352

Modified:
   trunk/gnue-forms/src/GFObjects/GFBlock.py
   trunk/gnue-forms/src/GFObjects/GFScrollBar.py
Log:
Cleanup of GFBlock


Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py   2006-04-04 08:24:06 UTC (rev 
8351)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py   2006-04-04 08:25:01 UTC (rev 
8352)
@@ -25,10 +25,10 @@
 """
 
 from gnue.forms.GFObjects.GFDataSource import GFDataSource
+from gnue.forms.GFObjects.GFContainer import GFContainer
 
 from gnue.common.apps import errors
 from gnue.common.datasources import GConditions
-from GFContainer import GFContainer
 from gnue.common import events
 from gnue.common.definitions import GParser
 
@@ -42,7 +42,13 @@
           % {'datasource': source, 'block': block.name}
     GParser.MarkupError.__init__ (self, msg, block._url, block._lineNumber)
 
+class InvalidEditableError (errors.ApplicationError):
+  def __init__ (self, value):
+    msg = u_("'%(value)s' is not a valid option for editable. " \
+             "Please use one of 'Y', 'N', 'new', 'update'") % {'value': value}
+    errors.ApplicationError.__init__ (self, msg)
 
+
 # =============================================================================
 # Wrapper of a block
 # =============================================================================
@@ -239,6 +245,34 @@
 
 
   # ---------------------------------------------------------------------------
+  # Get an ordered list of focus-controls
+  # ---------------------------------------------------------------------------
+
+  def getFocusOrder (self):
+
+    ctrlList = []
+    for field in self._children:
+      ctrlList += getattr (field, '_entryList', [])
+
+    return GFContainer.getFocusOrder (self, ctrlList)
+
+
+  # ---------------------------------------------------------------------------
+  # Register a scrollbar widget
+  # ---------------------------------------------------------------------------
+
+  def registerScrollbar (self, widget):
+    """
+    Register a given scrollbar widget to the block. This widget will be
+    notified on record movement. It has to implement a method
+    'doAdjustScrollbar', taking the current record and the number of records as
+    arguments.
+    """
+
+    self._scrollbars.append (widget)
+
+
+  # ---------------------------------------------------------------------------
   # Implementation of virtual methods
   # ---------------------------------------------------------------------------
 
@@ -289,9 +323,8 @@
 
     self.walk (self.__setChildRowSettings)
 
+
   # ---------------------------------------------------------------------------
-  # Distribute the rows and gaps to all children missing such an attribute
-  # ---------------------------------------------------------------------------
 
   def __setChildRowSettings (self, child):
 
@@ -301,6 +334,7 @@
     child._gap  = getattr (child, 'rowSpacer', self._gap)
 
 
+
   # ---------------------------------------------------------------------------
   # Event handling functions for datasource events
   # ---------------------------------------------------------------------------
@@ -323,6 +357,7 @@
   # ---------------------------------------------------------------------------
 
   def __dsCursorMoved (self, event):
+
     # Blocks can't cope with current record #-1
     recno = self._resultSet.getRecordNumber ()
     if recno != -1:
@@ -383,332 +418,432 @@
 
 
   # ---------------------------------------------------------------------------
-  # Get an ordered list of focus-controls
+  # Event handlers to be called from outside GF
   # ---------------------------------------------------------------------------
 
-  def getFocusOrder (self):
+  def _event_scroll_delta (self, adjustment):
+    """
+    Scroll the given number of records.
 
-    ctrlList = []
-    for field in self._children:
-      ctrlList += getattr (field, '_entryList', [])
+    @param adjustment: number of records to move relative to the current
+      record.
+    """
+  
+    self._event_scroll_to_record (self.__visibleStart + adjustment)
 
-    return GFContainer.getFocusOrder (self, ctrlList)
 
+  # ---------------------------------------------------------------------------
 
-  #
-  # isSaved
-  #
-  #
-  def isSaved(self):
+  def _event_scroll_to_record (self, position):
     """
-    Returns True if the datasource the block is associated
-    with is not pending any changes.
+    Scrolls the block to the given position.
+
+    @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
+
+    # First, scroll as far as possible without moving the record pointer
+    newVisibleStart = position
+
+    if newVisibleStart > self._currentRecord:
+      newVisibleStart = self._currentRecord
+    if newVisibleStart < self._currentRecord - self._rows + 1:
+      newVisibleStart = self._currentRecord - self._rows + 1
+
+    if newVisibleStart != self.__visibleStart:
+      self.switchRecord (self.__visibleStart - newVisibleStart)
+
+    # Now we have to move the record pointer to keep it in the visible portion
+    if position != self.__visibleStart:
+      self.__scrolling = True
+      try:
+        self.jumpRecords (position - self.__visibleStart)
+      finally:
+        self.__scrolling = False
+    else:
+      # If we didn't move the cursor, we have to update cursor position in UI
+      if self._form._currentEntry._block == self:
+        self._form.findAndChangeFocus (self._form._currentEntry)
+
+
+
+
+  # ===========================================================================
+  # Trigger functions
+  # ===========================================================================
+
+  def isSaved (self):
+    """
+    Returns True if the datasource the block is associated with is not pending
+    any changes.
+
+    This method is depreciated. Please use block.isPending () instead !
+    """
+
     print "DEPRECIATION WARNING: the use of block.isSaved () is depreciated.", 
\
           "Please use block.isPending () instead."
-    return not self.isPending()
+    return not self.isPending ()
 
-  def isPending(self):
+  # ---------------------------------------------------------------------------
+
+  def isPending (self):
     """
-    Returns True if the datasource the block is associated
-    with is pending any changes.
+    Returns True if the datasource the block is associated with is pending any
+    changes.
     """
-    return self._resultSet and self._resultSet.isPending()
 
-  #
-  # deleteRecord
-  #
-  # FIXME: This is a duplicate of GDataSource.__trigger_delete. Do we really
-  # need both?
-  def deleteRecord(self):
+    return self._resultSet and self._resultSet.isPending ()
+
+  # ---------------------------------------------------------------------------
+
+  def isEmpty (self):
     """
-    Doesn't really delete the record but marks it for
-    deletion during next commit
+    Returns True if the current record is empty.
+
+    Empty means that it has been newly inserted, but neither has any field been
+    changed nor has a detail for this record been inserted with a status other
+    than empty.
     """
-    self._resultSet.current.delete()
 
-  #
-  # undeleteRecord
-  #
-  def undeleteRecord(self):
+    return self._resultSet.current.isEmpty ()
+
+  # ---------------------------------------------------------------------------
+
+  def isLastRecord (self):
     """
-    Removes the delete mark from the record
+    Returns True if the current record is the last one in the ResultSet.
     """
-    self._resultSet.current.undelete()
 
-  #
-  # isEmpty()
-  #
-  def isEmpty(self):
-    return self._resultSet.current.isEmpty()
+    return self._resultSet.isLastRecord ()
 
-  #
-  # getResultSet()
-  #
-  def getResultSet(self):
-    return self._resultSet
+  # ---------------------------------------------------------------------------
 
-
-  #
-  #
-  #
-  def switchRecord(self, adjustment):
+  def isFirstRecord (self):
     """
-    Moves the proper record into editing position
+    Returns True if the current record is the first one in the ResultSet
     """
-    newRecord = self._resultSet.getRecordNumber ()
-    newRecordCount = self._resultSet.getRecordCount ()
 
-    self.__visibleStart += newRecord - self._currentRecord - adjustment
-    if self.__visibleStart > newRecord:
-      self.__visibleStart = newRecord
-    if self.__visibleStart < newRecord - self._rows + 1:
-      self.__visibleStart = newRecord - self._rows + 1
-    if self.__visibleStart < 0:
-      self.__visibleStart = 0
+    return self._resultSet.isFirstRecord ()
 
-    self._currentRecord = newRecord
-    self._recordCount = newRecordCount
+  # ---------------------------------------------------------------------------
 
-    for field in self._fieldList:
-      field.gotNewCurrentRecord()
-      for entry in field._entryList:
-        # This loop is probably better somewhere else
-        entry.recalculateVisible( adjustment, self._currentRecord, 
-                                  self._recordCount)
-      self._form.updateUIEntry(field)
-      self._form.refreshUIEvents()
+  def lastRecord (self):
+    """
+    Move to the last record of the block. Pre- and Post-Focusout triggers are
+    fired before moving as well as Pre- and Post-Focusin triggers after moving
+    the record pointer.
+    """
 
-    # Adjusting scrollbars
-    for sb in self._scrollbars:
-      sb.doAdjustScrollbar (self.__visibleStart,
-          max (self._recordCount, self.__visibleStart + self._rows))
+    if not self._resultSet.isLastRecord ():
+      # Do FocusOut triggers
+      self.processTrigger ('PRE-FOCUSOUT')
+      self.processTrigger ('POST-FOCUSOUT')
 
+      self._resultSet.lastRecord ()
 
+      # Focus in
+      self.processTrigger ('PRE-FOCUSIN')
+      self.processTrigger ('POST-FOCUSIN')
 
-  #
-  # newRecord
-  #
-  # Adds a record to the current records in memory
-  #
-  def newRecord(self):
+  # ---------------------------------------------------------------------------
 
-    # Focus out
-    self.processTrigger('PRE-FOCUSOUT')
-    if self.autoCommit and self._resultSet.current:
-      self._form.commit()
-    self.processTrigger('POST-FOCUSOUT')
+  def firstRecord (self):
+    """
+    Move to the first record of the block. Pre- and Post-Focusout triggers are
+    fired before moving as well as Pre- and Post-Focusin triggers after moving
+    the record pointer.
+    """
 
-    if self._resultSet.insertRecord (self._lastValues):
+    if not self._resultSet.isFirstRecord ():
+      # Do FocusOut triggers
+      self.processTrigger ('PRE-FOCUSOUT')
+      self.processTrigger ('POST-FOCUSOUT')
 
-      self._recordCount = self._resultSet.getRecordCount()
+      self._resultSet.firstRecord ()
 
       # Focus in
-      self.processTrigger('PRE-FOCUSIN')
-      self.processTrigger('POST-FOCUSIN')
+      self.processTrigger ('PRE-FOCUSIN')
+      self.processTrigger ('POST-FOCUSIN')
 
-  def duplicateRecord(self, exclude=(), include=()):
-    self._resultSet.duplicateRecord(exclude=exclude, include=include)
+  # ---------------------------------------------------------------------------
 
-  def isLastRecord(self):
-    return self._resultSet.isLastRecord()
+  def prevRecord (self):
+    """
+    Move to the previous record of the block. Pre- and Post-Focusout triggers
+    are fired before moving as well as Pre- and Post-Focusin triggers after
+    moving the record pointer.
+    """
 
-  def isFirstRecord(self):
-    return self._resultSet.isFirstRecord()
+    if not self._resultSet.isFirstRecord ():
+      # Do FocusOut triggers
+      self.processTrigger ('PRE-FOCUSOUT')
+      self.processTrigger ('POST-FOCUSOUT')
 
-  def nextRecord(self):
-    if not self._resultSet.isLastRecord():
+      self._resultSet.prevRecord ()
 
+      # Focus in
+      self.processTrigger ('PRE-FOCUSIN')
+      self.processTrigger ('POST-FOCUSIN')
+
+  # ---------------------------------------------------------------------------
+
+  def nextRecord (self):
+    """
+    Move to the next record. If autoCommit is set a commit is performed prior
+    to move the record pointer. If the record is already the last one, a new
+    record will be created if the following conditions are met: autoCreate is
+    True, there are already records available in the block and the block is
+    editable.
+    """
+
+    if not self._resultSet.isLastRecord ():
       # Do FocusOut triggers
-      self.processTrigger('PRE-FOCUSOUT')
+      self.processTrigger ('PRE-FOCUSOUT')
       if self.autoCommit:
-        self._form.commit()
-      self.processTrigger('POST-FOCUSOUT')
+        self._form.commit ()
+      self.processTrigger ('POST-FOCUSOUT')
 
-      self._resultSet.nextRecord()
-      self._recordCount = self._resultSet.getRecordCount()
+      self._resultSet.nextRecord ()
+      self._recordCount = self._resultSet.getRecordCount ()
 
       # Focus in
-      self.processTrigger('PRE-FOCUSIN')
-      self.processTrigger('POST-FOCUSIN')
+      self.processTrigger ('PRE-FOCUSIN')
+      self.processTrigger ('POST-FOCUSIN')
 
-    elif self.autoCreate and not self.isEmpty() and \
-         not self.editable in ('update','N'):
-      self.newRecord()
+    elif self.autoCreate and not self.isEmpty () and \
+         not self.editable in ('update', 'N'):
+      self.newRecord ()
+
       # Go to first field
-      self._form.findAndChangeFocus(self._entryList[0])
+      # TODO: check if this is really what we want to have 
+      self._form.findAndChangeFocus (self._entryList [0])
 
 
+  # ---------------------------------------------------------------------------
 
-  def lastRecord(self):
-    if not self._resultSet.isLastRecord():
-      # Do FocusOut triggers
-      self.processTrigger('PRE-FOCUSOUT')
-      self.processTrigger('POST-FOCUSOUT')
+  def deleteRecord (self):
+    """
+    Mark the current record for deletion. The acutal deletion will be done on
+    the next commit, call or update.
+    """
 
-      self._resultSet.lastRecord()
+    self._resultSet.current.delete ()
 
-      # Focus in
-      self.processTrigger('PRE-FOCUSIN')
-      self.processTrigger('POST-FOCUSIN')
+  # ---------------------------------------------------------------------------
 
-  def firstRecord(self):
-    if not self._resultSet.isFirstRecord():
-      # Do FocusOut triggers
-      self.processTrigger('PRE-FOCUSOUT')
-      self.processTrigger('POST-FOCUSOUT')
+  def undeleteRecord (self):
+    """
+    Removes the deletion mark from the record
+    """
 
-      self._resultSet.firstRecord()
+    self._resultSet.current.undelete ()
 
-      # Focus in
-      self.processTrigger('PRE-FOCUSIN')
-      self.processTrigger('POST-FOCUSIN')
 
-  def prevRecord(self):
-    if not self._resultSet.isFirstRecord():
+  # ---------------------------------------------------------------------------
 
-      # Do FocusOut triggers
-      self.processTrigger('PRE-FOCUSOUT')
-      self.processTrigger('POST-FOCUSOUT')
+  def newRecord (self):
+    """
+    Add a new record to the block. If autoCommit is set and a record is
+    currently pending it will be commited first.
+    """
 
-      self._resultSet.prevRecord()
+    # Focus out
+    self.processTrigger ('PRE-FOCUSOUT')
 
+    if self.autoCommit and self._resultSet.current:
+      self._form.commit ()
+
+    self.processTrigger ('POST-FOCUSOUT')
+
+    if self._resultSet.insertRecord (self._lastValues):
+      self._recordCount = self._resultSet.getRecordCount ()
+
       # Focus in
-      self.processTrigger('PRE-FOCUSIN')
-      self.processTrigger('POST-FOCUSIN')
+      self.processTrigger ('PRE-FOCUSIN')
+      self.processTrigger ('POST-FOCUSIN')
 
-  def commit(self):
+
+  # ---------------------------------------------------------------------------
+
+  def duplicateRecord (self, exclude = (), include = ()):
+    """
+    Create a new record and initialize it with field values from the record at
+    the current cursor position.
+
+    @param exclude: list of fields not to copy.
+    @param include: list of fields to copy. An empty list means to copy all
+      fields except primary key fields and rowid fields, which are never copied
+      anyway.
+    """
+
+    # TODO: check if we need to do autoCommit and fire triggers here too
+    self._resultSet.duplicateRecord (exclude = exclude, include = include)
+
+
+  # ---------------------------------------------------------------------------
+
+  def switchRecord (self, adjustment):
+    """
+    Moves the proper record into editing position
+    """
+
+    newRecord      = self._resultSet.getRecordNumber ()
+    newRecordCount = self._resultSet.getRecordCount ()
+
+    self.__visibleStart += newRecord - self._currentRecord - adjustment
+
+    self.__visibleStart = min (self.__visibleStart, newRecord)
+    self.__visibleStart = max (self.__visibleStart, newRecord - self._rows + 1)
+    self.__visibleStart = max (self.__visibleStart, 0)
+
+    self._currentRecord = newRecord
+    self._recordCount   = newRecordCount
+
+    for field in self._fieldList:
+      field.gotNewCurrentRecord ()
+
+      for entry in field._entryList:
+        # This loop is probably better somewhere else
+        entry.recalculateVisible (adjustment, self._currentRecord,
+                                  self._recordCount)
+
+      self._form.updateUIEntry (field)
+
+    self._form.refreshUIEvents ()
+
+    # Adjusting scrollbars
+    for sb in self._scrollbars:
+      sb.doAdjustScrollbar (self.__visibleStart,
+          max (self._recordCount, self.__visibleStart + self._rows))
+
+  # ---------------------------------------------------------------------------
+
+  def getResultSet (self):
+    """
+    Return the current ResultSet of the block.
+    """
+
+    return self._resultSet
+
+
+  # ---------------------------------------------------------------------------
+
+  def commit (self):
+    """
+    Commit all pending changes of the form this block is bound to.
+
+    This method is depreciated. Please use form.commit () instead.
+    """
+
     print "DEPRECIATION WARNING: the use of block.commit () is depreciated.", \
           "Please use form.commit () instead."
     self._form.commit ()
 
 
-  def jumpRecord(self, recordNumber):
+  # ---------------------------------------------------------------------------
+
+  def jumpRecord (self, recordNumber):
+    """
+    Jump to a specific record. If the block is the block being currently edited
+    in the form, the focus-out and focus-in block-level triggers will be fired.
+
+    @param recordNumber: record number to jump to. If this is a negative value,
+      move relative to the last record
+    """
+
     # If recordNumber is negative, move relative to last record
     if recordNumber < 0:
-      recordNumber += self._resultSet.getRecordCount()
+      recordNumber += self._resultSet.getRecordCount ()
     if recordNumber < 0:
       raise "Invalid record number"
 
-    if recordNumber != self._resultSet.getRecordNumber():
-
+    if recordNumber != self._resultSet.getRecordNumber ():
       if self._form._currentEntry._block == self:
         # Focus out
-        self.processTrigger('PRE-FOCUSOUT')
-        self.processTrigger('POST-FOCUSOUT')
+        self.processTrigger ('PRE-FOCUSOUT')
+        self.processTrigger ('POST-FOCUSOUT')
 
-      if not self._resultSet.setRecord(recordNumber):
-        self._resultSet.lastRecord()
+      if not self._resultSet.setRecord (recordNumber):
+        self._resultSet.lastRecord ()
 
       if self._form._currentEntry._block == self:
         # Focus in
-        self.processTrigger('PRE-FOCUSIN')
-        self.processTrigger('POST-FOCUSIN')
+        self.processTrigger ('PRE-FOCUSIN')
+        self.processTrigger ('POST-FOCUSIN')
+
         # Move to correct record in grid
         self._form.findAndChangeFocus (self._form._currentEntry)
         self._form._instance.updateRecordCounter (self._form)
 
 
-  def jumpRecords(self, adjustment):
-    targetRecord = self._resultSet.getRecordNumber() + adjustment
-
-    if targetRecord < 0:
-      targetRecord = 0
-    elif targetRecord > self._resultSet.getRecordCount():
-      targetRecord = self._resultSet.getRecordCount()
-
-    self.jumpRecord(targetRecord)
-
-
   # ---------------------------------------------------------------------------
-  # Scroll a given number of records
-  # ---------------------------------------------------------------------------
 
-  def scrollRecords (self, adjustment):
+  def jumpRecords (self, adjustment):
     """
-    Scroll the given number of records.
-    """
-    
-    self.scrollToRecord (self.__visibleStart + adjustment)
+    Move the record-pointer by a given adjustment relative to the current
+    record.
 
-
-  # ---------------------------------------------------------------------------
-  # Scroll to given record number
-  # ---------------------------------------------------------------------------
-
-  def scrollToRecord (self, position):
+    @param adjustment: the number of records to move from the current record.
     """
-    Scrolls the block to the given position.
 
-    The record number given in position will become the first visible record.
-    """
-    
-    if position < 0:
-      position = 0
-    elif position > self._resultSet.getRecordCount() - self._rows:
-      position = self._resultSet.getRecordCount() - self._rows
+    targetRecord = max (self._resultSet.getRecordNumber() + adjustment, 0)
 
-    # First, scroll as far as possible without moving the record pointer
-    newVisibleStart = position
+    if targetRecord > self._resultSet.getRecordCount ():
+      targetRecord = self._resultSet.getRecordCount()
 
-    if newVisibleStart > self._currentRecord:
-      newVisibleStart = self._currentRecord
-    if newVisibleStart < self._currentRecord - self._rows + 1:
-      newVisibleStart = self._currentRecord - self._rows + 1
+    self.jumpRecord (targetRecord)
 
-    if newVisibleStart != self.__visibleStart:
-      self.switchRecord (self.__visibleStart - newVisibleStart)
+  # ---------------------------------------------------------------------------
 
-    # Now we have to move the record pointer to keep it in the visible portion
-    if position != self.__visibleStart:
-      self.__scrolling = True
-      try:
-        self.jumpRecords (position - self.__visibleStart)
-      finally:
-        self.__scrolling = False
-    else:
-      # If we didn't move the cursor, we have to update cursor position in UI
-      if self._form._currentEntry._block == self:
-        self._form.findAndChangeFocus (self._form._currentEntry)
+  def processCommit (self):
+    """
+    Post all pending changes of the block
+    """
 
+    assert gDebug (4, "processing commit on block %s" % self.name, 1)
 
-  #
-  # processCommit
-  #
-  def processCommit(self):
-    assert gDebug (4, "processing commit on block %s"%self.name,1)
+    self.mode = 'commit'
 
-    self.mode='commit'
+    self._resultSet.setRecord (self._precommitRecord)
 
-    self._resultSet.setRecord(self._precommitRecord)
-
     if self._getMasterBlock () is None:
       self._dataSourceLink.postAll ()
 
-  #
-  # Called after the commit on the backend is through.
-  #
+  # ---------------------------------------------------------------------------
+
   def finalizeCommit (self, commit):
+    """
+    Called after the commit on the backend is through.
+    """
 
     # Synchronize backend -> resultset -> UI
     if self._getMasterBlock () is None:
       self._dataSourceLink.requeryAll (commit)
 
     # Our recordCount might have changed if records were deleted
-    self._recordCount = self._resultSet.getRecordCount()
+    self._recordCount = self._resultSet.getRecordCount ()
 
     # If all records were deleted, create an empty new one.
     if not self._recordCount:
-      self.newRecord()
+      self.newRecord ()
 
-    self.mode='normal'
+    self.mode = 'normal'
 
 
-  #
-  # processClear
-  #
-  def processClear(self):
+  # ---------------------------------------------------------------------------
 
+  def processClear (self):
+    """
+    Rollback the blocks pending changes (by calling a rollback of the backend)
+    and finally create a new and empty result set.  This method has no effect
+    for detail-blocks.
+    """
+
     # Detail blocks cannot be cleared - they follow their master blindly.
     if self._getMasterBlock () is not None:
       return
@@ -719,21 +854,24 @@
     self._dataSourceLink.createEmptyResultSet ()
 
 
-  #
-  # processRollback
-  #
-  # if recovering=False, then the user requested a rollback
-  # if recovering=True, then a commit or such failed and we need to clean up
-  # (but not lose state information)
-  #
+  # ---------------------------------------------------------------------------
+
   def processRollback (self, recovering = False, backendRollback = True):
+    """
+    Perform a rollback of all pending changes of the block.
+    @param recovering: If False, the user requested a rollback and a new, empty
+      result set will be created. If True, then a commit or such failed and we
+      need to clean up (but not lose state information).
+    @param backendRollback: If True, a rollback is performed on the backend
+      connection, otherwise not.
+    """
 
     # Detail blocks cannot be rolled back - they follow their master blindly.
     if self._getMasterBlock () is not None:
       return
 
-    # if called from GFForm the connection's rollback () has been executed
-    # already. But if called from a trigger code we do it here
+    # If called from GFForm the connection's rollback () has been executed
+    # already.  But if called from a trigger code we do it here
     if backendRollback:
       if self._dataSourceLink._connection is not None:
         self._dataSourceLink._connection.rollback ()
@@ -742,132 +880,133 @@
       self._dataSourceLink.createEmptyResultSet ()
 
 
-  #
-  # initQuery and processQuery
-  #
-  def initQuery(self):
+  # ---------------------------------------------------------------------------
 
+  def initQuery (self):
+
     # If Enter-Query is hit once, enter query mode
     # If Enter-Query is hit twice, bring back conditions from last query.
     # If Enter-Query is hit thrice, cancel the query and go into normal mode.
 
     if self.mode != 'query':
       self.mode = 'query'
-      self._query2 = int(gConfigForms("RememberLastQuery"))
+      self._query2 = int (gConfigForms ("RememberLastQuery"))
       self._queryValues = {}
-      self._queryValues.update(self._queryDefaults)
-      self.switchRecord(0)
+      self._queryValues.update (self._queryDefaults)
+      self.switchRecord (0)
 
-  def copyQuery(self):
+  # ---------------------------------------------------------------------------
+
+  def copyQuery (self):
+
     self._query2 = 0
     self._queryValues = {}
-    self._queryValues.update(self._lastQueryValues)
-    self.switchRecord(0)
+    self._queryValues.update (self._lastQueryValues)
+    self.switchRecord (0)
 
-  def cancelQuery(self):
+  # ---------------------------------------------------------------------------
+
+  def cancelQuery (self):
+
     self.mode = 'normal'
-    self.switchRecord(0)
+    self.switchRecord (0)
 
-  def processQuery(self):
-    # Set the maxList to a single master block
-    # as a placeholder
+  # ---------------------------------------------------------------------------
+
+  def processQuery (self):
+
+    # Set the maxList to a single master block as a placeholder.
     maxList = [self._getTopMasterBlock ()]
 
-    # Find the longest master/detail chain that
-    # contains query values.  This will become
-    # the chain that is queried
+    # Find the longest master/detail chain that contains query values.  This
+    # will become the chain that is queried.
     for block in self._logic._blockList:
       if block._queryValues.keys ():
         templist = [block]
+
         while (templist [-1])._getMasterBlock ():
           templist.append ((templist [-1])._getMasterBlock ())
-        if len (maxList) < len (templist): maxList = templist
 
+        if len (maxList) < len (templist):
+          maxList = templist
+
     # Store block states
     for block in self._logic._blockList:
       block.mode = 'normal'
       block._lastQueryValues = {}
-      block._lastQueryValues.update(block._queryValues)
+      block._lastQueryValues.update (block._queryValues)
 
     # graft in the sloppy query stuff if needed
     for block in maxList:
       for entry in block._entryList:
-        if hasattr(entry._field,'sloppyQuery') and \
-           block._queryValues.has_key(entry._field):
-          block._queryValues[entry._field] = "%"+ \
-            "%".join(list(block._queryValues[entry._field]))+"%"
+        if hasattr (entry._field, 'sloppyQuery') and \
+           block._queryValues.has_key (entry._field):
+          block._queryValues [entry._field] = "%" + \
+            "%".join (list (block._queryValues [entry._field])) + "%"
 
     # Find root block
     rootBlock = maxList [-1]
 
     # Condition for the master block
-    conditions = _generateConditional(rootBlock)
+    conditions = _generateConditional (rootBlock)
 
     # Conditions for the detail block
-    for block in maxList[:-1]:
+    for block in maxList [:-1]:
 
-      block.processTrigger('PRE-QUERY')
+      block.processTrigger ('PRE-QUERY')
       for field in block._fieldList:
-        field.processTrigger('PRE-QUERY')
+        field.processTrigger ('PRE-QUERY')
 
-      c = _generateConditional(block)
-      exist = GConditions.GCexist()
+      c = _generateConditional (block)
+      exist = GConditions.GCexist ()
       exist.table = block._dataSourceLink.table
       exist.masterlink = block._dataSourceLink.masterlink
       exist.detaillink = block._dataSourceLink.detaillink
       exist._children = [c]
       conditions = GConditions.combineConditions (conditions, exist)
 
-    rootBlock._dataSourceLink.createResultSet(conditions)
+    rootBlock._dataSourceLink.createResultSet (conditions)
 
-    rootBlock._recordCount = rootBlock._resultSet.getRecordCount()
+    rootBlock._recordCount = rootBlock._resultSet.getRecordCount ()
 
     for block in self._logic._blockList:
-      block.processTrigger('POST-QUERY')
+      block.processTrigger ('POST-QUERY')
       for field in block._fieldList:
-        field.processTrigger('POST-QUERY')
+        field.processTrigger ('POST-QUERY')
 
     # Adjusting scrollbars
     for sb in self._scrollbars:
       sb.doAdjustScrollbar (self._currentRecord, self._recordCount)
 
 
-  def registerScrollbar (self, sb):
-    self._scrollbars.append (sb)
-
-
   # ---------------------------------------------------------------------------
-  # Call a datasource's function
-  # ---------------------------------------------------------------------------
 
-  # FIXME: This is a duplicate of GDataSource.__trigger_call. Do we really need
-  # both?
   def callFunction (self, name, parameters):
+
     try:
       # Remember the current record; the record pointer is not reliable between
       # postAll and requeryAll!
       current = self._resultSet.current
       self._dataSourceLink.postAll ()
+
       try:
         res = current.call (name, parameters)
       finally:
         self._dataSourceLink.requeryAll (False)
+
     finally:
       self.switchRecord (0)
 
     return res
 
-
   # ---------------------------------------------------------------------------
-  # Update the current datasource's record set
-  # ---------------------------------------------------------------------------
 
-  # FIXME: This is a duplicate of GDataSource.__trigger_update. Do we really
-  # need both?
   def updateCurrentRecordSet (self):
+
     try:
       self._dataSourceLink.postAll ()
       self._dataSourceLink.requeryAll (False)
+
     finally:
       self.switchRecord (0)
 
@@ -904,51 +1043,93 @@
       return None
 
 
-  ###################################################################
-  #
-  # Trigger settable stuff
-  #
-  def triggerSetAutoCommit(self, value):
-    self.autoCommit = not not value # Force boolean
+  # ===========================================================================
+  # Trigger Namespace properties
+  # ===========================================================================
 
-  def triggerGetAutoCommit(self):
+  def triggerSetAutoCommit (self, value):
+
+    self.autoCommit = bool (value)
+
+  # ---------------------------------------------------------------------------
+
+  def triggerGetAutoCommit (self):
+
     return self.autoCommit
 
-  def triggerSetQueryable(self, value):
-    self.queryable = not not value # Force boolean
+  # ---------------------------------------------------------------------------
 
-  def triggerGetQueryable(self):
+  def triggerSetQueryable (self, value):
+
+    self.queryable = bool (value)
+
+  # ---------------------------------------------------------------------------
+
+  def triggerGetQueryable (self):
+
     return self.queryable
 
-  def triggerSetEditable(self, value):
-    assert (value in ('Y','new','update','N'))
-    self.editable = value
+  # ---------------------------------------------------------------------------
 
-  def triggerGetEditable(self):
+  def triggerSetEditable (self, value):
+
+    if value in ['Y', 'N', 'new', 'update']:
+      self.editable = value
+    else:
+      raise InvalidEditableError, value
+
+  # ---------------------------------------------------------------------------
+
+  def triggerGetEditable (self):
+
     return self.editable
 
-  def triggerSetAutoCreate(self, value):
-    self.autoCreate = not not value # Force boolean
+  # ---------------------------------------------------------------------------
 
-  def triggerGetAutoCreate(self):
+  def triggerSetAutoCreate (self, value):
+
+    self.autoCreate = bool (value)
+
+  # ---------------------------------------------------------------------------
+
+  def triggerGetAutoCreate (self):
+
     return self.autoCreate
 
-  def triggerSetDeletable(self, value):
-    self.deletable = not not value # Force boolean
+  # ---------------------------------------------------------------------------
 
-  def triggerGetDeletable(self):
+  def triggerSetDeletable (self, value):
+
+    self.deletable = bool (value)
+
+  # ---------------------------------------------------------------------------
+
+  def triggerGetDeletable (self):
+
     return self.deletable
 
-  def triggerSetTransparent(self, value):
-    self.transparent = not not value # Force boolean
+  # ---------------------------------------------------------------------------
 
-  def triggerGetTransparent(self):
+  def triggerSetTransparent (self, value):
+
+    self.transparent = bool (value)
+
+  # ---------------------------------------------------------------------------
+
+  def triggerGetTransparent (self):
+
     return self.transparent
 
-  def triggerSetAutoNextRecord(self, value):
-    self.autoNextRecord = not not value # Force boolean
+  # ---------------------------------------------------------------------------
 
-  def triggerGetAutoNextRecord(self):
+  def triggerSetAutoNextRecord (self, value):
+
+    self.autoNextRecord = bool (value)
+
+  # ---------------------------------------------------------------------------
+
+  def triggerGetAutoNextRecord (self):
+
     return self.autoNextRecord
 
 
@@ -1036,35 +1217,60 @@
   return result
 
 
+# =============================================================================
+# Iterator class for a given GFBlock
+# =============================================================================
+
 class _BlockIter:
-  """A simple resultset iterator that lets you use ResultSets as:
+  """A simple iterator that lets you use a Block like:
 
-    for record in myResultSet:
+    for record in myBlock:
       blah
   """
-  def __init__(self, block):
+
+  # ---------------------------------------------------------------------------
+  # Constructor
+  # ---------------------------------------------------------------------------
+
+  def __init__ (self, block):
+
     self.block = block
-    self.new = True
-    self.done = False
+    self.new   = True
+    self.done  = False
 
-  def __iter__(self):
+
+  # ---------------------------------------------------------------------------
+  # Return the iterator object itself
+  # ---------------------------------------------------------------------------
+
+  def __iter__ (self):
+
     return self
 
-  def next(self):
+
+  # ---------------------------------------------------------------------------
+  # Return the next item from the container
+  # ---------------------------------------------------------------------------
+
+  def next (self):
+
     if self.done:
+      # Make sure to raise StopIteration on subsequent calls to next ()
       raise StopIteration
+
     elif self.new:
-      self.block.jumpRecord(0)
+      self.block.jumpRecord (0)
       self.new = False
-    elif self.block._resultSet.isLastRecord():
+
+    elif self.block._resultSet.isLastRecord ():
       self.done = True
       raise StopIteration
+
     else:
-      self.block.nextRecord()
+      self.block.nextRecord ()
 
-    if self.block.isEmpty() and self.block._resultSet.isLastRecord():
+    if self.block.isEmpty () and self.block._resultSet.isLastRecord ():
       self.done = True
       raise StopIteration
 
     return self.block
-

Modified: trunk/gnue-forms/src/GFObjects/GFScrollBar.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFScrollBar.py       2006-04-04 08:24:06 UTC 
(rev 8351)
+++ trunk/gnue-forms/src/GFObjects/GFScrollBar.py       2006-04-04 08:25:01 UTC 
(rev 8352)
@@ -106,7 +106,7 @@
     @param delta: number of records to be moved (can be negative)
     """
 
-    self._block.scrollRecords (delta)
+    self._block._event_scroll_delta (delta)
 
 
   # ---------------------------------------------------------------------------
@@ -119,4 +119,4 @@
     @param recordNumber: number of record to jump to.
     """
 
-    self._block.scrollToRecord (recordNumber)
+    self._block._event_scroll_to_record (recordNumber)





reply via email to

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