2015-11-24 96 views
0

我有一個簡單的程序,允許用戶雙擊標籤並移動它。它完美地在Windows和Linux,但崩潰OSX上用不同:在OSX崩潰的wx python

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

沒有人能幫助我嗎? Pleeeeease – Psionman

回答

0

解決了它。

在該方法中RefreshSizerCell更換行:

oldItem.GetWindow().Destroy() 

oldItem.GetWindow().Hide() 
    self.mainSizer.Detach(oldItem.GetWindow()) 

不知道爲什麼一個方法適用於Linux/Windows的,而不是在OSX,而​​在所有3

其他作品