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...')