2010-08-31 70 views
2

我是Pythong的新手,我一直试图在UltimateListCtrl中获得一个按钮。我仍然无法弄清楚我做错了什么。这里是我的代码:使用wxPython在UltimateListCtrl中放置一个按钮

try: 
    from agw import ultimatelistctrl as ULC 
except ImportError: # if it's not there locally, try the wxPython lib. 
    from wx.lib.agw import ultimatelistctrl as ULC 


self.table = ULC.UltimateListCtrl(self, -1, agwStyle=ULC.ULC_REPORT| 
              ULC.ULC_HAS_VARIABLE_ROW_HEIGHT) 

self.table.InsertColumn(0, "Name") 
self.table.InsertColumn(1, "Size") 
self.table.InsertColumn(2, "Download") 


for i in range(0, len(masterlist)): 
    pos = self.table.InsertStringItem(i,str(masterlist[i]['name'])) 
    self.table.SetStringItem(pos, 1,str(masterlist[i]['size'])) 
    button = wx.Button(self, id=i, label="Download") 
    self.table.SetItemWindow(pos, col=2, wnd=button, expand=True) 

masterlist是一个下载项目的列表。

我得到这个回溯:

Traceback (most recent call last): 
File "E:\TestApp.py", line 67, in Display 
self.table.SetItemWindow(pos, col=5, wnd=button, expand=True) 
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\ultimatelistctrl.py", line 12961, in SetItemWindow 
return self._mainWin.SetItemWindow(item, wnd, expand) 
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\ultimatelistctrl.py", line 9021, in SetItemWindow 
item.SetWindow(wnd, expand) 
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\ultimatelistctrl.py", line 1863, in SetWindow 
mainWin = listCtrl._mainWin 
AttributeError: 'MainWindow' object has no attribute '_mainWin' 
+0

什么是您传递给SetItemWindow的“pos”?发布你的整个相关代码,不只是这个小样本 – 2010-08-31 21:14:23

+0

对不起,错过了这个变量。这应该是相关的一切。 – FlowofSoul 2010-08-31 21:24:34

回答

3

button的父母应该是你ULCself.table

因此改变这一行:

button = wx.Button(self, id=wx.ID_ANY, label="Download") 

这样:

button = wx.Button(self.table, id=wx.ID_ANY, label="Download") 

更新响应评论:

出于某种原因,它不似乎是可以删除与 DeleteAllItems()方法,如果任何项目含有小部件在ULC的所有项目,以便改用DeleteItem()

def emptyList(self) 
    itemCount = self.list.GetItemCount() 
    for item in xrange(itemCount): 
     self.list.DeleteItem(0) 
+0

谢谢,这很好。 – FlowofSoul 2010-08-31 22:39:42

+0

很高兴在这里呢! – volting 2010-08-31 22:57:26

+0

当我尝试“self.table.DeleteAllItems()”我得到这个错误消息:wx._core.PyDeadObjectError:Button对象的C++部分已被删除,不再允许属性访问。你知道如何解决这个问题吗?我没有看到开放另一个问题的意义。 – FlowofSoul 2010-09-01 03:39:12