改变当前显示的urwid/python2.6列表框的内容

2024-09-19 23:32:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用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-检查主.py接口代码。在

代码现在处于非常糟糕的状态,而我只编写了两个月的程序。任何关于代码样式、布局的建议,或任何其他提示,您可能会非常感谢。在


Tags: 代码inselfforclidefitemfixed
1条回答
网友
1楼 · 发布于 2024-09-19 23:32:03
self.mainListContent[:] = [new, list, of, widgets]

应该替换所有的小部件。在

下次如果你想得到更快的答复,请把你的问题发到邮件列表或IRC频道!在

相关问题 更多 >