/[papo]/gnue/reports/src/GRLayout.py
ViewVC logotype

Diff of /gnue/reports/src/GRLayout.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by charlie, Tue Aug 27 18:15:54 2002 UTC revision 1.4 by styxman, Thu Nov 14 23:02:37 2002 UTC
# Line 30  Line 30 
30    
31  from gnue.common.GObjects import *  from gnue.common.GObjects import *
32  from gnue.common import GDebug, GConditions  from gnue.common import GDebug, GConditions
33    from gnue.common.GTrigger import GTrigger,GTriggerExtension
34    
35  from GRParameters import GRStubParam  from GRParameters import GRStubParam
36  import GRExceptions  import GRExceptions
37  import string  import string
# Line 53  structuralComment = _noStructuralComment Line 55  structuralComment = _noStructuralComment
55    
56  ############################################################  ############################################################
57  #  #
58    # GRLayout
59  #  #
60  class GRLayout (GObj):  class GRLayout (GObj):
61    def __init__(self, parent):    def __init__(self, parent):
# Line 60  class GRLayout (GObj): Line 63  class GRLayout (GObj):
63      self._inits = (self.initialize,)      self._inits = (self.initialize,)
64    
65    
66    def _buildObject(self):    def initialize(self):
67        # Find the xml namespace in use by any child passthru objects
68      # If there is more than one object attached to a layout      # If there is more than one object attached to a layout
69      # object, then create an unbound section to contain them.      # object, then create an unbound section to contain them.
70      # This is a convenience for the layout engine code :)      # This is a convenience for the layout engine code :)
# Line 78  class GRLayout (GObj): Line 82  class GRLayout (GObj):
82        raise GRExceptions.NoLayoutDefined, \        raise GRExceptions.NoLayoutDefined, \
83          "The layout section does not contain any instructions. What do I do?"          "The layout section does not contain any instructions. What do I do?"
84    
     return GObj._buildObject(self)  
   
   def initialize(self):  
     # Find the xml namespace in use by any child passthru objects  
85      self._xmlchildnamespace = self._findNamespace(self)      self._xmlchildnamespace = self._findNamespace(self)
86      self._parent._namespace = self._xmlchildnamespace      self._parent._namespace = self._xmlchildnamespace
87    
# Line 152  class GRLayout (GObj): Line 152  class GRLayout (GObj):
152              if curr._name == sec:              if curr._name == sec:
153                section = curr                section = curr
154                break                break
155              curr = s._parent.findParentOfType('GRSection')              curr = curr._parent.findParentOfType('GRSection')
156    
157            if section == None:            if section == None:
158              raise GRExceptions.SourceOutOfScope, \              raise GRExceptions.SourceOutOfScope, \
# Line 169  class GRLayout (GObj): Line 169  class GRLayout (GObj):
169    
170        elif isinstance(object, GRSumm):        elif isinstance(object, GRSumm):
171          if object.section == None:          if object.section == None:
172            s = object._parent.findObjectOfType('GRSection')            s = object._parent.findParentOfType('GRSection')
173          else:          else:
174            sec = string.lower(object.section)            sec = string.lower(object.section)
175            s = self._mapper.sectionMap[sec]._object            s = self._mapper.sectionMap[sec]._object
# Line 198  class GRLayout (GObj): Line 198  class GRLayout (GObj):
198        structuralComment = _structuralComment        structuralComment = _structuralComment
199    
200      for child in self._children:      for child in self._children:
201        structuralComment(dest, '<!--[layout]-->')        structuralComment(dest, '<!-- [layout] -->')
202        child.processAsController(dest, self._mapper)        child.processAsController(dest, self._mapper)
203        structuralComment(dest, '<!--[/layout]-->\n')        structuralComment(dest, '<!-- [/layout] -->\n')
204    
205    
206    
# Line 210  class GRLayout (GObj): Line 210  class GRLayout (GObj):
210  # Any elements contained within a <layout> element  # Any elements contained within a <layout> element
211  # inherit GRLayoutElement  # inherit GRLayoutElement
212  #  #
213  class GRLayoutElement (GObj):  class GRLayoutElement (GObj,GTriggerExtension):
214    def __init__(self, parent=None, type='GRLayoutElement'):    def __init__(self, parent=None, type='GRLayoutElement'):
215        GTriggerExtension.__init__(self)
216      GObj.__init__(self, parent, type=type)      GObj.__init__(self, parent, type=type)
217      self.name = None      self.name = None
218      self._source = None      self._source = None
# Line 251  class ContainerElement (GRLayoutElement) Line 252  class ContainerElement (GRLayoutElement)
252      first = isfirst or self._type == 'GRSection'      first = isfirst or self._type == 'GRSection'
253    
254      while 1:      while 1:
255          if isinstance(self, GRSection) :
256            self.processTrigger('On-Process')
257            
258        for child in self._children:        for child in self._children:
259          if child._type == "_content_":          if child._type == "_content_":
260            dest.write(child.getContent())            dest.write(child.getContent())
# Line 258  class ContainerElement (GRLayoutElement) Line 262  class ContainerElement (GRLayoutElement)
262            # Handle GRSections specially as            # Handle GRSections specially as
263            # they require extra logic            # they require extra logic
264            if isinstance(child, GRSection):            if isinstance(child, GRSection):
   
