Update of /cvsroot/pythonreports/PythonReports/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22202
Modified Files:
test_build.py
Log Message:
initialize wx.App (may be needed for wx backend);
add wx-based progress indicator;
limit the number of processed rows
Index: test_build.py
===================================================================
RCS file: /cvsroot/pythonreports/PythonReports/test/test_build.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** test_build.py 1 Nov 2006 11:24:31 -0000 1.1
--- test_build.py 2 Nov 2006 11:30:19 -0000 1.2
***************
*** 3,6 ****
--- 3,9 ----
"""History (most recent first):
+ 01-nov-2006 [als] initialize wx.App (may be needed for wx backend);
+ add wx-based progress indicator;
+ limit the number of processed rows
25-jul-2006 [als] file output adjusted for ElementTree-based API
17-jul-2006 [als] created
***************
*** 12,19 ****
--- 15,33 ----
import sys
+ try:
+ import wx
+ except ImportError:
+ wx = None
+
from PythonReports.builder import Builder
import sakila
+ # limit the number of data objects to render
+ # (set to sys.maxint to process the whole sequence).
+ # (444 doesn't cause page break before the summary section
+ # with wx and RL drivers and is big enough to see the progress.)
+ DATA_LIMIT = 444
+
class Progress(object):
***************
*** 26,29 ****
--- 40,49 ----
self.percent = -1
+ def indicate(self):
+ """Show progress indicator at self.percent"""
+ _pos = int(_percent / 100 * self.BAR_WIDTH)
+ sys.stdout.write("\r[%s>%s] %5.1f%%"
+ % ("=" * _pos, " " * (self.BAR_WIDTH - _pos), _percent))
+
def __call__(self):
_context = self.builder.context
***************
*** 32,48 ****
if _percent > self.percent:
self.percent = _percent
! _pos = int(_percent / 100 * self.BAR_WIDTH)
! sys.stdout.write("\r[%s>%s] %5.1f%%"
! % ("=" * _pos, " " * (self.BAR_WIDTH - _pos), _percent))
def run():
_builder = Builder("sakila.prt")
try:
! _printout = _builder.run(sakila.load(),
! item_callback=Progress(_builder))
! except:
! raise
! # end progress report - print newline
! print
# write printout file
_out = file("sakila.prp", "w")
--- 52,96 ----
if _percent > self.percent:
self.percent = _percent
! self.indicate()
!
! def terminate(self):
! """Finalize the progress display"""
! print # line feed
!
! if wx:
! class wxProgress(Progress):
!
! def __init__(self, builder):
! super(wxProgress, self).__init__(builder)
! self.dialog = wx.ProgressDialog("Build Report",
! "Building the report, please wait...",
! style = wx.PD_APP_MODAL | wx.PD_SMOOTH | wx.PD_AUTO_HIDE
! | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME)
!
! def indicate(self):
! self.dialog.Update(self.percent)
!
! def terminate(self):
! self.dialog.Hide()
! self.dialog.Destroy()
def run():
+ if wx:
+ # if wx backend is used, App must be created
+ # before builder initialization.
+ _app = wx.App(0)
+ # create report builder
_builder = Builder("sakila.prt")
+ # create progress indicator
+ if wx:
+ _progress = wxProgress(_builder)
+ else:
+ _progress = Progress(_builder)
+ # build printout
try:
! _printout = _builder.run(sakila.load()[:DATA_LIMIT],
! item_callback=_progress)
! finally:
! _progress.terminate()
# write printout file
_out = file("sakila.prp", "w")
|