我正在使用Python编写一个音乐播放器,使用urwid作为cli。我打算将当前的播放列表放在simpleListWalker中,由listbox包装,然后是columns、pile和最后是frame。
我该如何用其他内容替换这个listbox(或simpleListWalker)的全部内容?
相关代码:
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)
完整代码请访问:http://github.com/ripdog/PyPlayer/tree/cli,请查看main.py获取接口代码。
目前代码的状态不是很好,而且我只学了两个月编程。如果您有任何关于代码风格,布局或其他建议,请非常感谢。