标签: urwid

Python ncurses,CDK,urwid的区别

这3个有什么区别?据我所知,它们都提供了对curses的绑定,这是基于终端文本的UI的C库.

我目前不知道3中的任何一个,我从未使用过诅咒.你会推荐哪一个?我听过多次ncurses,但只听过一次或两次CDK(通过研究),从未听说过urwid(我认为).

python curses ncurses urwid

25
推荐指数
1
解决办法
1万
查看次数

Python控制台UI建议

我目前正在重写一个使用curses的perl控制台应用程序,并计划在Python中实现它.到目前为止,我已经将我的库选项缩小到直接curses,urwid和dialog.

该应用程序基本上是一个适用于基本配置(网络选项,主机名等)的设备的安装程序.其中一个是否有任何建议或拥护者?urwid或对话有任何严重的限制吗?

python curses console-application urwid

10
推荐指数
1
解决办法
1249
查看次数

Python TUI库

我正在Linux中使用python和TUI编写一个小数独游戏/解算器(不是GUI,这只是蹩脚)只是为了好玩.我的问题是,哪个lib更好(我的意思是更容易处理,更好的支持,更直接和可理解),选择是诅咒urwid或者如果有人有更好的建议,为什么?我有一些Tkinter和wxPython经验.

任何帮助或信息将不胜感激.

python curses tui urwid

8
推荐指数
2
解决办法
7807
查看次数

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

我正在用python写一个音乐播放器,用cli使用urwid.我打算将当前播放列表放在一个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)
Run Code Online (Sandbox Code Playgroud)

完整代码:http://github.com/ripdog/PyPlayer/tree/cli - 检查main.py是否有接口代码.

代码目前处于非常糟糕的状态,我只编程了两个月.我们非常感谢您对代码风格,布局或任何其他提示的任何建议.

python urwid

7
推荐指数
1
解决办法
2565
查看次数

如何从'change'信号处理程序更改urwid.Edit的文本?

我想从其"更改"信号处理程序中更改urwid.Edit的文本.但是,它没有做任何事情.最小的工作示例:

import urwid

input_line = urwid.Edit(multiline=True)

def input_change(widget, text):
        if text.endswith("\n"):
                input_line.set_edit_text('')

urwid.connect_signal(input_line, 'change', input_change)
urwid.MainLoop(urwid.Filler(input_line)).run()
Run Code Online (Sandbox Code Playgroud)

如果按Enter键,它实际上会调用.set_edit_text(),但文本保持不变.我如何实现我想要的目标?

python urwid

6
推荐指数
1
解决办法
1727
查看次数

Urwid:使光标不可见

我正在使用urwid,这是一个用于在ncurses中设计终端用户界面的Python"框架".有一件事虽然我无法在urwid中做到容易诅咒 - 使光标不可见.就像现在一样,当选择按钮时光标是可见的,它看起来很丑陋.有没有办法禁用它?

python linux curses ncurses urwid

6
推荐指数
2
解决办法
981
查看次数

调试 urwid 应用程序有哪些好的选择?

我目前的临时方法是记录到文本文件,但这不是很互动。我试过使用pdb,但这似乎与 urwid 不符,pdb一旦遇到断点就不会接受任何输入。

python debugging python-3.x pdb urwid

5
推荐指数
1
解决办法
511
查看次数

如何使用 urwid 和 asyncio 使长任务不受阻塞?

我正在编写一个 Python 诅咒应用程序,该应用程序通过分别通过进程'stdin和发送和接收字符串来控制外部(Linux,如果有帮助)进程stdout。该接口使用urwid. 我编写了一个类来控制外部进程,并为一些 urwid 组件编写了一些其他类。

我还有一个按钮,应该向外部进程发送命令。但是,该过程不会立即响应,其任务通常需要长达几秒钟的时间,在此期间我希望界面不要冻结。

这是我运行子进程的方式:

def run(self, args):
    import io, fcntl, os
    from subprocess import Popen, PIPE

    # Run wpa_cli with arguments, use a thread to feed the process with an input queue
    self._pss = Popen(["wpa_cli"] + args, stdout=PIPE, stdin=PIPE)
    self.stdout = io.TextIOWrapper(self._pss.stdout, encoding="utf-8")
    self.stdin = io.TextIOWrapper(self._pss.stdin, encoding="utf-8", line_buffering=True)

    # Make the process' stdout a non-blocking file
    fd = self.stdout.fileno()
    fl = fcntl.fcntl(fd, fcntl.F_GETFL)
    fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
    ...
Run Code Online (Sandbox Code Playgroud)

我必须使进程的输出流非阻塞才能解析其输出。我不知道这对我的问题是否重要。 …

linux nonblocking urwid python-3.5

5
推荐指数
1
解决办法
1230
查看次数

如何组合多个TUI表单来编写更复杂的应用程序?

我想编写一个带有基于T ext的U ser I接口(TUI)的程序,它由几种形式组成.

介绍几种形式.

  • 第一个表单包含"列表".每个列表元素代表一个按钮.
  • 如果按下相应的按钮,则应出现另一个表单,其中可以输入列表条目的数据.
  • 然后再次显示第一个表单(使用更新的列表条目).

这是我的尝试,它使用库npyscreen但不返回第一个表单.代码也不包含更改列表项的逻辑.

#! /usr/bin/env python3
# coding:utf8

import npyscreen

# content
headers = ["column 1", "column 2", "column 3", "column 4"]
entries = [["a1", "a2", "a3", "a4"],
           ["b1", "b2", "b3", "b4"],
           ["c1", "c2", "c3", "c4"],
           ["d1", "d2", "d3", "d4"], 
           ["e1", "e2", "e3", "e4"]]


# returns a string in which the segments are padded with spaces.
def format_entry(entry):
    return "{:10} | {:10} | {:10} | {:10}".format(entry[0], entry[1] , …
Run Code Online (Sandbox Code Playgroud)

python tui console-application urwid npyscreen

5
推荐指数
1
解决办法
624
查看次数

在 Windows 上使用 urwid 时出现“NameError:名称 'fcntl' 未定义”

因此,我刚刚安装了 Urwid,并作为测试尝试运行相当于基本打印命令的 Urwid,如 Urwid 网站教程中的示例所示。我收到一条错误消息。

我尝试运行另一个示例并收到类似的错误消息。代码如下所示:

import urwid

txt = urwid.Text(u"Hello World")
fill = urwid.Filler(txt, 'top')
loop = urwid.MainLoop(fill)
loop.run()
Run Code Online (Sandbox Code Playgroud)

它应该在屏幕左上角打印“Hello World”,然后运行直到指示退出。相反,我收到此错误消息:

Traceback (most recent call last):
  File "C:\Users\Rory Kranz\AppData\Local\atom\app-1.34.0\testingg", line 5, in <module>
    loop = urwid.MainLoop(fill)
  File "C:\Users\Rory Kranz\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urwid\main_loop.py", line 114, in __init__
    screen = raw_display.Screen()
  File "C:\Users\Rory Kranz\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urwid\raw_display.py", line 92, in __init__
    fcntl.fcntl(self._resize_pipe_rd, fcntl.F_SETFL, os.O_NONBLOCK)
NameError: name 'fcntl' is not defined
Run Code Online (Sandbox Code Playgroud)

安装是否出了问题,或者我还需要安装其他东西才能让 Urwid 正常工作?

python urwid

5
推荐指数
1
解决办法
6310
查看次数