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

标签 python urwid

我正在用 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 中的接口(interface)代码。

代码现在处于非常糟糕的状态,我才编程了两个月。非常感谢您对代码风格、布局或任何其他技巧的任何建议。

最佳答案

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

应该替换整个小部件列表。

如果您想要更快的回复,下次将您的问题发布到邮件列表或 IRC channel !

关于python - 改变urwid/python2.6中当前显示列表框的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2137354/

相关文章:

python - 如何使用 AND 运算符过滤包含特定字符串值的行

python - lxml - 访问元素上元标记的值

python - 将 Django 应用程序部署到 Apache 时出现问题

python - 如何指示 urwid 列表框的项目多于当前显示的项目?

python - urwid 不会在 loop.draw_screen() 上更新屏幕

python - urwid 动态更改调色板颜色

python - 从单个值 : Fast and readable method? 构建一个小的 numpy 数组

python - 从 Windows 任务计划程序运行时如何使 Python.exe 保持打开状态

python - urwid - 无限循环的输出屏幕

Python 控制台 UI 建议