Problems with batch printing

Jürgen Kareta python at kareta.de
Mon Sep 11 07:41:29 PDT 2006


Hi Robin,

I build a application for printing parts lists for one of my customers. 
They like to have some kind of batch printing functionality which means 
reading some parts list numbers from a file and print them out without 
further user interaction.

I took the printing example of your book (chapter 17) and modified it 
for my needs. For the first list in batch print the print dialog appears 
and for the following list it should not. But the following lists will 
not be printed and I got  entries in the event log:

    Win32 error code returned by the print processor: 259 (0x103)

Tried it with three printers on two different networks, so I'm sure the 
problem is inside my code.
(python 2.4.2, wxpython 2.6.2.1 on wk2 sp4 and on XP sp3)

If you like to verify what I mean please cut your sample_text that it 
fits on one page and take the
On_print method below.  I'm a little surprised because you suggest such 
a solution with your
'force a copy' comment at the end of the method. But anyway, tried 
several other thinks without success.
Do you have some hints how I can implement this kind of batch printing ?

If the dialog is shown on every loop, it works fine, but that's not 
batch printing.

Thanks for your efford,
Jürgen

<code>
def OnPrint(self, evt):
        for counter in range(0,3):                                    
                      ## just let it print three times
            data = wx.PrintDialogData(self.pdata)
            printer = wx.Printer(data)
            text = self.tc.GetValue()
            printout = TextDocPrintout(text, "title", self.margins)
            if counter == 0:                                             
                     ## first time show the dialog
                useSetupDialog = True
            else:
                useSetupDialog = False                                 
                  ## otherwise not
            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()
</code>




More information about the wxpython-users mailing list