Difficulty in Printing

Apparently I'm missing something as to how these objects relate...

With the code below I'm getting:

    1. A blank page sent to the appropriate printer
    2. Oops MessageBox is printed as the result (Error)

When I switch GetDC lines I get an error... NoneType does not have GetTextExtent.

Versions:
    python: 2.3.2
    wxPython: 2.4.2.4 for Python 2.3

You help is appreciated.

    def SendToPrinter(self,txt):
                  printdata = wxPrintData()
        printdata.SetPaperId(wxPAPER_LETTER)
               printdialog = wxPrintDialog(self.frame)
        printdialog.GetPrintDialogData().SetPrintData(printdata)
        printdialog.GetPrintDialogData().SetSetupDialog(True)
        printdialog.ShowModal()
        printdata = printdialog.GetPrintDialogData().GetPrintData()
               pdd = printdialog.GetPrintDialogData()
        pdd.SetPrintData(printdata)
        printer = wxPrinter(pdd) printout = wxPrintout()
        # dc = printout.GetDC()
        dc = wxPrinterDC(printdata)
        lineheight = dc.GetTextExtent('X')[1]
               dc.BeginDrawing()

        top_margin = 50
        lft_margin = 50
        row = 0
        col = 0
        for s in txt.split('\n'):
            dc.DrawText(s,col + lft_margin,(row * lineheight) + top_margin)
            row += 1

        dc.EndDrawing()
               if not printer.Print(self.frame,printout,False):
            wxMessageBox('Oops...')

Brad Larson wrote:

Apparently I'm missing something as to how these objects relate...

With the code below I'm getting:

   1. A blank page sent to the appropriate printer
   2. Oops MessageBox is printed as the result (Error)

When I switch GetDC lines I get an error... NoneType does not have GetTextExtent.

Versions:
   python: 2.3.2
   wxPython: 2.4.2.4 for Python 2.3

You help is appreciated.

   def SendToPrinter(self,txt):
                printdata = wxPrintData()
       printdata.SetPaperId(wxPAPER_LETTER) printdialog = wxPrintDialog(self.frame)
       printdialog.GetPrintDialogData().SetPrintData(printdata)
       printdialog.GetPrintDialogData().SetSetupDialog(True)
       printdialog.ShowModal()
       printdata = printdialog.GetPrintDialogData().GetPrintData()
             pdd = printdialog.GetPrintDialogData()
       pdd.SetPrintData(printdata)
       printer = wxPrinter(pdd) printout = wxPrintout()

You must derive a class from wxPrintout and implement your printing of each page by overriding its methods. See the PrintFramework sample in the demo.

       # dc = printout.GetDC()
       dc = wxPrinterDC(printdata)

The printout doesn't provide a DC until printing has actually begun. At that point it will call its On* methods and then you can call self.GetDC() from your overridden versions of those methods.

···

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