dabo Commit
Revision 1386
Date: 2005-09-27 18:35:06 -0700 (Tue, 27 Sep 2005)
Author: paul

Changed:
U   trunk/dabo/lib/datanav/Form.py
U   trunk/dabo/lib/reportWriter.py
U   trunk/dabo/ui/uiwx/dGrid.py

Log:
Added Font* properties to dColumn. These apply to all the cells in an 
individual column, unless you have overridden an individual cell's 
renderer, in which case the font settings of that renderer will come
into play.

Added ability for report bands to have a height of None, which means that they
will be dynamically sized to accomodate all objects at runtime. For the detail
band, this means that theoretically each record could have a different band
height, if text flows down, for example. I say theoretically because I haven't
actually tested that yet.

Improved the automatic print preview report format in datanav. It now:

        + prints column headers

        + mirrors the font size, column width, cell vertical and horizontal
          alignment, and column height of the grid

        + mirrors the font size, header height, vertical and horizontal 
          alignment of the grid headers

        + automatically reorients to landscape if the detail flows beyond the 
width
          of portrait

        + stops printing more columns if doing so would result in overflowing 
the
          right margin




Diff:
Modified: trunk/dabo/lib/datanav/Form.py
===================================================================
--- trunk/dabo/lib/datanav/Form.py      2005-09-27 19:37:10 UTC (rev 1385)
+++ trunk/dabo/lib/datanav/Form.py      2005-09-28 01:35:06 UTC (rev 1386)
@@ -500,23 +500,16 @@
                           will be as defined in the browse page. If 
mode=="one", the fields displayed
                           will be as defined in the edit page.   *** PARTIALLY 
IMPLEMENTED ***
                """
+               grid = self.PageFrame.Pages[1].BrowseGrid
+
                rfxml = """<?xml version="1.0" encoding="UTF-8" 
standalone="yes"?>
 
 <report>
        <title>"""
                rfxml += "Quick Report: %s" % self.Caption
                rfxml += """</title>
-       <page>
-               <marginBottom>".5 in"</marginBottom>
-               <marginLeft>".5 in"</marginLeft>
-               <marginRight>".5 in"</marginRight>
-               <marginTop>".25 in"</marginTop>
-               <orientation>"portrait"</orientation>
-               <size>"letter"</size>
-       </page>
-
        <pageHeader>
-               <height>"0.25 in"</height>
+               <height>"0.75 in"</height>
                <objects>
                        <string>
                                <align>"center"</align>
@@ -529,33 +522,132 @@
                                <height>15.96</height>
                                <name>title</name>
                                <width>384.0</width>
-                               <x>265.0</x>
-                               <y>0.0</y>
-                       </string>
+                               <x>self.Bands["pageHeader"]["width"]/2</x>
+                               <y>"0.6 in"</y>
+                       </string>"""
+               x = 0
+               horBuffer = 3
+               vertBuffer = 5
+               for col in grid.Columns:
+                       coldict = {"caption": col.Caption, "fontSize": 
col.HeaderFontSize,
+                                  "width": col.Width, "x": x+horBuffer}
+                       coldict["horBuffer"] = horBuffer
+                       coldict["vertBuffer"] = vertBuffer
+                       coldict["rectWidth"] = coldict["width"] + (2*horBuffer)
+                       coldict["rectHeight"] = grid.HeaderHeight
+                       hAlign = col.HeaderHorizontalAlignment
+                       if hAlign is None:
+                               hAlign = grid.HeaderHorizontalAlignment
+                       coldict["textHorAlignment"] = "'%s'" % 
hAlign.lower().split(" ")[0]
+                       coldict["rectX"] = x
+                       vAlign = col.HeaderVerticalAlignment    
+                       if vAlign is None:
+                               vAlign = grid.HeaderHorizontalAlignment
+                       vAlign = vAlign[:3]
+                       if vAlign == "Cen":
+                               textY = (coldict["rectHeight"] / 2) - 
(coldict["fontSize"]/2)
+                       elif vAlign == "Top":
+                               textY = coldict["rectHeight"] - 
coldict["fontSize"]
+                       else:
+                               textY = vertBuffer
+                       coldict["textY"] = textY
+
+                       x += coldict["rectWidth"]
+                       if x > 720:
+                               # We'll run off the edge of the page, ignore 
the rest:
+                               break
+
+                       rfxml += """
+                       <rect>
+                               <width>%(rectWidth)s</width>
+                               <height>%(rectHeight)s</height>
+                               <strokeWidth>0.25</strokeWidth>
+                               <fillColor>(0.9,0.9,0.9)</fillColor>
+                               <x>%(rectX)s</x>
+                               <y>0</y>
+                       </rect>
+                       <string>
+                               <expr>"%(caption)s"</expr>
+                               <height>%(fontSize)s</height>
+                               <align>%(textHorAlignment)s</align>
+                               <fontSize>%(fontSize)s</fontSize>
+                               <width>%(width)s</width>
+                               <x>%(x)s</x>
+                               <y>%(textY)s</y>
+                       </string>""" % coldict
+               
+               rfxml += """
                </objects>
        </pageHeader>
 
        <detail>
