I'm probably doing something wrong, but the info I can find suggests that this:
buff = wx.EmptyBitmap(800, 600)
self.dc = wx.MemoryDC(buff)
gc=wx.GraphicsContext.Create(self.dc)
shouldn't crash; but it does, at the GraphicsContext.Create step.
There's no problem with GraphicsContext.Create in a ClientDC or a PaintDC,
self.dc=wx.ClientDC(self)
gc=wx.GraphicsContext.Create(self.dc)
works fine. And there's no problem with using a MemoryDC per se, if
I'm not using a GraphicsContext.
This is particularly awkward because (again if I understand correctly)
I need a MemoryDC to be able to print a GraphicsContext.
This is on an Intel Mac, MacOS10.4.8, Python 2.4, wxPython 2.8.1.1.
Here's a freestanding script that illustrates some of the things I've
tried. (I know the Blit won't work as is with the GraphicsContext,
but I can't get far enough to fix that anyway.)
#!/usr/local/bin/python2.4
import wx
class Canvas(wx.Panel):
def __init__(self,parent, id):
wx.Panel.__init__(self,parent,id)
menuBar=wx.MenuBar()
menu1 = wx.Menu()
menu1.Append(101, "&Blit!")
menuBar.Append(menu1, "DC")
parent.SetMenuBar(menuBar)
self.Bind(wx.EVT_PAINT, self.onPaintDC) #This works fine
#self.Bind(wx.EVT_PAINT, self.onPaintGC) #This crashes
self.Bind(wx.EVT_MENU, self.onBlit, id=101) #before calling
anything else
def onBlit(self,evt):
newDC=wx.ClientDC(self)
newDC.Blit(0,0,800,600,self.dc,0,0)
def onPaintDC(self,evt):
buff = wx.EmptyBitmap(800, 600)
self.dc = wx.MemoryDC(buff)
self.dc.SetBrush(wx.Brush("white"))
self.dc.DrawRectangle(0,0,800,600)
self.dc.SetPen(wx.Pen("black", 5))
self.dc.DrawLine(0,0,800,600)
def onPaintGC(self,evt):
buff = wx.EmptyBitmap(800, 600)
self.dc = wx.MemoryDC(buff)
#works fine when drawing to ClientDC
#self.dc=wx.ClientDC(self)
#Crashes here:
gc=wx.GraphicsContext.Create(self.dc)
gc.SetBrush(wx.Brush("white"))
gc.DrawRectangle(0,0,800,600)
gc.SetPen(wx.Pen("black", 5))
gc.StrokeLine(0,0,800,600)
app=wx.PySimpleApp()
frame=wx.Frame(None, wx.ID_ANY,title="TEST GC",size=(800,600))
canvas=Canvas(frame, wx.ID_ANY)
frame.Show()
app.MainLoop()
···
--
Ian York (iayork@gmail.com) <http://www.panix.com/~iayork/>
"-but as he was a York, I am rather inclined to suppose him a
very respectable Man." -Jane Austen, The History of England