Printing from a text box etc

Richard Terry wrote:

Is there any other example in the demo beside the printframework which seems to print out graphics stuff, to help me understand:
a) how to printout the contents of a text control
b) How to send anything I want to directly to the printer.

The key to using the print framework or even to use the printer DCs directly you need to think about how you would draw the data if it were being viewed on screen in a window. Then you just use that same drawing code (with perhaps some scaling to deal with the different DPIs of the two kinds of devices) from within the printing framework as shown in the demo.

You can also bypass the framework and go directly to a wx.PrinterDC or a wx.PostScriptDC but if you need to do more than a single page or want to allow the user to preview or set printer options and etc. then I think the framework will be a bit easier. Here is an example of printing with a wx.PostScriptDC from within the PyShell on Linux:

>>> data = wx.PrintData()
>>> data.GetPrinterCommand()
u'lpr'
>>> data.SetPrintMode(wx.PRINT_MODE_PRINTER)
>>> ptr = wx.PostScriptDC(data)
>>> ptr.StartDoc("I am printing...")
True

ยทยทยท

ptr.StartPage()

>>> ptr.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL))
>>> ptr.DrawText("This is a test...", 50,100)
>>> ptr.EndPage()
>>> ptr.EndDoc()

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