Using a wxFrame as a "Printing-Template"

Hi everybody!

This is my first post to this list.

I'm trying to make a "Printing-Template" with the GUI in BOA-..
in W2K with Python 2.2.2, wxPython 2.4.0.7 and a fresh CVS-version of BOA-..

Is it possible to get/paint a wxPrinterDC with contents from a wxFrame
"painted"
with ordinary objects like wxStaticText, wxStaticBitmap and wxStaticLine?

This wxFrame (template) isn't shown ( I only create it tempory with
MyFrameTemplate.create(self) ).
I tried to do things like create a wxBufferedDC before _init_ctrls in _init_
of the "Boa-Frame"
and also added an OnPaint event and a DoDrawing method (with "Blit-magic")
to be able
to follow the Demo example "PrintFramework" (based on wxScrolledWindow)...

I'm totaly lost now!!

Does anybody got some hints (if it's possible to do it)?

When I started to dig into this, I thought that I could get a copy with
something like:
    context = wxClientDC( MyFrameTemplate )
and copy it into the DC created with self.GetDC() in
MyPrintout(wxPrintout):OnPrintPage
with some "Blit-method".

Like this:
.
.
.
import MyFrameTemplate

class Main(wxFrame):
    .
    .
    .
    def OnSysprintbtnButton(self, event):
        printData = wxPrintData()
        printData.SetPaperId(wxPAPER_A4)
        ft = MyFrameTemplate.create(self)
        printout = MyPrintout( ft )
        printout2 = MyPrintout( ft )
        preview = wxPrintPreview(printout, printout2, printData)
        pvframe = wxPreviewFrame(preview, self, "This is a print preview")
        if not preview.Ok():
            print("Houston, we have a problem...\n")
            return
        pvframe.Initialize()
        pvframe.SetPosition(self.GetPosition())
        pvframe.SetSize(self.GetSize())
        pvframe.Show(True)

class MyPrintout(wxPrintout):
    def __init__(self, frame):
       wxPrintout.__init__(self)
       self.frame = frame
   .
   .
   .
   def OnPrintPage(self, page):
        dc = self.GetDC()

        # This "block" is only about scaling
        (fmaxX, fmaxY) = self.frame.GetClientSizeTuple()
        marginX = 50
        marginY = 50
        maxX = fmaxX + (2 * marginX)
        maxY = fmaxY + (2 * marginY)
        (w, h) = dc.GetSizeTuple()
        scaleX = float(w) / maxX
        scaleY = float(h) / maxY
        actualScale = min(scaleX, scaleY)
        posX = (w - (fmaxX * actualScale)) / 2.0
        posY = (h - (fmaxY * actualScale)) / 2.0
        dc.SetUserScale(actualScale, actualScale)
        dc.SetDeviceOrigin(int(posX), int(posY))

        context = wxClientDC( self.frame )
        memory = wxMemoryDC()
        bitmap = wxEmptyBitmap( fmaxX, fmaxY, -1 )
        memory.SelectObject( bitmap )
        memory.Blit( 0, 0, fmaxX, fmaxY, context , 0, 0)
        memory.SelectObject( wxNullBitmap )
        dc.DrawBitmap( bitmap, 0, 0, True )
        dc.DrawText("Page: %d" % page, marginX/2, maxY-marginY)
.
.
.

The result is some strange "screenshot" from my desktop in the preview :frowning:

TIA
Claes Ström

Claes Ström wrote:

Hi everybody!

This is my first post to this list.

I'm trying to make a "Printing-Template" with the GUI in BOA-..
in W2K with Python 2.2.2, wxPython 2.4.0.7 and a fresh CVS-version of BOA-..

Is it possible to get/paint a wxPrinterDC with contents from a wxFrame
"painted"
with ordinary objects like wxStaticText, wxStaticBitmap and wxStaticLine?

Normally you can't (and rightly so) make native controls draw themselves on a specific DC. Probably the closest you could get is something like a screenshot, create a wxWindowDC for the window and blit from it to a wxMemoryDC and then you'll have a snapshot of the window in the selected bitmap.

But this is probably not what you want. You should really just draw all the text and other items yourself directly to the wxPrinterDC...

···

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