开发者

Placing a Button in UltimateListCtrl using wxPython

I'm new to Pythong and I have been trying to get a button within UltimateListCtrl. I still can't figure out what I'm doing wrong. Here is my code:

try:
    from agw import ultimatelistctrl as ULC
except ImportError: # if it's not there locally, try the wxPython lib.
    from wx.lib.agw import ultimat开发者_运维问答elistctrl 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 is a list of download items.

I get this traceback:

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'


button's parent should be your ULC i.e self.table

So change this line:

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

to this:

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

Update in response to comment:

For some reason it doesn't seem to be possible to delete all items in a ULC with the DeleteAllItems() method if any of the items contain widgets so instead use DeleteItem().

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