dabo Commit
Revision 5440
Date: 2009-09-29 11:32:30 -0700 (Tue, 29 Sep 2009)
Author: Paul
Trac: http://trac.dabodev.com/changeset/5440
Changed:
U trunk/dabo/dEvents.py
U trunk/dabo/dReportWriter.py
U trunk/dabo/lib/reportWriter.py
U trunk/dabo/ui/uiwx/__init__.py
A trunk/dabo/ui/uiwx/dReportProgress.py
Log:
Added some events to dReportWriter: ReportBegin, ReportEnd, and
ReportIteration. Your code can bind to them like any other Dabo
event.
Added PrintStatus property, which if True (default is False) will
print status information to stdout like "processing record 1 of 20".
Added ShowProgress property, which if True (the default) will
show a progress gauge during the processing of the report, and hide
it when done.
There's a cancel button on the progress window, but it doesn't work.
I think I need to put the processing of the report into a worker
thread for the cancel button to be responsive. I'll try some more
later.
Diff:
Modified: trunk/dabo/dEvents.py
===================================================================
--- trunk/dabo/dEvents.py 2009-09-29 17:41:02 UTC (rev 5439)
+++ trunk/dabo/dEvents.py 2009-09-29 18:32:30 UTC (rev 5440)
@@ -207,6 +207,12 @@
appliesToClass = classmethod(appliesToClass)
+class ReportEvent(dEvent):
+ def appliesToClass(eventClass, objectClass):
+ return issubclass(objectClass, dabo.dReportWriter.dReportWriter)
+ appliesToClass = classmethod(appliesToClass)
+
+
class Activate(dEvent):
"""Occurs when the form or application becomes active."""
def appliesToClass(eventClass, objectClass):
@@ -882,3 +888,18 @@
return issubclass(objectClass, dabo.ui.dSpinner)
appliesToClass = classmethod(appliesToClass)
+
+class ReportBegin(ReportEvent):
+ """Occurs at the beginning of the report."""
+ pass
+
+
+class ReportEnd(ReportEvent):
+ """Occurs at the end of the report."""
+ pass
+
+
+class ReportIteration(ReportEvent):
+ """Occurs when the RecordNumber changes at report runtime."""
+ pass
+
Modified: trunk/dabo/dReportWriter.py
===================================================================
--- trunk/dabo/dReportWriter.py 2009-09-29 17:41:02 UTC (rev 5439)
+++ trunk/dabo/dReportWriter.py 2009-09-29 18:32:30 UTC (rev 5440)
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
+import dabo
from dabo.dLocalize import _
from dabo.lib.reportWriter import ReportWriter
from dabo.dObject import dObject
@@ -20,6 +21,38 @@
There is also a pure-python interface available.
"""
+
+ def _onReportBegin(self):
+ self.super()
+ self.raiseEvent(dabo.dEvents.ReportBegin)
+ if self.ShowProgress:
+ self._createProgress()
+
+ def _onReportEnd(self):
+ self.super()
+ self.raiseEvent(dabo.dEvents.ReportEnd)
+ if self.ShowProgress:
+ self._hideProgress()
+
+ def _onReportIteration(self):
+ dabo.ui.yieldUI()
+ self.super()
+ self.raiseEvent(dabo.dEvents.ReportIteration)
+ if self.ShowProgress:
+ self._updateProgress()
+
+ def _createProgress(self):
+ win = self._progressWindow =
dabo.ui.dReportProgress(self.Application.ActiveForm)
+ win.updateProgress(0, len(self.Cursor))
+ win.Visible = True
+
+ def _updateProgress(self):
+ self._progressWindow.updateProgress(self.RecordNumber+1,
len(self.Cursor))
+
+ def _hideProgress(self):
+ self._progressWindow.close()
+ dabo.ui.yieldUI() ## or else a segfault occurs when the parent
dialog is closed
+
def _getEncoding(self):
try:
v = self._encoding
@@ -45,7 +78,18 @@
def _setHomeDirectory(self, val):
self._homeDirectory = val
+
+ def _getShowProgress(self):
+ try:
+ v = self._showProgress
+ except AttributeError:
+ v = self._showProgress = True
+ return v
+ def _setShowProgress(self, val):
+ self._showProgress = bool(val)
+
+
Encoding = property(_getEncoding, _setEncoding, None,
_("Specifies the encoding for unicode strings. (str)"))
@@ -58,7 +102,14 @@
self.ReportFormFile, HomeDirectory will be set for you
automatically.
Otherwise, it will get set to
self.Application.HomeDirectory."""))
+ ShowProgress = property(_getShowProgress, _setShowProgress, None,
+ _("""Specified whether a default progress window is shown at
runtime.
+ If True, a progress bar will be shown during the processing of
the report.
+ Note that you can provide your own progress window by binding
to the
+ dabo.dEvents.ReportIteration event and setting this
ShowProgress property
+ to False."""))
+
if __name__ == "__main__":
## run a test:
rw = dReportWriter(Name="dReportWriter1", OutputFile="./dRW-test.pdf")
Modified: trunk/dabo/lib/reportWriter.py
===================================================================
--- trunk/dabo/lib/reportWriter.py 2009-09-29 17:41:02 UTC (rev 5439)
+++ trunk/dabo/lib/reportWriter.py 2009-09-29 18:32:30 UTC (rev 5440)
@@ -972,6 +972,20 @@
return
obj.setProp(prop, oldval, logUndo=False)
+ def _onReportBegin(self):
+ if self.PrintStatus:
+ print "Report Begin."
+ sys.stdout.flush()
+
+ def _onReportIteration(self):
+ if self.PrintStatus:
+ print "Processing row %s of %s..." % (self.RecordNumber
+ 1, len(self.Cursor))
+ sys.stdout.flush()
+
+ def _onReportEnd(self):
+ if self.PrintStatus:
+ print "Report End."
+
def storeSpanningObject(self, obj, origin=(0,0), group=None):
"""Store the passed spanning object for printing when the group
or
page ends. Pass the group expr to identify group headers, or
None to refer
@@ -1986,6 +2000,7 @@
# any of the static bands reference the variables.
processVariables()
beginPage()
+ self._onReportBegin()
y = printBand("ReportBegin")
# Print the dynamic bands (Detail, GroupHeader, GroupFooter):
@@ -1994,7 +2009,9 @@
_lastRecord = self.Record
self.Record = record
- # print group footers for previous group if necessary:
+ self._onReportIteration()
+
+ # print group footers for previous group if necessary:
if cursor_idx > 0:
# First pass, iterate through the groups
outer->inner, and if any group
# expr has changed, reset the curval for the
group and all child groups.
@@ -2066,6 +2083,7 @@
for idx, group in enumerate(groupsDesc):
y = printBand("groupFooter", y, group)
+ self._onReportEnd()
y = printBand("ReportEnd", y)
endPage()
@@ -2401,7 +2419,18 @@
def _setHomeDirectory(self, val):
self._homeDirectory = val
+
+ def _getPrintStatus(self):
+ try:
+ v = self._printStatus
+ except AttributeError:
+ v = self._printStatus = False
+ return v
+ def _setPrintStatus(self, val):
+ self._printStatus = bool(val)
+
+
def _getOutputFile(self):
try:
v = self._outputFile
@@ -2559,6 +2588,9 @@
be the directory that contains the report form file. If you set
self.ReportFormFile, HomeDirectory will be set for you
automatically."""))
+ PrintStatus = property(_getPrintStatus, _setPrintStatus, None,
+ _("""Specifies whether status info is printed to stdout."""))
+
OutputFile = property(_getOutputFile, _setOutputFile, None,
_("Specifies the output PDF file (name or file object)."))
Modified: trunk/dabo/ui/uiwx/__init__.py
===================================================================
--- trunk/dabo/ui/uiwx/__init__.py 2009-09-29 17:41:02 UTC (rev 5439)
+++ trunk/dabo/ui/uiwx/__init__.py 2009-09-29 18:32:30 UTC (rev 5440)
@@ -91,6 +91,7 @@
from dFileDialog import dFileDialog
from dFileDialog import dFolderDialog
from dFileDialog import dSaveDialog
+from dReportProgress import dReportProgress
from dSlidePanelControl import dSlidePanelControl
from dSlidePanelControl import dSlidePanel
from dFont import dFont
Added: trunk/dabo/ui/uiwx/dReportProgress.py
===================================================================
--- trunk/dabo/ui/uiwx/dReportProgress.py (rev 0)
+++ trunk/dabo/ui/uiwx/dReportProgress.py 2009-09-29 18:32:30 UTC (rev
5440)
@@ -0,0 +1,30 @@
+import dabo
+from dForm import dBorderlessForm
+from dGauge import dGauge
+from dLabel import dLabel
+from dButton import dButton
+
+class dReportProgress(dBorderlessForm):
+ def afterInit(self):
+ self.gauge = dGauge(self)
+ lblTitle = dLabel(self, Caption="Processing report...",
FontBold=True, FontSize=12)
+ butCancel = dButton(self, CancelButton=True, Caption="Cancel",
OnHit=self.onCancel)
+ ms = self.Sizer = dabo.ui.dBorderSizer(self, "v",
DefaultBorder=10)
+ ms.append(lblTitle)
+ ms.append(self.gauge, "expand")
+ ms.append(butCancel, alignment="right")
+ butCancel.setFocus()
+ self.fitToSizer()
+
+ def initProperties(self):
+ self.Centered = True
+
+ def updateProgress(self, val, range):
+ self.gauge.Range = range
+ self.gauge.Value = val
+ self.gauge.refresh()
+ dabo.ui.yieldUI()
+
+ def onCancel(self, evt):
+ print "cancel"
+
_______________________________________________
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]