开发者

How do you get the list data from a wxpyton gui click event?

I have a list ctrl box and I populate it with data.

self.listView1.Append([sFilename,sTitle,sArtist,sAlbum,sDestDir])

I created an event that triggers when a user clicks on a specific item in the list

def OnListView1ListItemSelected(se开发者_开发问答lf, event):
    print "onListViewSelect"

This works, but what I am stuck on is how do I capture the single line of data from the list the user clicked on?


Using wxPython 2.8.10, this is one way to drop the text from all columns in the selected row into a list. You're getting the object, selected index, number of columns, and then grabbing the text from each column:

def onListView1ListItemSelected(self, event):
    obj     = event.GetEventObject()
    index   = event.GetIndex()
    columns = obj.GetColumnCount()
    data    = []

    for i in range(columns):
        item = obj.GetItem(index, i)
        data.append(item.GetText())

    print(data)

I mentioned the version because I think the newest wxPython release allows you to specify a column in wx.ListCtrl.GetItemText, which could simplify things a bit. I haven't tried it though.


I think the simplest way is to just associate the data with the row. You can read about my approach here:

http://www.blog.pythonlibrary.org/2011/01/04/wxpython-wx-listctrl-tips-and-tricks/

Personally, I like ObjectListView the best: http://objectlistview.sourceforge.net/python/index.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