Printing in wxPython

Anand B Pillai abpillai at lycos.com
Fri Mar 28 10:17:00 EST 2003


Hi

 Can anyone post some sample code on printing in wxPython ?
 I want to print a wxBitmap displayed in a window(a wxPanel).
 I went through the printing sample of wxWindows in C++, but looks 
 like there is no similar example for python.

  I am following the printing guidelines and deriving my printout
  class from wxPrintout. But the problem is how do I pass a device
  context to it ? I cannot understand how I can pass the bitmap of
  my wxPanel to the printer device context of the wxPrintout class.
  
  Here is a snippet of my code.

  class MyPrintout(wxPrintout):

       ...
       def OnPrintPage(self, pgno):
           dc = wxPrintout_GetDC()
           #What to do with this dc ?
       
       def OnBeginDocument(self, pgstart, pgend):
           if not wxPrintout_OnBeginDocument(pgstart, pgend):
               return FALSE
           return TRUE 

  Moreover the python interpreter gives a NameError for the methods
wxPrintout_GetDC() and wxPrintout_OnBeginDocument(). What I am trying
to do is call the method of the parent class wxPrintout in my
PrintPage() method. I think
that I should not be getting this error! :-#

    Quoting from the wxPython documentation:

<Quote>
bool OnBeginDocument(int startPage, int endPage)

Called by the framework at the start of document printing. Return
FALSE from this function cancels the print job. OnBeginDocument is
called once for every copy printed.

The base wxPrintout::OnBeginDocument must be called (and the return
value checked) from within the overridden function, since it calls
wxDC::StartDoc.

 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).
</Quote>

 According to this, I should not be getting both the errors.
 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. :-)
 
Thanks for your help,

Anand Pillai




More information about the Python-list mailing list