这让我的智慧结束了。我对wxPython相对比较陌生,而且我正在编辑别人的代码,所以请随身携带。 在我的程序中,我有一个图像(位图)加载到一个wxScrolledWindow。我试图在图像上绘制一个网格,但我无法实现它的工作。我的工作是将这个程序从Windows上移植过来,它最初是在Windows上开发的,并且使它可以在Mac上工作,但这比我预期的要更加痛苦。wxPython中的Mac OSX 10.8.5上的Paint Event问题
def OnPaint(self, event):
dc = wx.BufferedPaintDC(self.staticBitmap,self.staticBitmap.GetBitmap())
dc.Clear()
dc.DrawBitmap(self.wxBitmap, 0, 0)
self.drawGrid(dc)
event.Skip()
def drawGrid(self, dc):
gridWid, gridHgt = self.staticBitmap.GetBitmap().GetSize()
numRows, numCols = self.gridSize, self.gridSize
if self.controlPanel.showGridBox.IsChecked():
dc.SetPen(wx.Pen(self.gridColor, self.gridThickness))
dc.SetTextForeground(self.gridColor)
cellWid = float(gridWid - 1)/numRows
cellHgt = float(gridHgt - 1)/numCols
for rowNum in xrange(numRows + 1) :
dc.DrawLine(0, rowNum*cellHgt, gridWid, rowNum*cellHgt)
for colNum in xrange(numCols + 1) :
dc.DrawLine(colNum*cellWid, 0, colNum*cellWid, gridHgt)
此代码在Windows 7上就好了,但我一直在Mac上运行它时,收到此错误:
Traceback (most recent call last):
File "/Users/kyra/Documents/workspace/ADAPT/src/GUI.py", line 1617, in OnPaint
dc = wx.BufferedPaintDC(self.staticBitmap, self.staticBitmap.GetBitmap())
File "/usr/local/lib/wxPython-3.0.2.0/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/_gdi.py", line 5290, in __init__
_gdi_.BufferedPaintDC_swiginit(self,_gdi_.new_BufferedPaintDC(*args, **kwargs))
wx._core.PyAssertionError: C++ assertion "window->MacGetCGContextRef() != NULL" failed at /BUILD/wxPython-src-3.0.2.0/src/osx/carbon/dcclient.cpp(195) in wxPaintDCImpl(): using wxPaintDC without being in a native paint event
self.staticBitmap是wxStaticBitmap,并self.wxBitmap是完全相同的图片。我的猜测是它可能与GraphicsContext有关,也许?有一个类似的问题在这里问:How to send PaintEvent in wxpython但这并没有帮助我。我做了他们用self.Refresh()提出的建议,但是我也遇到了同样的错误。为什么这会在Windows上工作,而不是在Mac上?似乎没有绘画出现在图像上。
您可能希望将其发布到https://groups.google.com/forum/#!forum/wxpython-users组或https://groups.google.com/forum/#!forum/wxpython-mac – 2015-01-26 20:54:37
谢谢,贴在那里以及:) – Kyra 2015-01-27 17:06:48