-               <height>25</height>
+               <height>None</height>
                <objects>"""
                x = 0
-               for col in self.PageFrame.Pages[1].BrowseGrid.Columns:
-                       coldict = {"caption": col.Caption, "field": 
col.DataField, "width": col.Width, "x": x}
+               horBuffer = 3
+               vertBuffer = 5
+               for col in grid.Columns:
+                       coldict = {"caption": col.Caption, "field": 
col.DataField, 
+                                  "width": col.Width, "fontSize": col.FontSize,
+                                  "x": x+horBuffer}
+                       coldict["horBuffer"] = horBuffer
+                       coldict["vertBuffer"] = vertBuffer
+                       coldict["rectWidth"] = coldict["width"] + (2*horBuffer)
+                       coldict["rectHeight"] = col.Parent.RowHeight
+                       coldict["textHorAlignment"] = "'%s'" % 
col.HorizontalAlignment.lower().split(" ")[0]
+                       coldict["rectX"] = x
+                       vAlign = col.VerticalAlignment  [:3]
+                       if vAlign == "Cen":
+                               textY = (coldict["rectHeight"] / 2) - 
(coldict["fontSize"]/2)
+                       elif vAlign == "Top":
+                               textY = coldict["rectHeight"] - 
coldict["fontSize"]
+                       else:
+                               textY = vertBuffer
+                       coldict["textY"] = textY
+
+                       x += coldict["rectWidth"]
+                       if x > 720:
+                               # We'll run off the edge of the page, ignore 
the rest:
+                               break
+
                        rfxml += """
+                       <rect>
+                               <width>%(rectWidth)s</width>
+                               <height>%(rectHeight)s</height>
+                               <strokeWidth>0.25</strokeWidth>
+                               <x>%(rectX)s</x>
+                               <y>0</y>
+                       </rect>
                        <string>
                                <expr>str(self.Record["%(field)s"])</expr>
-                               <height>15</height>
+                               <height>%(fontSize)s</height>
+                               <align>%(textHorAlignment)s</align>
+                               <fontSize>%(fontSize)s</fontSize>
                                <width>%(width)s</width>
                                <x>%(x)s</x>
-                               <y>0</y>
+                               <y>%(textY)s</y>
                        </string>""" % coldict
-                       x += coldict["width"]
+
+               orientation = "portrait"
+               if x > 504:
+                       # switch to landscape
+                       orientation = "landscape"
+               
                rfxml += """
                </objects>
        </detail>
 
+       <page>
+               <marginBottom>".5 in"</marginBottom>
+               <marginLeft>".5 in"</marginLeft>
+               <marginRight>".5 in"</marginRight>
+               <marginTop>".25 in"</marginTop>
+               <orientation>"%s"</orientation>
+               <size>"letter"</size>
+       </page>
+
 </report>
-"""
+""" % orientation
                return rfxml
 
                                

Modified: trunk/dabo/lib/reportWriter.py
===================================================================
--- trunk/dabo/lib/reportWriter.py      2005-09-27 19:37:10 UTC (rev 1385)
+++ trunk/dabo/lib/reportWriter.py      2005-09-28 01:35:06 UTC (rev 1386)
@@ -566,10 +566,16 @@
                        self.Bands[band] = {}
 
                        try:            
-                               height = self.getPt(eval(bandDict["height"]))
+                               height = eval(bandDict["height"])
                        except KeyError:
-                               height = self.getPt(self.default_bandHeight)
+                               height = self.default_bandHeight
 
