问题标签 [urwid]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
848 浏览

python - python中的main函数调用失败

我编写了以下代码来创建布局并在布局中显示一些文本。接下来,使用 urwid 库中的原始显示模块将布局显示在控制台屏幕上。但是运行代码失败,因为它没有找到我在类中单独编写的函数main 。

运行时的错误代码是:

编码 :

0 投票
2 回答
1450 浏览

python - main 中的全局变量在 python 的另一个函数中没有被识别

下面的代码创建一个布局并在布局中显示一些文本。接下来,使用 urwid 库中的原始显示模块将布局显示在控制台屏幕上。但是,运行代码失败,因为在 main 中声明的全局变量 ui 在另一个函数中无法识别。

运行时的错误代码是:
Traceback (most recent call last):
File "./yamlUrwidUIPhase6.py", line 97, in <module>
main() File "./yamlUrwidUIPhase6.py", line 90, in main
form = FormDisplay() File "./yamlUrwidUIPhase6.py", line 23, in __init__
palette = ui.register_palette([
NameError: global name 'ui' is not defined

编码 :

我不想更改函数 formLayout,因为我打算在这个基本代码框架中添加更多内容,其中将添加另一个函数,该函数重复调用 formLayout 以根据从 yml 文件中读取的值不断更新屏幕。

0 投票
2 回答
882 浏览

python - 'Assertion Error' while trying to create a console screen using urwid

code below creates a layout and displays some text in the layout. Next the layout is displayed on the console screen using raw display module from urwid library. (More info on my complete project can be gleaned from questions at widget advice for a console project and urwid for a console project. My skype help request being here.) However running the code fails as an Assertion Error is raised as described below :

Error on running code is :
Traceback (most recent call last):
File "./yamlUrwidUIPhase6.py", line 98, in <module>
main()
File "./yamlUrwidUIPhase6.py", line 92, in main
form.main()
File "./yamlUrwidUIPhase6.py", line 48, in main
self.view = formLayout()
File "./yamlUrwidUIPhase6.py", line 77, in formLayout
ui.draw_screen(dim, frame.render(dim, True))
File "/usr/lib64/python2.7/site-packages/urwid/raw_display.py", line 535, in draw_screen
assert self._started
AssertionError

The code :

I don't want to change the function formLayout as I intend to add more to this basic code framework, where in another function will be added that repeatedly calls formLayout to keep updating the screen based on reading values from a yml file. I already have a separate code that deals with reading the yaml file and extracting ordered dictionaries out it. After figuring out how to get basic urwid console working, I can move on to integrating both to create my final application.

0 投票
1 回答
741 浏览

python - 尝试使用 urwid 创建控制台屏幕时出现“AttributeError”

下面的代码创建一个布局并在布局中显示一些文本。接下来,使用 urwid 库中的原始显示模块将布局显示在控制台屏幕上。(关于我的完整项目的更多信息可以从控制台项目的小部件建议和控制台项目urwid 中收集。我的 Skype 帮助请求在这里。)但是运行代码失败,因为如下所述引发 AttributeError。在查看 /usr/lib64/python2.7/site-packages/urwid 的 urwid 源代码时,我看到 main_loop.py 和 curses_display.py 都有一个带有不同参数的 draw_screen 函数: main_loop.py -> def draw_screen(self ):

curses_display.py > def draw_screen(self, (cols, rows), r):

我是否必须通过import draw_screen from specificFile命令来指定使用哪一个?或者我在看画布概念有什么根本错误吗?我还可以看到文件 /usr/lib64/python2.7/site-packages/urwid/container.py中的框架类( class Frame(BoxWidget): )具有渲染功能(def render(self, size, focus =假):)

运行代码的错误是:
Traceback (most recent call last):
File "./yamlUrwidUIPhase6.py", line 104, in <module>
main() File "./yamlUrwidUIPhase6.py", line 98, in main
form.main()
File "./yamlUrwidUIPhase6.py", line 51, in main
self.loop.run()
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 274, in run
self.screen.run_wrapper(self._run)
File "/usr/lib64/python2.7/site-packages/urwid/raw_display.py", line 237, in run_wrapper return fn()
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 285, in _run self.draw_screen()
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 508, in draw_screen
canvas = self._topmost_widget.render(self.screen_size, focus=True)
AttributeError: 'NoneType' object has no attribute 'render'

编码 :

我不想更改函数 formLayout,因为我打算在这个基本代码框架中添加更多内容,其中将添加另一个函数,该函数重复调用 formLayout 以根据从 yml 文件中读取的值不断更新屏幕。我已经有一个单独的代码来处理读取 yaml 文件并从中提取有序字典。在弄清楚如何让基本的 urwid 控制台正常工作之后,我可以继续集成两者来创建我的最终应用程序。

0 投票
2 回答
1160 浏览

python - Command prompt messed up after running a Python program

The code below creates a layout and displays some text in the layout. Next the layout is displayed on the console screen using the raw display module from the Urwid library. (More information on my complete project can be gleaned from questions at Required widgets for displaying a 1D console application and Using Urwid to create a 2D console application.

My skype help request being here. I can run the code to display the relevant information. On pressing F8 the code asks a dialog on screen if to exit. On pressing the 'y' key, the application ends. But right after that the commmand prompt is messed up. I am not able to write anything at the command prompt. Pressing the Enter button only repeats the command prompt as follows:

The code is:

I suspect the behaviour shown after the application exits has got to do something with return calls of the functions FormDisplay, formlayout and formlayoutExit. How can I fix this problem?

0 投票
1 回答
803 浏览

python - urwid 示例中属性的含义

我是使用 Urwid 库(内置 Python)的新手,我试图在 urwid 示例中了解一些现有的 urwid示例。其中之一是这段代码:

  1. 这个例子中的属性是如何工作的?
  2. 前景和背景是什么意思?
  3. map1 "wraps" txt 是什么意思?这是否意味着您创建了一个名为 map1 的小部件并将该小部件放置在放置 txt 的屏幕位置上?短语“用另一个小部件 B 包装一个小部件 A”是否与我们所说的“将小部件 A 映射到小部件 B”的意思相同?
  4. map1 是 Filler 装饰小部件的 original_widget 吗?
  5. 哪个代码部分匹配 streak 的垂直高度与 txt 的垂直高度完全匹配?为什么 streak 的垂直高度没有变得大于或小于 txt 的垂直高度?如果没有 map2 那么这是否意味着除了 txt1 屏幕的其余部分将是红色或只是黑色?
0 投票
2 回答
2198 浏览

python - 在 urwid 中使用 ListBox 时出现“AttributeError”

下面使用 urwid 库的代码应该在控制台屏幕上显示 yml 文件的内容(如此处给出) (根据此处的应用程序表单布局:

代码是:

ui用于表示控制台屏幕的代码。我使用了一个全局列表框 api,它将包含来自 yml 文件的值,其键是 $display。代码失败,给出以下错误:

我用 ddd 和 pydb 调试器检查了代码的解析部分,解析 yml 部分似乎没问题,打印语句正确地给出了 $display 的值。我使用 ui 的方式有问题吗?我应该改用 draw_screen 吗?

0 投票
1 回答
850 浏览

python - 无法在 urwid 的 linebox 小部件中放置一系列列

我正在阅读一个 yml 表单文件并将其内容作为 urwid 中的列获取。我必须在控制台上显示这些列。如果我使用普通的列表框和 listwalker,那么我可以让列显示在屏幕上。但是,我需要将一些列分组为一个块并将其显示在一个 linebox 小部件中。我该怎么做?

我的每个列小部件都有两列,第一列是文本小部件,第二列是编辑小部件。这是我尝试过的:

  1. 尝试通过附加到名为 blockPile 的堆(声明为 blockPile = urwid.Pile([ ]) )来创建一堆列,如下所示:
    blockPile.contents.append(columnEntry, options='pack')

    但收到此错误

    TypeError: append() got an unexpected keyword argument 'options'

  2. 然后删除了选项并使用了这个:

    blockPile.contents.append(columnEntry)

    但出现以下错误

    urwid.container.PileError: added content invalid: <Columns selectable box/flow widget>

  3. 接下来我使用了列表框

    blockContent = urwid.SimpleListWalker([])
    blockListbox = urwid.ListBox(blockContent)

    并使用 append 将我的列放入 listBox
    blockContent.append(columnEntry)

    最后将列表框放在盒子适配器中

    box = urwid.BoxAdapter(blockContent, height = 20)

    然后在一个 linebox 中返回它
    return urwid.LineBox(box, title='|** Block **|')

    但现在我收到以下错误
    AttributeError: 'SimpleListWalker' object has no attribute 'selectable'

如果我只使用一个列表框和一个 listwalker 并且不将列表框放在其他任何东西中,那么一切正常。但我希望将列的列表框放在一个行框中。我该怎么做?

0 投票
1 回答
412 浏览

python - Python3:清除异常链?

我试图在一个except:块中引发异常,但解释器试图提供帮助并“强制”打印堆栈跟踪。有可能避免这种情况吗?

一点背景信息:我正在玩 urwid,一个Python 的TUI 库。用户界面由 call 开始,由raiseurwid.MainLoop.run()结束。到目前为止,这工作正常,但是当引发另一个异常时会发生什么?例如,当我正在捕捉(urwid MainLoop 没有)时,我会进行一些清理并希望通过引发适当的异常来结束用户界面。但这会导致屏幕充满堆栈跟踪。 urwid.ExitMainLoop()KeyboardInterrupt

一些小的研究表明,python3 可以记住链式异常,并且可以使用 'cause': 显式引发异常raise B() from A()。我学习了一些方法来更改或附加有关引发的异常的数据,但我发现无法“禁用”此功能。我想避免打印堆栈跟踪和行之类The above exception was the direct cause of...的,而只是在一个块内引发接口结束异常,except:就像我在一个块之外一样。

这是可能的还是我在做一些根本错误的事情?

编辑:这是一个类似于我当前架构的示例,导致同样的问题:

不幸的是,我也无法更改main_loop为 except KeyboardInterrupt。有解决这个问题的模式吗?

0 投票
1 回答
824 浏览

python - Python:urwid:尝试处理不同的视图

我正在尝试编写一个具有不同视图的程序。

我尝试创建一个使用 urwid 处理不同视图的类,并将视图代码与其他代码分开。但是经过很多不同的尝试,我不知道从哪里开始了。

我需要哪些 urwid 对象来彻底擦除和重绘屏幕?以及如何封装它们以便我可以在用户输入后切换视图?