Robin Dunn:
Frank Niessink wrote:
Hi all,
I want my users to be able to print a selection of items (e.g. tasks). So, I enable setting the selection in the wx.PrintDialogData that is passed to the wx.Printer:
printout = Printout(self.viewer)
printDialogData = wx.PrintDialogData(printerSettings.printData)
printDialogData.EnableSelection(True)
printDialog = wx.Printer(printDialogData)
printDialog.Print(self.mainwindow, printout, prompt=True)Printout is a subclass of wx.html.HtmlPrintout.
If the user selects 'selection' in the print dialog, my Printout instance has to query the viewer for the current selection. I thought overriding one of the OnBegin... methods of wx.Printout (the superclass of wx.html.HtmlPrintout) should do the trick (as indicated by the wx.Printout documentation), but it seems these methods are never called? What am I missing?
Unfortunately the printout methods aren't overridable (in a Python class) from wx.html.HtmlPrintout. They probably could be made to allow it though...
Fortunately, I found an alternative solution that doesn't involve overriding (Html)Printout methods. It works by first showing the print dialog without actually printing, next querying the PrintDialogData, creating the Printout and then finally print the Printout without showing the dialog:
printDialogData = wx.PrintDialogData(printerSettings.printData)
printDialogData.EnableSelection(True)
printer = wx.Printer(printDialogData)
printer.PrintDialog(self.mainwindow)
printout = Printout(self.viewer,
printSelectionOnly=printer.PrintDialogData.Selection)
if printer.PrintDialogData.Selection:
printer.PrintDialogData.ToPage = printer.PrintDialogData.MaxPage
printer.Print(self.mainwindow, printout, prompt=False)
The only weird thing is that when I select the 'selection' radio box in the print dialog the ToPage property of the PrintDialogData is set to 1. This looks like a bug to me. Anyway, the simple work-around is to set ToPage back to MaxPage if Selection is True.
Cheers, Frank