dabo Commit
Revision 5186
Date: 2009-04-21 14:40:18 -0700 (Tue, 21 Apr 2009)
Author: Paul
Trac: http://trac.dabodev.com/changeset/5186

Changed:
U   branches/paul_reporting/dabo/lib/reportWriter.py

Log:
This is getting closer. At least the detail bands don't overlap, but there's too
much space (and unneeded page breaks) after some long paragraphs.



Diff:
Modified: branches/paul_reporting/dabo/lib/reportWriter.py
===================================================================
--- branches/paul_reporting/dabo/lib/reportWriter.py    2009-04-21 03:18:04 UTC 
(rev 5185)
+++ branches/paul_reporting/dabo/lib/reportWriter.py    2009-04-21 21:40:18 UTC 
(rev 5186)
@@ -462,11 +462,18 @@
        def initAvailableProps(self):
                super(Band, self).initAvailableProps()
                self.AvailableProps["Height"] = toPropDict(float, 0.0, 
-                               """Specifies the height of the band.
+                               """Specifies the height of the band, not 
including growable objects.
 
                                If the height evaluates to None, the height of 
the band will size
                                itself dynamically at runtime.""")
 
+               self.AvailableProps["TotalHeight"] = toPropDict(float, 0.0, 
+                               """Specifies the height of the band, including 
growable objects.
+
+                               Read-only/calculated at runtime. Specifies the 
height of the band
+                               on the page, and gets reevaluated for each page 
the band continues
+                               printing on.""")
+
                self.AvailableProps["DesignerLock"] = toPropDict(bool, False, 
                                """Specifies whether the band height can be 
changed interactively.
 
@@ -843,7 +850,7 @@
                        x = x - (width / 2)
        
                if objType != "Frameset":       
-                       height = self.getObjectHeight(obj)
+                       height = self.getPt(obj.getProp("Height"))
                        if vAnchor == "top":
                                y = y - height
                        elif vAnchor == "middle":
@@ -1286,8 +1293,6 @@
                        neededHeight = objNeededHeight + padTop + padBottom
                return story, neededHeight
 
-       def getNeededHeight(self, obj):
-               return self.getStory(obj)[1]
 
        def getColorTupleFromReportLab(self, val):
                """Given a color tuple in reportlab format (values between 0 
and 1), return
@@ -1480,22 +1485,32 @@
 
                        self.ReportForm.Bands[band] = CaselessDict()
 
-                       fixedBandHeight = self.getBandHeight(bandDict, 
onlyFixedObjects=True)
-                       # Band height accounting also for objects that grow 
downward:
                        bandHeight = self.getBandHeight(bandDict)
+                       print "bandHeight:", bandHeight
 
                        width = pageWidth - ml - mr
-                       y -= fixedBandHeight
 
-                       # Non-detail band special cases:
-                       if band == "pageHeader":
-                               x,y = pageHeaderOrigin
-                       elif band == "pageFooter":
-                               x,y = pageFooterOrigin
-                       elif band in ("pageBackground", "pageForeground"):
-                               x,y = 0,1
-                               width, height = pageWidth-1, pageHeight-1
+                       def getTotalBandHeight():
+                               maxBandHeight = bandHeight
+                               if deferred:
+                                       for obj, obj_deferred, neededHeight in 
deferred:
+                                               needed = neededHeight
+                                               maxBandHeight = 
max(maxBandHeight, neededHeight)
+                               else:
+                                       for obj in bandDict.get("Objects", []):
+                                               if obj.getProp("Height") is 
None:
+                                                       needed = 
self.getStory(obj)[1] + bandHeight - self.getPt(obj.getProp("y"))
+                                                       maxBandHeight = 
max(maxBandHeight, needed)
+                               availableHeight = y - (pageFooterOrigin[1] + 
pfHeight)
+                               if maxBandHeight > availableHeight:
+                                       maxBandHeight = availableHeight
+                               return maxBandHeight
 
+                       maxBandHeight = getTotalBandHeight()
+                       if not deferred:
+                               y -= bandHeight
+
+
                        if band in ("groupHeader", "groupFooter", "detail"):
                                extraHeight = 0
                                if band == "groupHeader":
@@ -1509,7 +1524,7 @@
                                check = pageFooterOrigin[1] + pfHeight + 
extraHeight
                                if bandDict.getProp("height") is not None:
                                        # band height is fixed, won't flow to 
next page. 
-                                       check += fixedBandHeight
+                                       check += bandHeight
 
                                if y < check:
                                        if self._currentColumn >= columnCount-1:
@@ -1518,17 +1533,32 @@
                                        else:
                                                self._currentColumn += 1
                                        y = pageHeaderOrigin[1]
+                                       maxBandHeight = getTotalBandHeight()
                                        if band == "detail":
                                                y = reprintGroupHeaders(y)
-                                       y -= fixedBandHeight
+                                       if not deferred:
+                                               y -= bandHeight
                                
+                       if band == "detail":
+                               print "maxBandHeight, deferred:", 
maxBandHeight, bool(deferred)
+
+                       # Non-detail band special cases:
+                       if band == "pageHeader":
+                               x,y = pageHeaderOrigin
+                       elif band == "pageFooter":
+                               x,y = pageFooterOrigin
+                       elif band in ("pageBackground", "pageForeground"):
+                               x,y = 0,1
+                               width, height = pageWidth-1, pageHeight-1
+
                        x = ml + (self._currentColumn * columnWidth)
                                
                        self.ReportForm.Bands[band]["x"] = x
                        self.ReportForm.Bands[band]["y"] = y
                        self.ReportForm.Bands[band]["Width"] = width
                        self.ReportForm.Bands[band]["Height"] = bandHeight
-       
+                       self.ReportForm.Bands[band]["TotalHeight"] = 
maxBandHeight      
+
                        if self.ShowBandOutlines:
                                self.printBandOutline("%s (record %s)" % (band, 
self.RecordNumber), 
                                                x, y, width, bandHeight)
@@ -1576,21 +1606,10 @@
                                new_obj_deferred, neededHeight = self.draw(obj, 
(x1, y1),       availableHeight=availableHeight,
                                                deferred=obj_deferred)
 
-                               #if new_obj_deferred:
-                                       #print new_obj_deferred
-                                       #1/0
-                               #if used_height == 0:
-                               #       new_obj_deferred = None
-
-                               #used_height += alreadyUsedHeight
                                if bandDict.getProp("height") is not None:
                                        # Band height is fixed; cancel any 
deferrals.
                                        new_obj_deferred = None
 
-                               #if used_height >= bandHeight:
-                               #       # no more room in the band for this 
object.
-                               #       new_obj_deferred = None
-
                                if new_obj_deferred:
                                        if obj_deferred:
                                                # was already deferred, and now 
deferred again. WARNING: if para longer 
@@ -1612,9 +1631,9 @@
 
                        if deferred:
                                # the deferred objs will print on the next 
page. RECURSE WARNING.
-                               printBand(band=band, y=-1, group=group, 
deferred=deferred)
-                               print "deferred"
-                       print y
+                               dy = printBand(band=band, y=-1, group=group, 
deferred=deferred)
+                       y -= (maxBandHeight-bandHeight) 
+                       print y, maxBandHeight, bandHeight      
                        return y
 
 
@@ -1697,9 +1716,10 @@
                                        y = printBand("groupHeader", y, group)
 
 
+                       print "printing detail...", self.PageNumber, 
self.RecordNumber, y
                        # print the detail band:
                        y = printBand("detail", y)
-
+                       print "...done printing detail", self.PageNumber, 
self.RecordNumber, y
                        self._recordNumber += 1
 
 
@@ -1715,57 +1735,34 @@
                        self._canvas = None
 
 
-       def getBandHeight(self, bandDict, onlyFixedObjects=False):
+       def getBandHeight(self, bandDict):
                """Return the height of the band.
 
                If the band's Height property is None, the height will be
                calculated based on the objects in the band.
-
-               If onlyFixedObjects is True, growable objects won't be 
-               counted.
                """
 
-               height = bandDict.getProp("Height")
-               if height is not None:
+               bandHeight = bandDict.getProp("Height")
+               if bandHeight is not None:
                        # explicitly-set height
-                       return self.getPt(height)
+                       return self.getPt(bandHeight)
 
                # dynamic height: figure out based on the objects in the band.
-               maxHeight = 0
+               bandHeight = 0
                objects = bandDict.get("objects", [])
 
                for obj in objects:
                        obj_y = self.getPt(obj.getProp("y"))
-                       obj_ht = self.getObjectHeight(obj)
+                       obj_ht = obj.getProp("Height")
+                       if obj_ht is None:
+                               continue
+                       # object height is fixed.
+                       obj_ht = self.getPt(obj_ht)
+                       thisHeight = obj_y + obj_ht
+                       bandHeight = max(thisHeight, bandHeight)
+               return bandHeight
 
-                       if obj.getProp("Height") is None:
-                               # Object height grows downward to accommodate 
(not upward like
-                               # other objects), so we need to add to the 
height beyond the area
-                               # already filled by the y pos of the object.
-                               if not onlyFixedObjects:
-                                       thisHeight = obj_ht - obj_y
-                               else:
-                                       thisHeight = obj_y
-                       else:
-                               # object height is fixed.
-                               thisHeight = obj_y + obj_ht
 
-                       maxHeight = max(thisHeight, maxHeight)
-               return maxHeight
-
-
-       def getObjectHeight(self, obj):
-               """Return the height of the object, in points.
-
-               If the object's height is None and it is growable (paragraph),
-               the height will be calculated.
-               """
-               obj_ht = obj.getProp("Height")
-               if obj_ht is None:
-                       obj_ht = self.getNeededHeight(obj)
-               return self.getPt(obj_ht)
-               
-
        def getPageSize(self):
                ## Set the Page Size:
                # get the string pageSize value from the spec file:



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to