265              # If this is the top-most section for a datasource,              # If this is the top-most section for a datasource,
266              # it needs to be called with processAsController.              # it needs to be called with processAsController.
267              if child._mymapper.toplevel:              if child._mymapper.toplevel:
               GDebug.printMesg(10, "Calling new controlling section")  
268    
269                  GDebug.printMesg(10, "Calling new controlling section")
270                child.processAsController(dest, mapper)                child.processAsController(dest, mapper)
271    
272              # ..otherwise call the GRSection's process method.              # ..otherwise call the GRSection's process method.
# Line 274  class ContainerElement (GRLayoutElement) Line 277  class ContainerElement (GRLayoutElement)
277                      (nextSection._name not in (child._childSections)),                      (nextSection._name not in (child._childSections)),
278                   firstSection=firstSection,                   firstSection=firstSection,
279                   nextSection=nextSection)                   nextSection=nextSection)
280              # Don't allow the processing to enter trigger objects
281              elif isinstance(child, GTrigger):
282                pass
283            else:            else:
284              # Handle the layout element.              # Handle the layout element.
285              nextSection = child.process(dest, mapper, first, islast,              nextSection = child.process(dest, mapper, first, islast,
# Line 311  class GRSection (ContainerElement): Line 316  class GRSection (ContainerElement):
316    def __init__(self, parent):    def __init__(self, parent):
317      ContainerElement.__init__(self, parent, 'GRSection')      ContainerElement.__init__(self, parent, 'GRSection')
318      self._childSections = []      self._childSections = []
319        self._validTriggers = {'PRE-SECTION':'Pre-Section',
320                               'POST-SECTION':'Post-Section',
321                               'ON-PROCESS':'On-Process'}
322    
323    def _buildObject(self):    def _buildObject(self):
324      if not hasattr(self,'name') or self.name == None:      if not hasattr(self,'name') or self.name == None:
# Line 360  class GRSection (ContainerElement): Line 368  class GRSection (ContainerElement):
368              c2.processDefault(dest, mapper)              c2.processDefault(dest, mapper)
369    
370    
371    
372    #    #
373    # Used internally to determine next section to move    # Used internally to determine next section to move
374    #    #
# Line 400  class GRSection (ContainerElement): Line 409  class GRSection (ContainerElement):
409    # Generic process() method.  Process the    # Generic process() method.  Process the
410    # current record and handle any children.    # current record and handle any children.
411    def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):    def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
412        self.processTrigger('Pre-Section')
413      GDebug.printMesg(10,"Repeating Section %s" % self._name)      GDebug.printMesg(10,"Repeating Section %s" % self._name)
414      structuralComment(dest,"<!--[section:%s]-->" % self._name)      structuralComment(dest,"<!-- [section:%s] -->" % self._name)
415      nextSection = self.processChildren(dest, mapper, isfirst, islast, firstSection, nextSection)      nextSection = self.processChildren(dest, mapper, isfirst, islast, firstSection, nextSection)
416      structuralComment(dest,"<!--[/section:%s]-->" % self._name)  
417        try:
418    
419          structuralComment(dest,"<!-- [Setting %s to clear on next set] -->" % self._name)
420          mapper.sectionMap[self.name]._clearOnNextSet = 1
421        except KeyError:
422          pass
423    
424        structuralComment(dest,"<!-- [/section:%s] -->" % self._name)
425      GDebug.printMesg(10,"Leaving section %s" % self._name)      GDebug.printMesg(10,"Leaving section %s" % self._name)
426        self.processTrigger('Post-Section')
427      return nextSection      return nextSection
428    
429    
# Line 424  class GRDefault (GObj): Line 442  class GRDefault (GObj):
442      self._mymapper = None      self._mymapper = None
443    
444    def processDefault(self, dest, mapper):    def processDefault(self, dest, mapper):
445      structuralComment(dest,"<!--[default]-->")      structuralComment(dest,"<!-- [default] -->")
446      for child in self._children:      for child in self._children:
447        if child._type == "_content_":        if child._type == "_content_":
448          dest.write(child.getContent())          dest.write(child.getContent())
449      structuralComment(dest,"<!--[/default]-->")      structuralComment(dest,"<!-- [/default] -->")
450    
451    def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):    def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
452      return nextSection      return nextSection
# Line 446  class GRField (GRLayoutElement): Line 464  class GRField (GRLayoutElement):
464      self.format = None      self.format = None
465    
466    def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):    def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
467      structuralComment(dest,"<!--[field:%s]-->" % self.name)      structuralComment(dest,"<!-- [field:%s] -->" % self.name)
468      dest.write (string.replace(saxutils.escape("%s" % self._mymapper.getField(self.name,      dest.write (string.replace(saxutils.escape("%s" % self._mymapper.getField(self.name,
469                                                self.format)), '\r',''))                                                self.format)), '\r',''))
470      structuralComment(dest,"<!--[/field:%s]-->" % self.name)      structuralComment(dest,"<!-- [/field:%s] -->" % self.name)
471      return nextSection      return nextSection
472    
473    
# Line 475  class GRSumm (GRLayoutElement): Line 493  class GRSumm (GRLayoutElement):
493      return GRLayoutElement._buildObject(self)      return GRLayoutElement._buildObject(self)
494    
495    def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):    def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
496      structuralComment(dest,"<!--[summ:%s]-->" % self.name)      structuralComment(dest,"<!-- [summ:%s:%s:%s] -->" % (self.section, self._field, self.function))
497      dest.write (self._mymapper.getSummary(self._field, self.function, self.format))      dest.write (self._mymapper.getSummary(self._field, self.function, self.format))
498      structuralComment(dest,"<!--[/summ:%s]-->" % self.name)      structuralComment(dest,"<!-- [/summ] -->")
499      return nextSection      return nextSection
500    
501    
# Line 497  class GRParam(GRLayoutElement, GRStubPar Line 515  class GRParam(GRLayoutElement, GRStubPar
515      GRStubParam.__init__(self, parent)      GRStubParam.__init__(self, parent)
516    
517    def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):    def process(self, dest, mapper, isfirst, islast, firstSection, nextSection):
518      structuralComment(dest,"<!--[param:%s]-->" % self.name)      structuralComment(dest,"<!-- [param:%s] -->" % self.name)
519      dest.write (self.getFormattedValue())      dest.write (self.getFormattedValue())
520      structuralComment(dest,"<!--[/param:%s]-->" % self.name)      structuralComment(dest,"<!-- [/param:%s] -->" % self.name)
521      return nextSection      return nextSection
522    
523    

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26