Changeset 1185
- Timestamp:
- 08/23/2005 06:58:04 PM (3 years ago)
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/dabo/__init__.py (modified) (1 diff)
- trunk/dabo/lib/datanav/Form.py (modified) (3 diffs)
- trunk/dabo/lib/datanav/Page.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r1182 r1185 14 14 open-source database backends: MySQL, PostgreSQL, Firebird, and SQLite. 15 15 Next on the list should be Oracle, Sybase, and MS-SQL. 16 17 Started work implementing a Quick Report in the datanav library, which 18 replaces the old HTML Print Preview. This uses the fledgling Dabo Report 19 Writer to create a PDF rendition of the dataset. 16 20 17 21 trunk/dabo/__init__.py
r1173 r1185 84 84 85 85 from dApp import dApp 86 from dReportWriter import dReportWriter 87 86 88 from __version__ import version 87 89 import dEvents trunk/dabo/lib/datanav/Form.py
r1165 r1185 41 41 # We want a toolbar 42 42 self.ShowToolBar = True 43 44 43 # The list of _tempfiles will be deleted when the form is destroyed: 44 self._tempFiles = [] 45 46 47 def _initEvents(self): 48 self.bindEvent(dEvents.Close, self._onClose) 49 Form.doDefault() 50 51 45 52 def __init__(self, parent=None, previewMode=False, tbl="", *args, **kwargs): 46 53 self.preview = previewMode … … 57 64 # Map escape key to close the form 58 65 self.bindKey("esc", self.Close) 59 66 67 68 def _onClose(self, evt): 69 for f in self._tempFiles: 70 try: 71 os.remove(f) 72 except: 73 # perhaps it is already gone, removed explicitly. 74 pass 75 76 60 77 def save(self, dataSource=None): 61 78 if dataSource is None: … … 460 477 return None 461 478 479 480 def getReportForm(self, mode): 481 """Returns the rfxml to generate a report for the dataset. 482 483 The mode is one of "all" or "one", and determines if the entire recordset 484 is printed, or just the current record. This allows for different report 485 formats for each case. 486 487 The rfxml can come from a few places, in descending precedence: 488 1) if self.ReportForm["all"] or self.ReportForm["one"] exists, 489 that will be used. *** NOT IMPLEMENTED YET *** 490 491 2) if self.ReportFormFile["all"] or self.ReportFormFile["one"] exists, 492 that will be used. *** NOT IMPLEMENTED YET *** 493 494 3) if self.Application.HomeDirectory/reports/datanav-<cursorname>-(all|one).rfxml 495 exists, that will be used. IOW, drop in a properly named rfxml file into 496 the reports directory underneath your application home, and it will be used 497 automatically. *** NOT IMPLEMENTED YET *** 498 499 4) a generic report form will be generated. If mode=="all", the fields displayed 500 will be as defined in the browse page. If mode=="one", the fields displayed 501 will be as defined in the edit page. *** PARTIALLY IMPLEMENTED *** 502 """ 503 rfxml = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 504 505 <report> 506 <title>""" 507 rfxml += "Quick Report: %s" % self.Caption 508 rfxml += """</title> 509 <page> 510 <marginBottom>".5 in"</marginBottom> 511 <marginLeft>".5 in"</marginLeft> 512 <marginRight>".5 in"</marginRight> 513 <marginTop>".25 in"</marginTop> 514 <orientation>"portrait"</orientation> 515 <size>"letter"</size> 516 </page> 517 518 <pageHeader> 519 <height>"0.25 in"</height> 520 <objects> 521 <string> 522 <align>"center"</align> 523 <valign>"top"</valign> 524 <borderWidth>"0 pt"</borderWidth> 525 <expr>self.ReportForm["title"]</expr> 526 <fontName>"Helvetica"</fontName> 527 <fontSize>14</fontSize> 528 <hAnchor>"center"</hAnchor> 529 <height>15.96</height> 530 <name>title</name> 531 <width>384.0</width> 532 <x>265.0</x> 533 <y>0.0</y> 534 </string> 535 </objects> 536 </pageHeader> 537 538 <detail> 539 <height>25</height> 540 <objects>""" 541 x = 0 542 for col in self.PageFrame.Pages[1].BrowseGrid.Columns: 543 coldict = {"caption": col.Caption, "field": col.Field, "width": col.Width, "x": x} 544 rfxml += """ 545 <string> 546 <expr>str(self.Record["%(field)s"])</expr> 547 <height>15</height> 548 <width>%(width)s</width> 549 <x>%(x)s</x> 550 <y>0</y> 551 </string>""" % coldict 552 x += coldict["width"] 553 rfxml += """ 554 </objects> 555 </detail> 556 557 </report> 558 """ 559 return rfxml 560 462 561 463 562 def _getFormType(self): trunk/dabo/lib/datanav/Page.py
r1177 r1185 1 import os 2 import sys 1 3 import wx 2 4 import dabo … … 636 638 637 639 638 def onPreview(self, evt):640 def __onPreview_old(self, evt): 639 641 if self.itemsCreated: 640 642 if self.Form.preview: … … 662 664 win.PreviewText(html) 663 665 664 666 667 def onPreview(self, evt): 668 if not self.itemsCreated: 669 return 670 if self.Form.preview: 671 # Just previewing 672 dabo.ui.info(message="Not available in preview mode", 673 title = "Preview Mode") 674 return 675 676 class ReportFormatDialog(dabo.ui.dOkCancelDialog): 677 def initProperties(self): 678 self.Caption = "Choose Report" 679 self.mode = None 680 681 def addControls(self): 682 self.addObject(dabo.ui.dRadioGroup, Name="radMode", Caption="Mode", 683 Orientation="Row", 684 Choices=["List all records in dataset", "Just this record"], 685 ValueMode="Key", 686 Keys={"all":0, "one":1}) 687 self.Sizer.append(self.radMode, 1, "expand", border=5) 688 self.addObject(dabo.ui.dButton, Name="btnAdvanced", Caption="Advanced", 689 Enabled=False) 690 self.Sizer.append(self.btnAdvanced, border=5) 691 692 def onOK(self, evt): 693 self.mode = self.radMode.Value 694 695 d = ReportFormatDialog() 696 d.show() 697 mode = d.mode 698 d.release() 699 700 if mode is not None: 701 # Run the report 702 biz = self.Form.getBizobj() 703 rfxml = self.Form.getReportForm(mode) 704 cursor = biz.getDataSet() 705 if mode == "one": 706 cursor = (cursor[biz.RowNumber],) 707 708 outputfile = "%s.pdf" % os.tempnam() 709 self.Form._tempFiles.append(outputfile) 710 711 rw = dabo.dReportWriter(OutputFile=outputfile, 712 ReportFormXML=rfxml, 713 Cursor=cursor) 714 rw.write() 715 716 # Now, preview using the platform's default pdf viewer: 717 try: 718 os.startfile(outputfile) 719 except AttributeError: 720 # startfile only available on Windows 721 if sys.platform == "darwin": 722 os.system("open %s" % outputfile) 723 else: 724 # on Linux, punt with xpdf: 725 os.popen2("xpdf %s" % outputfile) 726 727 665 728 class EditPage(Page): 666 729 def __init__(self, parent, ds=None):