+                       if height is not None:
+                               height = self.getPt(height)
+                       else:
+                               # figure out height based on the objects in the 
band.
+                               height = self.calculateBandHeight(bandDict)
+
                        x = ml
                        y = y - height
                        width = pageWidth - ml - mr
@@ -581,16 +587,9 @@
                                x,y = pageFooterOrigin
                        elif band in ("pageBackground", "pageForeground"):
                                x,y = 0,1
-
-                       if band in ("pageBackground", "pageForeground"):
                                width, height = pageWidth-1, pageHeight-1
-                       else:
-                               width = pageWidth - ml - mr
-                               try:
-                                       height = 
self.getPt(eval(bandDict["height"]))
-                               except KeyError:
-                                       height = self.default_bandHeight
 
+
                        if band == "detail":
                                pf = _form.get("pageFooter")
                                if pf is None:
@@ -686,6 +685,26 @@
                        self._canvas = None
 
 
+       def calculateBandHeight(self, bandDict):
+               maxHeight = 0
+               if bandDict.has_key("objects"):
+                       for object in bandDict["objects"]:
+                               try:
+                                       y = self.getPt(eval(object["y"]))
+                               except KeyError:
+                                       y = self.default_y
+
+                               try:
+                                       ht = eval(object["height"])
+                               except KeyError:
+                                       ht = self.default_height
+                               ht = self.getPt(ht)
+
+                               thisHeight = y + ht
+                               maxHeight = max(thisHeight, maxHeight)
+               return maxHeight
+
+               
        def getPageSize(self):
                ## Set the Page Size:
                # get the string pageSize value from the spec file:

Modified: trunk/dabo/ui/uiwx/dGrid.py
===================================================================
--- trunk/dabo/ui/uiwx/dGrid.py 2005-09-27 19:37:10 UTC (rev 1385)
+++ trunk/dabo/ui/uiwx/dGrid.py 2005-09-28 01:35:06 UTC (rev 1386)
@@ -440,7 +440,8 @@
                self._beforeInit()
                kwargs["Parent"] = parent
                # dColumn maintains one attr object that the grid table will 
use:
-               self._gridColAttr = parent._defaultGridColAttr.Clone()
+               a = self._gridColAttr = parent._defaultGridColAttr.Clone()
+               a.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.LIGHT))
 
                super(dColumn, self).__init__(properties, *args, **kwargs)
 
@@ -718,6 +719,96 @@
                        self._properties["DataField"] = val
 
 
+       def _getFont(self):
+               return self._gridColAttr.GetFont()
+       
+       def _setFont(self, val):
+               if self._constructed():
+                       assert isinstance(val, wx.Font)
+                       self._gridColAttr.SetFont(val)
+                       self._refreshGrid()
+               else:
+                       self._properties["Font"] = val
+
+       
+       def _getFontBold(self):
+               return self.Font.GetWeight() == wx.BOLD
+       
+       def _setFontBold(self, val):
+               if self._constructed():
+                       font = self.Font
+                       if val:
+                               font.SetWeight(wx.BOLD)
+                       else:
+                               font.SetWeight(wx.LIGHT)
+                       self.Font = font
+               else:
+                       self._properties["FontBold"] = val
+
+       def _getFontDescription(self):
+               f = self.Font
+               ret = f.GetFaceName() + " " + str(f.GetPointSize())
+               if f.GetWeight() == wx.BOLD:
+                       ret += " B"
+               if f.GetStyle() == wx.ITALIC:
+                       ret += " I"
+               return ret
+       
+       def _getFontInfo(self):
+               return self.Font.GetNativeFontInfoDesc()
+
+               
+       def _getFontItalic(self):
+               return self.Font.GetStyle() == wx.ITALIC
+       
+       def _setFontItalic(self, val):
+               if self._constructed():
+                       font = self.Font
+                       if val:
+                               font.SetStyle(wx.ITALIC)
+                       else:
+                               font.SetStyle(wx.NORMAL)
+                       self.Font = font
+               else:
+                       self._properties["FontItalic"] = val
+
+       
+       def _getFontFace(self):
+               return self.Font.GetFaceName()
+
+       def _setFontFace(self, val):
+               if self._constructed():
+                       f = self.Font
+                       f.SetFaceName(val)
+                       self.Font = f
+               else:
+                       self._properties["FontFace"] = val
+
+       
+       def _getFontSize(self):
+               return self.Font.GetPointSize()
+       
+       def _setFontSize(self, val):
+               if self._constructed():
+                       font = self.Font
+                       font.SetPointSize(int(val))
+                       self.Font = font
+               else:
+                       self._properties["FontSize"] = val
+       
+       def _getFontUnderline(self):
+               return self.Font.GetUnderlined()
+       
+       def _setFontUnderline(self, val):
+               if self._constructed():
+                       # underlining doesn't seem to be working...
+                       font = self.Font
+                       font.SetUnderlined(bool(val))
+                       self.Font = font
+               else:
+                       self._properties["FontUnderline"] = val
+
+
        def _getHeaderFont(self):
                try:
                        v = self._headerFont
