开发者

Changing contents of currently displayed listbox in urwid/python2.6

I'm writing a music player in python, with a cli using urwid. I intend to have the current playlist in a simpleListWalker, wrapped by a listbox, then columns, a pile, and finally a frame.

How do I replace the entire contents of this listbox (or simpleListWalker) with something else?

Relevant code:

class mainDisplay(object):
...
    def renderList(self):
       songList = db.getListOfSongs()
       songDictList = [item for item in songList if item['location'] in 
       commandSh.currentPlaylists[commandSh.plyr.currentList]]
       self.currentSongWidgets = self.createList(songDictList)
      开发者_如何学编程 self.mainListContent = urwid.SimpleListWalker([urwid.AttrMap(w, None, 
       'reveal focus') for w in self.currentSongWidgets])
    def initFace(self):#this is the init function that creates the interface
        #on startup
        ...
        self.scanPlaylists()
        self.renderList()
        self.mainList = urwid.ListBox(self.mainListContent)
        self.columns = urwid.Columns([self.mainList, self.secondaryList])
        self.pile = urwid.Pile([self.columns, 
        ("fixed", 1, self.statusDisplayOne), 
        ("fixed", 1, self.statusDisplayTwo), 
        ("fixed", 1, self.cmdShInterface)], 3)
        self.topFrame = urwid.Frame(self.pile)

Full code at: http://github.com/ripdog/PyPlayer/tree/cli - Check main.py for interface code.

The code is in a pretty bad state right now, and I've only been programming for two months. Any suggestions on code style, layout, or any other tips you may have are very much appreciated.


self.mainListContent[:] = [new, list, of, widgets]

should replace the whole list of widgets in place.

Next time post your question to the mailing list or the IRC channel if you want a faster response!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