[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8907 - trunk/gnue-forms/src/GFObjects
From: |
reinhard |
Subject: |
[gnue] r8907 - trunk/gnue-forms/src/GFObjects |
Date: |
Mon, 23 Oct 2006 08:37:53 -0500 (CDT) |
Author: reinhard
Date: 2006-10-23 08:37:52 -0500 (Mon, 23 Oct 2006)
New Revision: 8907
Modified:
trunk/gnue-forms/src/GFObjects/GFBlock.py
Log:
More code reformatting.
Modified: trunk/gnue-forms/src/GFObjects/GFBlock.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFBlock.py 2006-10-23 13:27:04 UTC (rev
8906)
+++ trunk/gnue-forms/src/GFObjects/GFBlock.py 2006-10-23 13:37:52 UTC (rev
8907)
@@ -20,40 +20,47 @@
# - Suite 330, Boston, MA 02111-1307, USA.
#
# $Id$
+
"""
-Classes making up the Block object
+Classes making up the Block object.
"""
-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 gnue.common.definitions import GParser
from gnue.common import events
-from gnue.common.definitions import GParser
+from gnue.forms.GFObjects.GFContainer import GFContainer
+from gnue.forms.GFObjects.GFDataSource import GFDataSource
+
+__all__ = ['GFBlock', 'DatasourceNotFoundError', 'InvalidEditableError']
+
+
# =============================================================================
# Exceptions
# =============================================================================
-class DatasourceNotFoundError (GParser.MarkupError):
- def __init__ (self, source, block):
- msg = u_("Datasource '%(datasource)s' in block '%(block)s' not found") \
- % {'datasource': source, 'block': block.name}
- GParser.MarkupError.__init__ (self, msg, block._url, block._lineNumber)
+class DatasourceNotFoundError(GParser.MarkupError):
+ def __init__(self, source, block):
+ msg = u_("Datasource '%(datasource)s' in block '%(block)s' not found")
\
+ % {'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)
+# =============================================================================
+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)
+
+
# =============================================================================
# <block>
# =============================================================================
-class GFBlock (GFContainer, events.EventAware):
+class GFBlock(GFContainer, events.EventAware):
"""
Class that represents the <block> tag in a gfd file.
"""
@@ -64,7 +71,7 @@
def __init__(self, parent=None):
- GFContainer.__init__ (self, parent, 'GFBlock')
+ GFContainer.__init__(self, parent, 'GFBlock')
self.mode = 'normal'
@@ -149,62 +156,62 @@
# Object construction from xml
# -------------------------------------------------------------------------
- def _buildObject (self):
+ def _buildObject(self):
- self._rows = getattr (self, 'rows', self._rows)
- self._gap = getattr (self, 'rowSpacer', self._gap)
+ self._rows = getattr(self, 'rows', self._rows)
+ self._gap = getattr(self, 'rowSpacer', self._gap)
- if hasattr (self, 'restrictDelete') and self.restrictDelete:
+ if hasattr(self, 'restrictDelete') and self.restrictDelete:
self.deletable = False
- del self.__dict__ ['restrictDelete']
+ del self.__dict__['restrictDelete']
- if hasattr (self, 'restrictInsert') and self.restrictInsert:
+ if hasattr(self, 'restrictInsert') and self.restrictInsert:
self.editable = 'update'
- del self.__dict__ ['restrictInsert']
+ del self.__dict__['restrictInsert']
- if hasattr (self,'datasource'):
- self.datasource = self.datasource.lower ()
+ if hasattr(self,'datasource'):
+ self.datasource = self.datasource.lower()
- return GFContainer._buildObject (self)
+ return GFContainer._buildObject(self)
# -------------------------------------------------------------------------
# Implementation of virtual methods
# -------------------------------------------------------------------------
- def _phase_1_init_ (self):
+ def _phase_1_init_(self):
- GFContainer._phase_1_init_ (self)
+ GFContainer._phase_1_init_(self)
self._convertAsterisksToPercent = gConfigForms('AsteriskWildcard')
- self._logic = logic = self.findParentOfType ('GFLogic')
+ self._logic = logic = self.findParentOfType('GFLogic')
self._lastValues = {}
- logic._blockList.append (self)
- logic._blockMap [self.name] = self
+ logic._blockList.append(self)
+ logic._blockMap[self.name] = self
# Initialize our events system
- events.EventAware.__init__ (self, self._form._instance.eventController)
+ events.EventAware.__init__(self, self._form._instance.eventController)
# Create a stub/non-bound datasource if we aren't bound to one
- if not hasattr (self, 'datasource') or not self.datasource:
- ds = GFDataSource (self._form)
+ if not hasattr(self, 'datasource') or not self.datasource:
+ ds = GFDataSource(self._form)
ds.type = 'unbound'
- self.datasource = ds.name = "__dts_%s" % id (self)
- self._form._datasourceDictionary [ds.name] = ds
- ds._buildObject ()
- ds.phaseInit ()
+ self.datasource = ds.name = "__dts_%s" % id(self)
+ self._form._datasourceDictionary[ds.name] = ds
+ ds._buildObject()
+ ds.phaseInit()
dsDict = self._form._datasourceDictionary
- self._dataSourceLink = dsDict.get (self.datasource)
+ self._dataSourceLink = dsDict.get(self.datasource)
if self._dataSourceLink is None:
- raise DatasourceNotFoundError, (self.datasource, self)
+ raise DatasourceNotFoundError,(self.datasource, self)
# Register event handling functions
- self._dataSourceLink.registerEventListeners ({
+ self._dataSourceLink.registerEventListeners({
'dsResultSetActivated': self.__dsResultSetActivated,
'dsResultSetChanged' : self.__dsResultSetActivated, # sic!
'dsCursorMoved' : self.__dsCursorMoved,
@@ -216,40 +223,40 @@
'dsCommitDelete' : self.__dsCommitDelete})
# Get min and max child rows, if applicable
- self._minChildRows = getattr (self._dataSourceLink, 'detailmin', 0)
- self._maxChildRows = getattr (self._dataSourceLink, 'detailmax', None)
+ self._minChildRows = getattr(self._dataSourceLink, 'detailmin', 0)
+ self._maxChildRows = getattr(self._dataSourceLink, 'detailmax', None)
- self.walk (self.__setChildRowSettings)
+ self.walk(self.__setChildRowSettings)
# -------------------------------------------------------------------------
- def __setChildRowSettings (self, child):
+ def __setChildRowSettings(self, child):
# If a child has no rows- or rowSpacer-attribute copy the blocks values
# to the child
- child._rows = getattr (child, 'rows', self._rows)
- child._gap = getattr (child, 'rowSpacer', self._gap)
+ child._rows = getattr(child, 'rows', self._rows)
+ child._gap = getattr(child, 'rowSpacer', self._gap)
# -------------------------------------------------------------------------
# Get an ordered list of focus-controls
# -------------------------------------------------------------------------
- def get_focus_order (self):
+ def get_focus_order(self):
ctrlList = []
for field in self._children:
- ctrlList += getattr (field, '_entryList', [])
+ ctrlList += getattr(field, '_entryList', [])
- return GFContainer.get_focus_order (self, ctrlList)
+ return GFContainer.get_focus_order(self, ctrlList)
# -------------------------------------------------------------------------
# Register a scrollbar widget
# -------------------------------------------------------------------------
- def register_scrollbar (self, widget):
+ def register_scrollbar(self, widget):
"""
Register a given scrollbar widget to the block. This widget will be
notified on record movement. It has to implement a method
@@ -257,14 +264,14 @@
as arguments.
"""
- self.__scrollbars.append (widget)
+ self.__scrollbars.append(widget)
# -------------------------------------------------------------------------
# Event handling functions for datasource events
# -------------------------------------------------------------------------
- def __dsResultSetActivated (self, event):
+ def __dsResultSetActivated(self, event):
# FIXME: If an exception appears here, we have a problem: it is
probably
# too late to cancel the operation.
@@ -276,11 +283,11 @@
# 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 ()
+ recno = self._resultSet.getRecordNumber()
if recno == -1:
self.__scrolling_blocked = True
try:
- if not self._resultSet.firstRecord ():
+ if not self._resultSet.firstRecord():
self._resultSet.insertRecord(self._lastValues)
finally:
self.__scrolling_blocked = False
@@ -292,72 +299,72 @@
# -------------------------------------------------------------------------
- def __dsCursorMoved (self, event):
+ def __dsCursorMoved(self, event):
if self.__scrolling_blocked:
return
# Blocks can't cope with current record #-1
- recno = self._resultSet.getRecordNumber ()
+ recno = self._resultSet.getRecordNumber()
if recno != -1:
self.__current_record_changed(False)
# -------------------------------------------------------------------------
- def __dsRecordInserted (self, event):
+ def __dsRecordInserted(self, event):
self._initializingRecord = event.record
oldmode = self.mode
self.mode = 'init'
- self.processTrigger ('ON-NEWRECORD')
+ self.processTrigger('ON-NEWRECORD')
self.mode = oldmode
# -------------------------------------------------------------------------
- def __dsRecordLoaded (self, event):
+ def __dsRecordLoaded(self, event):
self._initializingRecord = event.record
oldmode = self.mode
self.mode = 'init'
- self.processTrigger ('ON-RECORDLOADED')
+ self.processTrigger('ON-RECORDLOADED')
self.mode = oldmode
# -------------------------------------------------------------------------
- def __dsRecordTouched (self, event):
+ def __dsRecordTouched(self, event):
# This already gets called by GFField??
- # self.__fireRecordTrigger ('PRE-CHANGE')
+ # self.__fireRecordTrigger('PRE-CHANGE')
pass
# -------------------------------------------------------------------------
- def __dsCommitInsert (self, event):
- self.__fireRecordTrigger ('PRE-INSERT')
- self.__fireRecordTrigger ('PRE-COMMIT')
+ def __dsCommitInsert(self, event):
+ self.__fireRecordTrigger('PRE-INSERT')
+ self.__fireRecordTrigger('PRE-COMMIT')
# -------------------------------------------------------------------------
- def __dsCommitUpdate (self, event):
- self.__fireRecordTrigger ('PRE-UPDATE')
- self.__fireRecordTrigger ('PRE-COMMIT')
+ def __dsCommitUpdate(self, event):
+ self.__fireRecordTrigger('PRE-UPDATE')
+ self.__fireRecordTrigger('PRE-COMMIT')
# -------------------------------------------------------------------------
- def __dsCommitDelete (self, event):
- self.__fireRecordTrigger ('PRE-DELETE')
- self.__fireRecordTrigger ('PRE-COMMIT')
+ def __dsCommitDelete(self, event):
+ self.__fireRecordTrigger('PRE-DELETE')
+ self.__fireRecordTrigger('PRE-COMMIT')
# -------------------------------------------------------------------------
- def __fireRecordTrigger (self, trigger):
- self.processTrigger (trigger)
+ def __fireRecordTrigger(self, trigger):
+ self.processTrigger(trigger)
for field in self._fieldList:
- field.processTrigger (trigger)
+ field.processTrigger(trigger)
# -------------------------------------------------------------------------
- # Event handlers for UI events (scrollbar or mouse wheel)
+ # Event handlers for UI events(scrollbar or mouse wheel)
# -------------------------------------------------------------------------
- def _event_rows_changed (self, new_rows):
+ def _event_rows_changed(self, new_rows):
"""
Notify the block that the number of rows displayed has changed.
@@ -375,7 +382,7 @@
# -------------------------------------------------------------------------
- def _event_scroll_delta (self, adjustment):
+ def _event_scroll_delta(self, adjustment):
"""
Scroll the given number of records.
@@ -383,11 +390,11 @@
record.
"""
- self._event_scroll_to_record (self.__visibleStart + adjustment)
+ self._event_scroll_to_record(self.__visibleStart + adjustment)
# -------------------------------------------------------------------------
- def _event_scroll_to_record (self, position):
+ def _event_scroll_to_record(self, position):
"""
Scrolls the block to the given position.
@@ -619,7 +626,7 @@
# -------------------------------------------------------------------------
- def is_first_record (self):
+ def is_first_record(self):
"""
Returns True if the current record is the first one in the ResultSet
"""
@@ -628,12 +635,12 @@
# -------------------------------------------------------------------------
- def is_last_record (self):
+ def is_last_record(self):
"""
Returns True if the current record is the last one in the ResultSet.
"""
- return self._resultSet.isLastRecord ()
+ return self._resultSet.isLastRecord()
# -------------------------------------------------------------------------
@@ -696,7 +703,7 @@
if self._resultSet.isLastRecord():
if self.autoCreate and not self.is_empty() and \
- not self.editable in ('update', 'N'):
+ not self.editable in('update', 'N'):
self.new_record()
return
@@ -884,61 +891,61 @@
def execute_query(self):
# Set the maxList to a single master block as a placeholder.
- maxList = [self._getTopMasterBlock ()]
+ maxList = [self._getTopMasterBlock()]
# 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.__query_values.keys ():
+ if block.__query_values.keys():
templist = [block]
- while (templist [-1])._getMasterBlock ():
- templist.append ((templist [-1])._getMasterBlock ())
+ while (templist[-1])._getMasterBlock():
+ templist.append((templist[-1])._getMasterBlock())
- if len (maxList) < len (templist):
+ if len(maxList) < len(templist):
maxList = templist
# Store block states
for block in self._logic._blockList:
block.__last_query_values = {}
- block.__last_query_values.update (block.__query_values)
+ block.__last_query_values.update(block.__query_values)
# graft in the sloppy query stuff if needed
for block in maxList:
for entry in block._entryList:
if entry._type == 'GFEntry' and \
- hasattr (entry._field, 'sloppyQuery') and \
- block.__query_values.has_key (entry._field):
- block.__query_values [entry._field] = "%" + "%".join(
- list (block.__query_values [entry._field])) + "%"
+ hasattr(entry._field, 'sloppyQuery') and \
+ block.__query_values.has_key(entry._field):
+ block.__query_values[entry._field] = "%" + "%".join(
+ list(block.__query_values[entry._field])) + "%"
# Find root block
- rootBlock = maxList [-1]
+ rootBlock = maxList[-1]
# Condition for the master block
- conditions = rootBlock._generateConditional ()
+ conditions = rootBlock._generateConditional()
# 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 = block._generateConditional ()
- exist = GConditions.GCexist ()
+ c = block._generateConditional()
+ 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)
+ conditions = GConditions.combineConditions(conditions, exist)
- rootBlock._dataSourceLink.createResultSet (conditions)
+ rootBlock._dataSourceLink.createResultSet(conditions)
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')
block.cancel_query()
@@ -951,7 +958,7 @@
Post all pending changes of the block
"""
- assert gDebug (4, "processing commit on block %s" % self.name, 1)
+ assert gDebug(4, "processing commit on block %s" % self.name, 1)
self.mode = 'commit'
@@ -1001,33 +1008,33 @@
# Function and Update
# -------------------------------------------------------------------------
- def callFunction (self, name, parameters):
+ def callFunction(self, name, parameters):
# Remember the current record; the record pointer is not reliable
# between postAll and requeryAll!
current = self._resultSet.current
- self._dataSourceLink.postAll ()
+ self._dataSourceLink.postAll()
try:
- res = current.call (name, parameters)
+ res = current.call(name, parameters)
finally:
- self._dataSourceLink.requeryAll (False)
+ self._dataSourceLink.requeryAll(False)
return res
# -------------------------------------------------------------------------
- def updateCurrentRecordSet (self):
+ def updateCurrentRecordSet(self):
- self._dataSourceLink.postAll ()
- self._dataSourceLink.requeryAll (False)
+ self._dataSourceLink.postAll()
+ self._dataSourceLink.requeryAll(False)
# -------------------------------------------------------------------------
# Raw data access
# -------------------------------------------------------------------------
- def getResultSet (self):
+ def getResultSet(self):
"""
Return the current ResultSet of the block.
"""
@@ -1162,14 +1169,14 @@
# Switch the proper record into editing position
# -------------------------------------------------------------------------
- def __switch_record (self, new_visible_start, refresh_all):
+ def __switch_record(self, new_visible_start, refresh_all):
if self.mode == 'query':
newRecord = 0
newRecordCount = 1
else:
- newRecord = self._resultSet.getRecordNumber ()
- newRecordCount = self._resultSet.getRecordCount ()
+ newRecord = self._resultSet.getRecordNumber()
+ newRecordCount = self._resultSet.getRecordCount()
adjustment = newRecord - self._currentRecord
@@ -1197,7 +1204,7 @@
self._recordCount = newRecordCount
for entry in self._entryList:
- entry.recalculate_visible (adjustment, self._currentRecord,
+ entry.recalculate_visible(adjustment, self._currentRecord,
self._recordCount, refresh)
self.__adjust_scrollbars()
@@ -1250,21 +1257,21 @@
def __adjust_scrollbars(self):
for sb in self.__scrollbars:
- sb.adjust_scrollbar (self.__visibleStart,
- max (self._recordCount, self.__visibleStart + self._rows))
+ sb.adjust_scrollbar(self.__visibleStart,
+ max(self._recordCount, self.__visibleStart + self._rows))
# -------------------------------------------------------------------------
# Return the top level master block of this block
# -------------------------------------------------------------------------
- def _getTopMasterBlock (self):
+ def _getTopMasterBlock(self):
result = self
- master = result._getMasterBlock ()
+ master = result._getMasterBlock()
while master is not None:
result = master
- master = result._getMasterBlock ()
+ master = result._getMasterBlock()
return result
@@ -1272,10 +1279,10 @@
# Return the master block of this block
# -------------------------------------------------------------------------
- def _getMasterBlock (self):
+ def _getMasterBlock(self):
- if self._dataSourceLink.hasMaster ():
- ds = self._dataSourceLink.getMaster ()
+ if self._dataSourceLink.hasMaster():
+ ds = self._dataSourceLink.getMaster()
for block in self._logic._blockList:
if block._dataSourceLink == ds:
return block
@@ -1290,7 +1297,7 @@
# Create a condition tree
# -------------------------------------------------------------------------
- def _generateConditional (self):
+ def _generateConditional(self):
"""
Create a condition tree based upon the values currently stored in the
form.
@@ -1316,8 +1323,8 @@
condEq = {}
conditions = []
# Get all the user-supplied parameters from the entry widgets
- for entry, val in self.__query_values.items ():
- if entry._bound and entry.isQueryable () and len (("%s" % val)):
+ for entry, val in self.__query_values.items():
+ if entry._bound and entry.isQueryable() and len(("%s" % val)):
# New : operator support
match = False
@@ -1358,18 +1365,18 @@
if entry.typecast == 'text':
if self._convertAsterisksToPercent:
try:
- val = ("%s" % val).replace ('*', '%')
+ val = ("%s" % val).replace('*', '%')
except ValueError:
pass
val = cond_value(val)
- if (val.find ('%') >= 0 or val.find ('_') >= 0):
- condLike [entry] = val
+ if (val.find('%') >= 0 or val.find('_') >= 0):
+ condLike[entry] = val
else:
- condEq [entry] = val
+ condEq[entry] = val
else:
- condEq [entry] = val
+ condEq[entry] = val
epf = []
for (entry, value) in condEq.items():
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8907 - trunk/gnue-forms/src/GFObjects,
reinhard <=