我有一个简单的程序,允许用户双击标签并移动它。它在Windows和Linux上运行良好,但在OSX上崩溃的各种各样:
Segmentation fault: 11
或有时
Bus error: 10
有人可以帮忙吗?该计划如下:
import wx
class DoubleClick(wx.Frame):
def __init__(self, parent, title):
super(DoubleClick, self).__init__(parent, title=title,
size=(250, 200))
self.mainSizer=wx.GridBagSizer()
self.Available=['square','circle','cross','triangle']
self.Used=[]
self.SetSizer(self.mainSizer)
self.Center()
self.Show()
self.DisplayShapes()
def RefreshSizerCell(self, item, row, column):
oldItem=self.mainSizer.FindItemAtPosition((row, column))
if (oldItem !=None) and oldItem.IsWindow():
oldItem.GetWindow().Destroy()
pass
self.mainSizer.Add(item, pos=(row, column), flag=wx.TOP|wx.LEFT|wx.RIGHT, border=10)
self.Layout()
self.Fit()
def onAvailableDClick(self, e):
if len(self.Available)>0:
shape=self.GetShapeName(e)
self.Used.append(str(shape))
self.Available.remove(shape)
self.DisplayShapes()
def onUsedDClick(self, e):
if len(self.Used)>0:
shape=self.GetShapeName(e)
self.Available.append(str(shape))
self.Used.remove(shape)
self.DisplayShapes()
def DisplayShapes(self):
availableSizer=ShapeDisplay(self, self.Available, self.onAvailableDClick)
self.RefreshSizerCell(availableSizer,0,0)
usedSizer=ShapeDisplay(self, self.Used, self.onUsedDClick)
self.RefreshSizerCell(usedSizer,1,0)
def GetShapeName(self, event):
imgCtrl=event.GetEventObject()
shape=imgCtrl.GetName()
return shape
class ShapeDisplay(wx.Panel):
def __init__(self, parent, shapeList, bindTo):
wx.Panel.__init__(self, parent, id=wx.ID_ANY)
shapeSizer=wx.GridBagSizer()
shapePos=0
for ii in range(0, len(shapeList)):
shape=shapeList[ii]
lblShape=wx.StaticText(self, label=shape, name=shape)
lblShape.Bind(wx.EVT_LEFT_DCLICK, bindTo)
shapeSizer.Add(lblShape, pos=(0,shapePos), flag=wx.LEFT, border=5)
shapePos+=1
self.SetSizer(shapeSizer)
if __name__ == '__main__':
myApp = wx.App()
DoubleClick(None, title='Double click')
myApp.MainLoop()
答案 0 :(得分:0)
解决了它。
在方法RefreshSizerCell中替换以下行:
oldItem.GetWindow().Destroy()
与
oldItem.GetWindow().Hide()
self.mainSizer.Detach(oldItem.GetWindow())
不确定为什么一种方法适用于Linux / Windows而不适用于OSX,而另一种适用于所有3种方法