daboide Commit
Revision 218
Date: 2005-10-30 22:25:17 -0800 (Sun, 30 Oct 2005)
Author: paul
Changed:
U trunk/wizards/AppWizardX/AppWizard.py
A trunk/wizards/AppWizardX/spec-FrmReportBase.py
A trunk/wizards/AppWizardX/spec-FrmReportSample.py
U trunk/wizards/AppWizardX/spec-MenReports.py
A trunk/wizards/AppWizardX/spec-getSampleDataSet.py
A trunk/wizards/AppWizardX/spec-sampleReport.rfxml
Log:
Added a sample report along with sample report form and sample dataset
for the report. Eventually, we'll want a checkbox in the wizard to turn
on/off the generation of the sample report, but I wanted to get actual
code in people's hands to be able to introduce simple reporting into
their apps.
Diff:
Modified: trunk/wizards/AppWizardX/AppWizard.py
===================================================================
--- trunk/wizards/AppWizardX/AppWizard.py 2005-10-31 00:50:36 UTC (rev
217)
+++ trunk/wizards/AppWizardX/AppWizard.py 2005-10-31 06:25:17 UTC (rev
218)
@@ -718,6 +718,8 @@
open("./__init__.py",
"w").write(self.getModuleInit_db())
open("./default.cnxml",
"w").write(self.getDbConnXML(ci))
+ # Write the sample getDataSet:
+ open("./getSampleDataSet.py",
"w").write(self.getSampleDataSet())
# Biz module:
os.chdir("../biz")
@@ -755,6 +757,10 @@
f.write(self.getReportsMenu())
f.close()
+ ## FrmReportBase and FrmReportSample:
+ open("./FrmReportBase.py",
"w").write(self.getFrmReportBase())
+ open("./FrmReportSample.py",
"w").write(self.getFrmReportSample())
+
## base page:
open("./PagBase.py", "w").write(self.getPagBase())
@@ -767,6 +773,10 @@
f.write(self.getForm(table))
f.close()
+ # reports dir:
+ os.chdir("../reports")
+ open("./sampleReport.rfxml",
"w").write(self.getSampleReport())
+
return True
else:
@@ -868,11 +878,31 @@
"spec-FrmBase.py")).read() % locals()
+ def getFrmReportBase(self):
+ return open(os.path.join(self.Application.HomeDirectory,
+ "spec-FrmReportBase.py")).read() % locals()
+
+
+ def getFrmReportSample(self):
+ return open(os.path.join(self.Application.HomeDirectory,
+ "spec-FrmReportSample.py")).read() % locals()
+
+
def getPagBase(self):
return open(os.path.join(self.Application.HomeDirectory,
"spec-PagBase.py")).read() % locals()
+ def getSampleDataSet(self):
+ return open(os.path.join(self.Application.HomeDirectory,
+ "spec-getSampleDataSet.py")).read() % locals()
+
+
+ def getSampleReport(self):
+ return open(os.path.join(self.Application.HomeDirectory,
+ "spec-sampleReport.rfxml")).read() % locals()
+
+
def relationSpecs(relaDict):
ret = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<daboRelationSpecs>
Added: trunk/wizards/AppWizardX/spec-FrmReportBase.py
===================================================================
--- trunk/wizards/AppWizardX/spec-FrmReportBase.py 2005-10-31 00:50:36 UTC
(rev 217)
+++ trunk/wizards/AppWizardX/spec-FrmReportBase.py 2005-10-31 06:25:17 UTC
(rev 218)
@@ -0,0 +1,53 @@
+import dabo.ui
+from dabo.dReportWriter import dReportWriter
+import dabo.lib.reportUtils as reportUtils
+
+
+class FrmReportBase(dabo.ui.dDialog):
+
+ def initProperties(self):
+ if self.ReportName:
+ self.Caption = self.ReportName
+ else:
+ self.Caption = "Run Report"
+ self.Modal = True
+ self.ReportForm = None
+ self.DataSet = []
+ self.ReportWriter = dReportWriter(Encoding="latin-1")
+ self.SizerBorder = 7
+
+
+ def addControls(self):
+ preview = self.addObject(dabo.ui.dButton, Caption="Run Report",
+ RegID="cmdRunReport")
+ hs = dabo.ui.dSizer("h")
+ hs.append(preview, alignment="right", border=self.SizerBorder)
+ self.Sizer.append(hs, alignment="bottom",
border=self.SizerBorder)
+
+
+ def onHit_cmdRunReport(self, evt):
+ self.runReport()
+
+
+ def requery(self):
+ """Subclasses should override to fill self.DataSet"""
+ pass
+
+
+ def runReport(self, requery=True):
+ """Preview the report in the default pdf viewer."""
+ if requery:
+ self.requery()
+ f = self.write()
+ reportUtils.previewPDF(f)
+
+
+ def write(self):
+ """Write the report to a temporary file, and return the file
name."""
+ rw = self.ReportWriter
+ rw.ReportFormFile = self.ReportForm
+ rw.Cursor = self.DataSet
+ f = rw.OutputFile = reportUtils.getTempFile()
+ rw.write()
+ return f
+
Property changes on: trunk/wizards/AppWizardX/spec-FrmReportBase.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/wizards/AppWizardX/spec-FrmReportSample.py
===================================================================
--- trunk/wizards/AppWizardX/spec-FrmReportSample.py 2005-10-31 00:50:36 UTC
(rev 217)
+++ trunk/wizards/AppWizardX/spec-FrmReportSample.py 2005-10-31 06:25:17 UTC
(rev 218)
@@ -0,0 +1,32 @@
+## This is a sample form for putting together a report form xml (rfxml file)
+## and a dataset, and previewing the report. Study this code, as well as the
+## code in FrmReportBase, and then rework it to your specific needs. To put
+## your report in the reports menu, see MenReports.py.
+
+import datetime
+import os
+import dabo.ui
+from FrmReportBase import FrmReportBase
+
+
+class FrmReportSample(FrmReportBase):
+
+ def initProperties(self):
+ app = self.Application
+ self.ReportName = "Sample Report"
+ FrmReportSample.doDefault()
+ self.ReportForm = os.path.join(app.HomeDirectory,
"reports/sampleReport.rfxml")
+ self.DataSetFunction = app.db.getSampleDataSet
+
+
+ def addControls(self):
+ """Add any controls here, such as record selection choices."""
+ FrmReportSample.doDefault()
+
+
+ def requery(self):
+ """Called by preview in FrmReportBase, it's time to requery the
dataset."""
+ # Send whatever parameters your function requires, perhaps as
entered by the
+ # user in the controls you've exposed in this form.
+ self.DataSet = self.DataSetFunction()
+
Property changes on: trunk/wizards/AppWizardX/spec-FrmReportSample.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/wizards/AppWizardX/spec-MenReports.py
===================================================================
--- trunk/wizards/AppWizardX/spec-MenReports.py 2005-10-31 00:50:36 UTC (rev
217)
+++ trunk/wizards/AppWizardX/spec-MenReports.py 2005-10-31 06:25:17 UTC (rev
218)
@@ -23,9 +23,7 @@
# tuple and the code below will insert a separator in its
place. Explicitly
# set up which character has the hotkey by adding a & in front
of it and
# by turning off the autoHotKeys flag. eg:
- # forms = (("&Invoices",
app.ui.FrmReportInvoices),
- # ("&Statements",
app.ui.FrmReportStatements),)
- forms = ()
+ forms = (("&Sample Report", app.ui.FrmReportSample),)
for form in forms:
caption = form[0]
Added: trunk/wizards/AppWizardX/spec-getSampleDataSet.py
===================================================================
--- trunk/wizards/AppWizardX/spec-getSampleDataSet.py 2005-10-31 00:50:36 UTC
(rev 217)
+++ trunk/wizards/AppWizardX/spec-getSampleDataSet.py 2005-10-31 06:25:17 UTC
(rev 218)
@@ -0,0 +1,15 @@
+import datetime
+import decimal
+import dabo
+
+
+def getSampleDataSet():
+ """Return the dataset for the sample report.
+
+ Your real code here would run ad-hoc sql queries and build up a
+ dataset (list of dicts).
+ """
+ ds = [{"name": "Denise", "sex": "F"},
+ {"name": "Paul", "sex": "M"}]
+ return ds
+
Property changes on: trunk/wizards/AppWizardX/spec-getSampleDataSet.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/wizards/AppWizardX/spec-sampleReport.rfxml
===================================================================
--- trunk/wizards/AppWizardX/spec-sampleReport.rfxml 2005-10-31 00:50:36 UTC
(rev 217)
+++ trunk/wizards/AppWizardX/spec-sampleReport.rfxml 2005-10-31 06:25:17 UTC
(rev 218)
@@ -0,0 +1,231 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+
+<report>
+ <page>
+ <marginBottom>".5 in"</marginBottom>
+ <marginLeft>".75 in"</marginLeft>
+ <marginRight>".75 in"</marginRight>
+ <marginTop>".75 in"</marginTop>
+ <orientation>"portrait"</orientation>
+ <size>"letter"</size>
+ </page>
+
+ <pageHeader>
+ <height>"1.75 in"</height>
+ <objects>
+ <string>
+ <align>"left"</align>
+ <vAlign>"top"</vAlign>
+ <vAnchor>"top"</vAnchor>
+ <borderWidth>"0 pt"</borderWidth>
+
<expr>self.Application.getAppInfo("companyName")</expr>
+ <fontName>"Helvetica"</fontName>
+ <fontBold>True</fontBold>
+ <fontSize>14</fontSize>
+ <hAnchor>"left"</hAnchor>
+ <height>16</height>
+ <name>companyName</name>
+ <width>"4 in"</width>
+ <x>"1.1 in"</x>
+ <y>"1.7875 in"</y>
+ </string>
+
+ <string>
+ <align>"left"</align>
+ <vAlign>"top"</vAlign>
+ <vAnchor>"top"</vAnchor>
+ <borderWidth>"0 pt"</borderWidth>
+
<expr>self.Application.getAppInfo("companyAddress1")</expr>
+ <fontName>"Helvetica"</fontName>
+ <fontSize>14</fontSize>
+ <hAnchor>"left"</hAnchor>
+ <height>16</height>
+ <name>companyAddress1</name>
+ <width>"4 in"</width>
+ <x>"1.1 in"</x>
+ <y>"1.5575 in"</y>
+ </string>
+
+ <string>
+ <align>"left"</align>
+ <vAlign>"top"</vAlign>
+ <vAnchor>"top"</vAnchor>
+ <borderWidth>"0 pt"</borderWidth>
+
<expr>self.Application.getAppInfo("companyAddress2")</expr>
+ <fontName>"Helvetica"</fontName>
+ <fontSize>14</fontSize>
+ <hAnchor>"left"</hAnchor>
+ <height>16</height>
+ <name>companyAddress1</name>
+ <width>"4 in"</width>
+ <x>"1.1 in"</x>
+ <y>"1.3275 in"</y>
+ </string>
+
+ <string>
+ <align>"left"</align>
+ <vAlign>"top"</vAlign>
+ <vAnchor>"top"</vAnchor>
+ <borderWidth>"0 pt"</borderWidth>
+
<expr>self.Application.getAppInfo("companyPhone")</expr>
+ <fontName>"Helvetica"</fontName>
+ <fontSize>14</fontSize>
+ <hAnchor>"left"</hAnchor>
+ <height>16</height>
+ <name>companyAddress1</name>
+ <width>"7 in"</width>
+ <x>"1.1 in"</x>
+ <y>"1.0975 in"</y>
+ </string>
+
+ <string>
+ <align>"right"</align>
+ <vAlign>"top"</vAlign>
+ <vAnchor>"top"</vAnchor>
+ <borderWidth>"0 pt"</borderWidth>
+ <expr>self.ReportForm["title"]</expr>
+ <fontName>"Helvetica"</fontName>
+ <fontSize>36</fontSize>
+ <hAnchor>"right"</hAnchor>
+ <height>30</height>
+ <name>title</name>
+ <width>"4 in"</width>
+ <x>self.Bands["pageHeader"]["width"]-1</x>
+ <y>self.Bands["pageHeader"]["height"]</y>
+ </string>
+
+ </objects>
+ </pageHeader>
+
+ <variables>
+<!--
+ <variable>
+ <name>clientBalance</name>
+ <expr>self.Variables['clientBalance'] +
self.Record['amount']</expr>
+ <initialValue>decimal.Decimal('0.00')</initialValue>
+ <resetAt>self.Record['clientid']</resetAt>
+ </variable>
+-->
+ </variables>
+
+ <groups>
+<!--
+ <group>
+ <expr>self.Record['clientid']</expr>
+ <startOnNewPage>True</startOnNewPage>
+ <groupHeader>
+ <height>"2.125 in"</height>
+ <objects>
+ <string>
+
<expr>self.Record["clientname"]</expr>
+ <height>20</height>
+ <width>"6 in"</width>
+ <fontSize>14</fontSize>
+ <x>"0 in"</x>
+ <y>"1.925 in"</y>
+ </string>
+ </objects>
+ </groupHeader>
+ <groupFooter>
+ <height>"0.25 in"</height>
+ <objects>
+ <string>
+ <expr>"Amount due: $
%%s" %% locale.format('%%s',
+
self.Variables["clientBalance"], True)</expr>
+ <align>"right"</align>
+ <hAnchor>"right"</hAnchor>
+ <height>20</height>
+ <width>"6 in"</width>
+ <fontSize>14</fontSize>
+ <x>"7 in"</x>
+ <y>"0 in"</y>
+ </string>
+ </objects>
+ </groupFooter>
+ </group>
+ -->
+ </groups>
+
+ <detail>
+ <height>".25 in"</height>
+ <objects>
+ <rect>
+ <height>".25 in"</height>
+ <strokeWidth>".25 pt"</strokeWidth>
+ <width>"5.5 in"</width>
+ <x>"1.5 in"</x>
+ <y>"0 in"</y>
+ </rect>
+ <string>
+ <expr>self.Record["name"]</expr>
+ <height>15</height>
+ <width>"0.80 in"</width>
+ <x>"1.6 in"</x>
+ <y>5</y>
+ </string>
+ <line>
+ <strokeWidth>0.25</strokeWidth>
+ <strokeColor>(.2,.2,.2)</strokeColor>
+ <x>"2.605 in"</x>
+ <y>0</y>
+ <height>self.Bands["detail"]["height"]</height>
+ <width>0</width>
+ </line>
+ <string>
+ <expr>self.Record["sex"]</expr>
+ <height>15</height>
+ <width>"1.25 in"</width>
+ <x>"2.65 in"</x>
+ <y>5</y>
+ </string>
+ </objects>
+ </detail>
+
+ <pageBackground>
+ <objects>
+ <rect>
+ <strokeColor>(.7,.7,.7)</strokeColor>
+ <height>.25</height>
+ <width>.25</width>
+ <x>"0.25 in"</x>
+ <y>"6.875 in"</y>
+ </rect>
+ <rect>
+ <strokeColor>(.7,.7,.7)</strokeColor>
+ <height>.25</height>
+ <width>.25</width>
+ <x>"8.25 in"</x>
+ <y>"6.875 in"</y>
+ </rect>
+ </objects>
+ </pageBackground>
+
+ <pageFooter>
+ <height>"2.5 in"</height>
+ <objects>
+ <string>
+ <align>"center"</align>
+ <borderWidth>"0 pt"</borderWidth>
+ <expr>"This is a sample report generated by the
Dabo AppWizard"</expr>
+ <fontName>"Helvetica"</fontName>
+ <fontSize>12</fontSize>
+ <fontItalic>True</fontItalic>
+ <hAnchor>"center"</hAnchor>
+ <height>"0.25 in"</height>
+ <width>"8 in"</width>
+ <x>"3.5 in"</x>
+ <y>0</y>
+ </string>
+
+ </objects>
+ </pageFooter>
+
+ <testcursor name="str" sex="str">
+ <record name="'Ringo'" sex="'M'" />
+ <record name="'Patsy'" sex="'F'" />
+ <record name="'Johnny'" sex="'M'" />
+ </testcursor>
+
+ <title>Sample Report</title>
+
+</report>
Property changes on: trunk/wizards/AppWizardX/spec-sampleReport.rfxml
___________________________________________________________________
Name: svn:eol-style
+ native
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev