I use the printing framework as shown in the demo:
def OnPrintPage(self, page):
dc = self.GetDC()
...
Then I use my own drawing function which uses a GraphicsContext. This works well for the print preview window (GetDC() returns a MemoryDC) but does not work with the printing process itself (GetDC() return a PrintDC, which GraphicsContext.Create() does not like..).
Do I need to store the GC as bitmap buffer (and if yes, how?) and then render it on the PrintDC or is there a more elegant way?
GraphicsContext is eventually going to be able to have a way to target a printer, but currently you'll need to do it something like you mention. You simply need to select a bitmap into a MemoryDC and use that as the target of the GrpahicsContext.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
GraphicsContext is eventually going to be able to have a way to target a
printer, but currently you'll need to do it something like you mention.
You simply need to select a bitmap into a MemoryDC and use that as the
target of the GrpahicsContext.
# initializing a buffer bmp and a MemoryDC drawing on t
buff = wx.EmptyBitmap(800, 600)
mdc = wx.MemoryDC(buff)
# some test GC code
gc = wx.GraphicsContext.Create(mdc)
gc.SetBrush(wx.Brush("white"))
gc.DrawRectangle(0,0,800,600)
gc.SetPen(wx.Pen("black", 5))
gc.StrokeLine(0,0,800,600)
# testing if the bmp works
buff.SaveFile("test.png", wx.BITMAP_TYPE_PNG) # it does..
# drawing the buffer onto the DC
dc.DrawBitmap(buff, 0, 0) # does not work..
The bitmap needs to be unselected from the memory dc before you can use it for drawing to another dc. Or you can save a step and use Blit to move the pixels from mdc to dc.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!