我正在用 python 编写一个音乐播放器,并带有一个使用 urwid 的 cli。我打算将当前播放列表放在一个 simpleListWalker 中,由一个列表框包裹,然后是列、一堆,最后是一个框架。
如何用其他内容替换此列表框(或 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 的接口代码。
代码现在处于非常糟糕的状态,而我只编程了两个月。非常感谢您对代码样式、布局或任何其他提示的任何建议。