@@ -1096,6 +1187,30 @@
        DataField = property(_getDataField, _setDataField, None,
                        _("Field key in the data set to which this column is 
bound.  (str)") )
 
+       Font = property(_getFont, _setFont, None,
+                       _("The font properties of the column's cells. (obj)") )
+       
+       FontBold = property(_getFontBold, _setFontBold, None,
+                       _("Specifies if the cell font is bold-faced. (bool)") )
+       
+       FontDescription = property(_getFontDescription, None, None, 
+                       _("Human-readable description of the column's cell font 
settings. (str)") )
+       
+       FontFace = property(_getFontFace, _setFontFace, None,
+                       _("Specifies the font face for the column cells. 
(str)") )
+       
+       FontInfo = property(_getFontInfo, None, None,
+                       _("Specifies the platform-native font info string for 
the column cells. Read-only. (str)") )
+       
+       FontItalic = property(_getFontItalic, _setFontItalic, None,
+                       _("Specifies whether the column's cell font is 
italicized. (bool)") )
+       
+       FontSize = property(_getFontSize, _setFontSize, None,
+                       _("Specifies the point size of the column's cell font. 
(int)") )
+       
+       FontUnderline = property(_getFontUnderline, _setFontUnderline, None,
+                       _("Specifies whether cell text is underlined. (bool)") )
+
        HeaderBackgroundColor = property(_getHeaderBackgroundColor, 
_setHeaderBackgroundColor, None,
                        _("Optional color for the background of the column 
header  (str)") )
 
@@ -1191,7 +1306,10 @@
 
                cm.dControlMixin.__init__(self, preClass, parent, properties, 
*args, **kwargs)
                
+               # Need to sync the size reported by wx to the size reported by 
Dabo:
+               self.RowHeight = self.RowHeight
 
+
        def _afterInit(self):
                self._header = None
                self.fieldSpecs = {}
@@ -2299,15 +2417,8 @@
                row = evt.GetRowOrCol()
                size = self.GetRowSize(row)
 
-               # Persist the new size
-               app = self.Application
-               if app is not None:
-                       app.setUserSetting("%s.%s.%s" % (
-                                          self.Form.Name, self.Name, 
"RowSize"), size)
-               
                if self.SameSizeRows:
-                       self.SetDefaultRowSize(size, True)
-                       self.ForceRefresh()
+                       self.RowHeight = size
 
        
        def _onGridCellSelected(self, evt):
@@ -2740,12 +2851,12 @@
                try:
                        val = self._headerHorizontalAlignment
                except AttributeError:
-                       val = self._headerHorizontalAlignment = None
+                       val = self._headerHorizontalAlignment = "Center"
                return val
 
        def _setHeaderHorizontalAlignment(self, val):
                if self._constructed():
-                       v = self._expandPropStringValue(val, ("Left", "Right", 
"Center", None))
+                       v = self._expandPropStringValue(val, ("Left", "Right", 
"Center"))
                        self._headerHorizontalAlignment = v
                        self.refresh()
                else:
@@ -2756,12 +2867,12 @@
                try:
                        val = self._headerVerticalAlignment
                except AttributeError:
-                       val = self._headerVerticalAlignment = None
+                       val = self._headerVerticalAlignment = "Center"
                return val
 
        def _setHeaderVerticalAlignment(self, val):
                if self._constructed():
-                       v = self._expandPropStringValue(val, ("Top", "Bottom", 
"Center", None))
+                       v = self._expandPropStringValue(val, ("Top", "Bottom", 
"Center"))
                        self._headerVerticalAlignment = v
                        self.refresh()
                else:




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to