Printing in wxPython
zhitenev at cs.vsu.ru
Sat Mar 29 10:50:36 CET 2003
"Anand B Pillai" <abpillai at lycos.com> wrote in message:
news:bd993a2f.0303280717.3f7a19d at posting.google.com...
> Moreover the python interpreter gives a NameError for the methods
> wxPrintout_GetDC() and wxPrintout_OnBeginDocument(). What I am trying
Certainly, wxPrintout_GetDC() doesn't exist. You can get a dc by issuing
self.GetDC(), or wxPrintout.GetDC(self).
> wxPython note: If this method is overridden in a Python class then
> the base class version can be called by using the
> methodbase_OnBeginDocument(startPage, endPage).
A bit mistaken: <Quote>
wxPython note: If this method is overridden in a Python class then the base
class version can be called by using the method
Note the ' ' between method and base. You have to call method which name is
'base_OnBeginDocument(startPage, endPage)'. Don't be confused.
> The printing example given is also very confusing. It is not very clear
> how the device context of the current window is passed to the printer.
> It would be helpful if anyone who has got it right could enlighten. :-)
You don't need to pass a device context to your document dc. You have to
_draw_ on this dc.
You issue BeginDoc, draw on a printer DC, issue EndDoc, and after that
printer prints what you have drawn on this DC between BeginDoc and EndDoc.
In your particular example, you have to copy the information from your
panel's DC to Printer DC. See DC method Blit. I can give you only a rough
def OnPrintPage(self, pgno):
dc = self.GetDC()
pandc = self.panel1.GetDC()
sz = pandc.GetSizeTuple()
dc.Blit(0,0, sz, sz, 0, 0, pandc)
This should print the content of your panel without zooming (if there are no
errors). Remember that screen resolution and printer resolution are very
different (72dpi and 300 dpi, e.g.). You may have to zoom your drawings. See
also wxDC.SetUserScale and wxMemoryDC.
> Thanks for your help,
I am glad to help you.
> Anand Pillai
More information about the Python-list