ultimatelistctrl:列表索引超出范围

时间:2015-10-24 20:42:57

标签: python wxpython

我在wxPython中使用UltimateListCtrl。我可以在Mouse vs Python上获得演示代码,但是当我尝试调整它时。或者,即使将其复制并粘贴到我的程序中,也会失败:

Traceback (most recent call last):
File "C:\Users\dgunter\Documents\GitHub\TimeJobTracker\timejob.py", line 346, in ArchiveJobs
jobwin = ArchiveJobWindow(self)
File "C:\Users\dgunter\Documents\GitHub\TimeJobTracker\timejob.py", line 87, in __init__
mylist.SetStringItem(0, 1, "Go")
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\lib\agw\ultimatelistctrl.py", line 11366, in SetStringItem
self._mainWin.SetItem(info)
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\lib\agw\ultimatelistctrl.py", line 8802, in SetItem
line.SetItem(item._col, item)
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\lib\agw\ultimatelistctrl.py", line 4095, in SetItem
item = self._items[index]
IndexError: list index out of range

以下是我正在使用的代码,您会注意到列表项是从我给出的链接中复制的。我的实际数据是从数据库中加载的,我刚离开那部分。

import wx
from wx.lib.agw import ultimatelistctrl as ULC

class ArchiveJobWindow(wx.Frame):
    def __init__(self, parent):
        super(ArchiveJobWindow, self).__init__(parent, title='Archive Unused Jobs', style=wx.CAPTION, size=(650,350))

        self.parent = parent
        self.panel = wx.Panel(self, wx.ID_ANY)
        topSizer = wx.BoxSizer(wx.VERTICAL)
        buttonSizer = wx.BoxSizer(wx.HORIZONTAL)

        font = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
        boldfont = wx.SystemSettings_GetFont(wx.SYS_DEFAULT_GUI_FONT)
        boldfont.SetWeight(wx.BOLD)
        boldfont.SetPointSize(12)


        mylist = ULC.UltimateListCtrl(self.panel, agwStyle=wx.LC_REPORT|wx.LC_VRULES|wx.LC_HRULES|wx.LC_SINGLE_SEL|0x0010, size=(200, 100))

        info = ULC.UltimateListItem()
        info._mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE | wx.LIST_MASK_FORMAT | ULC.ULC_MASK_CHECK
        info._image = []
        info._format = 0
        info._kind = 1
        info._text = "Artist Name"
        mylist.InsertColumnInfo(0, info)

        info = ULC.UltimateListItem()
        info._format = wx.LIST_FORMAT_RIGHT
        info._mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE | wx.LIST_MASK_FORMAT | ULC.ULC_MASK_FONT
        info._image = []
        info._text = "Title"
        info._font = boldfont
        mylist.InsertColumnInfo(1, info)

        info = ULC.UltimateListItem()
        info._mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE | wx.LIST_MASK_FORMAT
        info._format = 0
        info._text = "Genre"
        info._font = font
        info._image = []
        mylist.InsertColumnInfo(2, info)

        mylist.InsertStringItem(0, "Newsboys")
        mylist.SetStringItem(0, 1, "Go")
        mylist.SetStringItem(0, 2, "Rock")

        mylist.InsertStringItem(1, "Puffy")
        mylist.SetStringItem(1, 1, "Bring It!")
        mylist.SetStringItem(1, 2, "Pop")

        mylist.InsertStringItem(2, "Family Force 5")
        mylist.SetStringItem(2, 1, "III")
        mylist.SetStringItem(2, 2, "Crunk")

        mylist.SetColumnWidth(0, 150)
        mylist.SetColumnWidth(1, 200)
        mylist.SetColumnWidth(2, 100)


        cancelbutton = wx.Button(self.panel, id=wx.ID_CANCEL)
        Okbutton = wx.Button(self.panel, id=wx.ID_OK)




        # panelSizer.Add(self.panel, 1, wx.EXPAND)
        buttonSizer.AddStretchSpacer(6)
        buttonSizer.Add(cancelbutton, 1, wx.ALIGN_RIGHT, 0)
        buttonSizer.Add((20,0))
        buttonSizer.Add(Okbutton, 1, wx.ALIGN_RIGHT, 0)
        buttonSizer.AddStretchSpacer(1)

        topSizer.AddStretchSpacer(2)
        topSizer.Add(mylist)
        topSizer.AddStretchSpacer(2)
        topSizer.Add(buttonSizer, 1, wx.ALIGN_RIGHT, 0)
        topSizer.Add((0,20))
        # panelSizer.Add(topSizer, 1, wx.EXPAND)
        self.panel.SetSizer(topSizer)


app = wx.App(False)
window = ArchiveJobWindow(None)
window.Show()


app.MainLoop()

欢迎任何建议。

由于

1 个答案:

答案 0 :(得分:1)

我不明白为什么,但是如果你改变这一行就可以了:

mylist = ULC.UltimateListCtrl(self.panel, agwStyle=wx.LC_REPORT|wx.LC_VRULES|wx.LC_HRULES|wx.LC_SINGLE_SEL|0x0010, size=(200, 100))

到此:

mylist = ULC.UltimateListCtrl(self.panel, agwStyle=ULC.ULC_REPORT, size=(200, 100))

它使得因为为了让示例甚至运行我必须添加0x0010

我认为这些例子必须过时。