[wxPython-dev] 20060902 test build uploaded

Robin Dunn robin at alldunn.com
Thu Sep 14 15:13:10 PDT 2006


jmf wrote:

>     def OnPrint(self, evt):
>         data = wx.PrintDialogData(self.pdata)
>         printer = wx.Printer(data)
>         text = self.tc.GetValue()
>         printout = TextDocPrintout(text, "title", self.margins)
>         useSetupDialog = True
>         #~ useSetupDialog = False
>         if not printer.Print(self, printout, useSetupDialog) \
>            and printer.GetLastError() == wx.PRINTER_ERROR:
>             wx.MessageBox(
>                 "There was a problem printing.\n"
>                 "Perhaps your current printer is not set correctly?",
>                 "Printing Error", wx.OK)
>         else:
>             data = printer.GetPrintDialogData()
>             self.pdata = wx.PrintData(data.GetPrintData()) # force a copy
>         printout.Destroy()
> 

> 4) Launch the print process, with a <wx.Printer>.print(...).
> This is the tricky part. wxWidgets/wxPython with the help of the
> installed printing drivers will build a setup dialog window with a "print
> button" and the user will print from there.
> The previously defined printdata are not used for the real printing job,
> but are used in the display (and the setup) of the setup dialog.

> 5) Launch the print with the print button.
> At this time, it seems the real printing is using some "other internal
> printdata" from this setup dialog window. 

The wx.PrintDialogData makes a opy of the wx.PrintData object passed to 
its constructor, and that printdata is used for the dialog and the 
print.  You can then get your own copy of that printdata after the print 
is done as shown above on the "force a copy" line.


> Indeed, it is still possible
> to modify the printing setup, like orientation, resolution, ... (The
> PDFCreator was a big help).
> 
> This two-step process is a nice design. It let the user choose the
> printer and define the print options.
> 
> The negative side effect of this approach: it seems impossible to
> have a direct printing, bypassing the setup dialog and using the
> default printer. If, in the above example, I set useSetupDialog = False,
> printing will not work - nothing will be printed, 

As I mentioned the other day in the "Problems with batch printing" 
thread in wxPython-users, you just need to preserve a copy of the 
wx.PrintDialogData from a prior print that did use the print dialog, or 
properly initialize a new instance, and then you should be able to do 
dialog-less printing.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-dev mailing list