def OnPrintPreview(self, event): """ Define the method that implements Print Preview """ # Convert the Note Text (in plain text format) into the form needed for the # TranscriptPrintoutClass's Print Preview display. (This creates graphic and pageData) (graphic, pageData) = TranscriptPrintoutClass.PrepareData(TransanaGlobal.printData, noteTxt = self.txt.GetValue()) # Pass the graph can data obtained from PrepareData() to the Print Preview mechanism TWICE, # once for the preview and once for the printer. printout = TranscriptPrintoutClass.MyPrintout('', graphic, pageData) printout2 = TranscriptPrintoutClass.MyPrintout('', graphic, pageData) # use wxPython's PrintPreview object to display the Print Preview. self.preview = wx.PrintPreview(printout, printout2, self.printData) # Check to see if the Print Preview was properly created. if not self.preview.Ok(): # If not, display an error message and exit self.SetStatusText(_("Print Preview Problem")) return # Calculate the best size for the Print Preview window theWidth = max(wx.Display(TransanaGlobal.configData.primaryScreen).GetClientArea()[2] - 180, 760) # wx.ClientDisplayRect() theHeight = max(wx.Display(TransanaGlobal.configData.primaryScreen).GetClientArea()[3] - 200, 560) # wx.ClientDisplayRect() # Create the dialog to hold the wx.PrintPreview object frame2 = wx.PreviewFrame(self.preview, TransanaGlobal.menuWindow, _("Print Preview"), size=(theWidth, theHeight)) frame2.Centre() # Initialize the frame so it will display correctly frame2.Initialize() # Finally, we actually show the frame! frame2.Show(True)
def OnPrint(self, event): """ Define the method that implements Print """ # Convert the Note Text (in plain text format) into the form needed for the # TranscriptPrintoutClass's Print Preview display. (This creates graphic and pageData) (graphic, pageData) = TranscriptPrintoutClass.PrepareData(TransanaGlobal.printData, noteTxt = self.txt.GetValue()) # Pass the graph can data obtained from PrepareData() to the Print Preview mechanism ONCE printout = TranscriptPrintoutClass.MyPrintout('', graphic, pageData) # Create a Print Dialog Data object pdd = wx.PrintDialogData() # Populate the Print Dialog Data with the global print data pdd.SetPrintData(self.printData) # Define a wxPrinter object with the Print Dialog Data printer = wx.Printer(pdd) # Send the output to the printer. If there's a problem ... if not printer.Print(self, printout): # ... create and display an error message dlg = Dialogs.ErrorDialog(None, _("There was a problem printing this report.")) dlg.ShowModal() dlg.Destroy() # Finally, destroy the printout object. printout.Destroy()
def CallDisplay(self): """ Call the parent method (passed in during initialization) that populates the report """ # Get the paper size from the TranscriptPrintoutClass (paperWidth, paperHeight) = TranscriptPrintoutClass.GetPaperSize() # Get the current height of the report window height = self.GetSize()[1] # Turn off the size hints, so we can resize the window self.SetSizeHints(-1, -1, -1, -1) # We need to adjust the size of the display slightly depending on platform. if '__WXMAC__' in wx.PlatformInfo: # GetPaperSize() is based on PRINTER, not SCREEN resolution. We need to adjust this on the mac, changing from 72 DPI to 96 DPI paperWidth = int(paperWidth * 4 / 3) # Adjust the page size for the right margin and scroll bar sizeAdjust = 48 # Set the size of the report so that it matches the width of the paper being used (plus the # line number area and the scroll bar) self.SetSize( (paperWidth + self.reportText.lineNumberWidth + sizeAdjust, height)) # Set Size Hints, so the report can't be resized. (This may not be practical for large paper on small monitors.) self.SetSizeHints(self.GetSize()[0], int(self.GetSize()[1] * 0.8), self.GetSize()[0], -1) # Center on the screen TransanaGlobal.CenterOnPrimary(self) # CallDisplay() ALWAYS makes the report Read Only, so change the EDIT button state to NO EDIT ... self.toolBar.ToggleTool(T_FILE_EDIT, False) # ... and make the report read-only. self.reportText.SetReadOnly(True) # Disable the Font items self.toolBar.EnableTool(T_FILE_FONT, False) # The Menu does not exist on the Mac ... if not '__WXMAC__' in wx.PlatformInfo: # ... but if we're not on the Mac, disable it! self.menuFile.Enable(M_FILE_FONT, False) # Clear the Report self.reportText.ClearDoc() # If a Display Method has been defined ... if self.displayMethod != None: # ... call it. self.displayMethod(self.reportText) # Move the cursor to the beginning of the report self.reportText.GotoPos(0) # Bring the Report to the top so it will definitely be visible self.Raise()
def __init__(self, dbTree, sel): # Set the Cursor to the Hourglass while the report is assembled TransanaGlobal.menuWindow.SetCursor(wx.StockCursor(wx.CURSOR_WAIT)) try: # Build the title and subtitle title = _('Collection Summary Report') if dbTree.GetPyData(sel).nodetype == 'SearchCollectionNode': reportType = _('Search Result Collection') else: reportType = _('Collection') prompt = '%s: %s' if 'unicode' in wx.PlatformInfo: # Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data. reportType = unicode(reportType, 'utf8') prompt = unicode(prompt, 'utf8') subtitle = prompt % (reportType, dbTree.GetItemText(sel)) # Prepare the Transcript for printing (graphic, pageData) = TranscriptPrintoutClass.PrepareData( TransanaGlobal.printData, collectionTree=dbTree, collectionNode=sel, title=title, subtitle=subtitle) # If there's data inthe report... if pageData != []: # Send the results of the PrepareData() call to the MyPrintout object, once for the print preview # version and once for the printer version. printout = TranscriptPrintoutClass.MyPrintout( title, graphic, pageData, subtitle=subtitle) printout2 = TranscriptPrintoutClass.MyPrintout( title, graphic, pageData, subtitle=subtitle) # Create the Print Preview Object printPreview = wx.PrintPreview(printout, printout2, TransanaGlobal.printData) # Check for errors during Print preview construction if not printPreview.Ok(): dlg = Dialogs.ErrorDialog(None, _("Print Preview Problem")) dlg.ShowModal() dlg.Destroy() else: # Create the Frame for the Print Preview # The parent Frame is the global Menu Window theWidth = max(wx.ClientDisplayRect()[2] - 180, 760) theHeight = max(wx.ClientDisplayRect()[3] - 200, 560) printFrame = wx.PreviewFrame(printPreview, TransanaGlobal.menuWindow, _("Print Preview"), size=(theWidth, theHeight)) printFrame.Centre() # Initialize the Frame for the Print Preview printFrame.Initialize() # Restore Cursor to Arrow TransanaGlobal.menuWindow.SetCursor( wx.StockCursor(wx.CURSOR_ARROW)) # Display the Print Preview Frame printFrame.Show(True) else: # Restore Cursor to Arrow TransanaGlobal.menuWindow.SetCursor( wx.StockCursor(wx.CURSOR_ARROW)) # If there are no clips to report, display an error message. if 'unicode' in wx.PlatformInfo: # Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data. prompt = unicode( _('Collection "%s" has no Clips for the Collection Summary Report.' ), 'utf8') else: prompt = _( 'Collection "%s" has no Clips for the Collection Summary Report.' ) dlg = wx.MessageDialog(None, prompt % dbTree.GetItemText(sel), style=wx.OK | wx.ICON_EXCLAMATION) dlg.ShowModal() dlg.Destroy() finally: # Restore Cursor to Arrow TransanaGlobal.menuWindow.SetCursor(wx.StockCursor( wx.CURSOR_ARROW))