[PythonReports-checkins] PythonReports/PythonReports design.py, 1.14, 1.15
Brought to you by:
a1s
From: alexander s. <a1...@us...> - 2006-12-07 11:17:30
|
Update of /cvsroot/pythonreports/PythonReports/PythonReports In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16794 Modified Files: design.py Log Message: write printouts Index: design.py =================================================================== RCS file: /cvsroot/pythonreports/PythonReports/PythonReports/design.py,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** design.py 6 Dec 2006 19:26:57 -0000 1.14 --- design.py 7 Dec 2006 11:17:27 -0000 1.15 *************** *** 5,8 **** --- 5,9 ---- """PythonReports Template Designer""" """History (most recent first): + 07-dec-2006 [als] write printouts 06-dec-2006 [als] rebuild insertion menu each time selected node tag changes: prebuilt menu reuse didn't work reliably *************** *** 67,70 **** --- 68,75 ---- from PythonReports.datatypes import * from PythonReports.Tk import PreviewWindow + try: + from PythonReports import pdf + except ImportError: + pdf = None NEW_REPORT_TEMPLATE = """<report> *************** *** 949,952 **** --- 954,959 ---- _popup.add_separator() self._build_menu_item(_popup, ''"Print Pre_view", command=self.preview) + self._build_menu_item(_popup, ''"_Write Printout...", + command=self.printout) # Help menu _popup = self._build_menu_item(_menu, ''"_Help", item_type="cascade") *************** *** 1559,1566 **** validator(tree, _root, "/" + _root.tag) ! def _run_preview(self): ! """Build and show the report""" if not self.updateTree(): ! return # message boxes take focus away. remember currently focused widget # to regain the focus after message display. --- 1566,1577 ---- validator(tree, _root, "/" + _root.tag) ! def _get_report_data(self): ! """Return data sequence for report preview or output ! ! If the report cannot be run, return None ! ! """ if not self.updateTree(): ! return None # message boxes take focus away. remember currently focused widget # to regain the focus after message display. *************** *** 1582,1586 **** if _msg.show() != "ok": _focus.focus_set() ! return _data = () else: --- 1593,1597 ---- if _msg.show() != "ok": _focus.focus_set() ! return None _data = () else: *************** *** 1597,1603 **** )).show() _focus.focus_set() ! return _data = () _focus.focus_set() # build printout tree # Note: it is best to use same backend for both building and rendering. --- 1608,1621 ---- )).show() _focus.focus_set() ! return None _data = () _focus.focus_set() + return _data + + def _run_preview(self): + """Build and show the report""" + _data = self._get_report_data() + if _data is None: + return # build printout tree # Note: it is best to use same backend for both building and rendering. *************** *** 1635,1638 **** --- 1653,1685 ---- _focus.focus_set() + def printout(self): + """Build and save report printout""" + _data = self._get_report_data() + if _data is None: + return + if self.filename: + _filename = os.path.splitext(self.filename)[0] + else: + _filename = "" + _filetypes = [ + (self._("PythonReports Printouts"), ".prp"), + (self._("All Files"), "*"), + ] + if pdf: + _filetypes.insert(1, (self._("Adobe PDF Files"), ".pdf")) + _filename = tkFileDialog.asksaveasfilename( + initialfile=_filename, initialdir=(self.filedir or os.getcwd()), + filetypes=_filetypes, defaultextension=".prp") + if not _filename: + return + _printout = Builder(self.report).run(_data) + # printout must be validated before it can be saved + self._validate(_printout, prp.Printout) + # take output type from file extension + if pdf and _filename.lower().endswith(".pdf"): + pdf.write(_printout, _filename) + else: + _printout.write(_filename) + def run(argv=sys.argv): """Command line executable""" |