标签: urwid

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

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

python debugging python-3.x pdb urwid

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

urwid - 无限循环的输出屏幕

我正在尝试制作一个简单的 urwid 作为无限循环的输出屏幕。它需要输出来自另一个类的数据。

我现在找到的解决方案是:有一个带有队列属性的 Printer 类(实际输出类的测试替换器)。当它需要显示某些内容时,会将其附加到队列中。然后,有一个 Interface 类(实际的接口)及其自己的 Printer 实例。与 MainLoop 并行运行的线程检查队列是否有项目,如果有,则输出它们。由于 Printer 的 main 函数是一个无限循环,它也有自己的线程 - 在这个测试中,它只是每隔几秒输出“Hello”。

这是代码:

import urwid
import threading
import time

class Interface:
    palette = [
        ('body', 'white', 'black'),
        ('ext', 'white', 'dark blue'),
        ('ext_hi', 'light cyan', 'dark blue', 'bold'),
        ]

    header_text = [
        ('ext_hi', 'ESC'), ':quit        ',
        ('ext_hi', 'UP'), ',', ('ext_hi', 'DOWN'), ':scroll',
        ]

    def __init__(self):
        self.header = urwid.AttrWrap(urwid.Text(self.header_text), 'ext')
        self.flowWalker = urwid.SimpleListWalker([])
        self.body = urwid.ListBox(self.flowWalker)
        self.footer = urwid.AttrWrap(urwid.Edit("Edit:  "), 'ext')
        self.view …
Run Code Online (Sandbox Code Playgroud)

python multithreading urwid

4
推荐指数
1
解决办法
1851
查看次数

Python ABC多重继承

我认为代码比用文字可以更好地解释问题。这是my_abc.py中的代码:

from abc import ABCMeta, abstractmethod

class MyABC(object):
    __metaclass__ = ABCMeta

    @abstractmethod
    def print(self):
        pass
Run Code Online (Sandbox Code Playgroud)

这是my_class.py中的代码

from my_abc import MyABC
from third_party_package import SomeClass

class MyClass(MyABC, SomeClass):
    def __init__(self):
        super(MyClass, self).__init__()

    def print(self):
        print('Hello ABC')
Run Code Online (Sandbox Code Playgroud)

当我尝试运行my_class.py时,我得到:

TypeError:调用元类基础元类冲突时出错:派生类的元类必须是其所有基础元类的(非严格)子类

我知道我可以创建一个直接从我的接口MyABC继承的类,然后创建另一个类,然后再从我创建的该类和第三方模块类继承。

我的问题是:是否有另一种更好,更适当的方法直接执行此操作,而无需为我的目的创建中间类?

python metaclass multiple-inheritance python-2.7 urwid

4
推荐指数
2
解决办法
4341
查看次数

如何将 urwid.BigText 放入 urwid.ListBox

AttributeError: 'BigText' object has no attribute 'rows'当尝试在列表框顶部放置 BigText 时,我不断收到错误。我知道 BigText 是一个“固定”小部件,而 ListBox 需要一个“流”小部件,但无论我如何尝试,我似乎都无法让我的程序获取 BigText。这是我尝试过的详尽示例:

head_title = urwid.BigText(('banner', u'Header'), urwid.HalfBlock5x4Font())
head = urwid.Filler(head_title)
# head = urwid.AttrMap(head, 'banner')
# head = urwid.AttrMap(head, 'streak')
head = urwid.BoxAdapter(head, 3)
print head
# this gives me `<BoxAdapter flow widget <Filler box widget <BigText fixed widget>> height=3>`


body = [head, urwid.Divider()]
return urwid.ListBox(body)
Run Code Online (Sandbox Code Playgroud)

谢谢!

python listbox widget urwid

4
推荐指数
1
解决办法
947
查看次数

从父类扩展python 3中的__init__的正确方法

一般问题:完全像父类一样初始化子类,但添加单个属性的最简单/“最pythonic”方法是什么?

我的具体问题:我想扩展(UrwidEdit对象以包括单个附加属性my_attribute;我已经将原始签名复制到__init__和中super().__init__,但是签名中有一些未定义的参数/常量(LEFTSPACE),我不明白在父类中如何设置它们。以下是我的(中断)类定义和父init方法:

class MyEdit(urwid.Edit):

    def __init__(self, my_attribute, caption="", edit_text="", multiline=False, align=LEFT, wrap=SPACE, allow_tab=False, edit_pos=None, layout=None, mask=None):

        super().__init__(caption="", edit_text="", multiline=False, align=LEFT, wrap=SPACE, allow_tab=False, edit_pos=None, layout=None, mask=None)
        self.my_attribute = []    
        # super().__super.__init__("", align, wrap, layout)

    def my_method(self):
        #some code that modifies my_attribute
        return self.my_attribute




class Edit(Text):
    """
    Text editing widget implements cursor movement, text insertion and
    deletion.  A caption may prefix the editing area.  Uses text class …
Run Code Online (Sandbox Code Playgroud)

python oop initialization python-3.x urwid

4
推荐指数
1
解决办法
1119
查看次数

urwid中是否有焦点更改事件?

是否可以跟踪urwid.ListBox对象中突出显示项目的更改?甚至通过一个ListWalker物体?

我想,当用户使用箭头键从一个项目移动到另一个调用回调[],[],不是当用户点击[Enter]一个项目.

在此输入图像描述

python events python-3.x urwid

3
推荐指数
1
解决办法
577
查看次数

如何使python库“ urwid”的按钮看起来漂亮?

urwid中按钮的默认外观很有用,但在我眼中却不是很漂亮。当多个按钮并排显示时,这也可能会令人不快。

如何获得一个带有边框和居中文本的按钮,并在其获得焦点时更改其颜色?

在此处输入图片说明

python tui button console-application urwid

3
推荐指数
1
解决办法
607
查看次数

如何使用Python Urwid进行类似UI的聊天?

我可以使用gevent和zeromq实现聊天守护程序,但我想为其创建一个控制台UI。

我与ncurses的第一次尝试失败了,所以我尝试Urwid,发现该项目寿司正想正是我想要的:

Nigiri UI

我研究了源代码,但是由于不熟悉控制台UI编程,因此未能找出产生此结果的部分(特别是因为它使用了多个选项卡),而我想我必须使用connect信号

是否有人可以做到这一点?

我不需要整个程序,我可以自己处理通信,守护程序,选项以及所有其他内容。

只是设置UI的基础知识,在底部输入一些文本,然后异步通知顶部面板在不阻止底部输出的情况下添加一些文本。

谢谢

python console user-interface chat urwid

2
推荐指数
1
解决办法
3928
查看次数

我无法获得urwid教程示例

我是Python和urwid的新手,我在这里尝试了教程示例http://excess.org/urwid/docs/tutorial/

然而,虽然第一个工作正常,但大多数后来的工作似乎不起作用.例如,尝试运行这个特定的:

import urwid

choices = u'Chapman Cleese Gilliam Idle Jones Palin'.split()

def menu(title, choices):
    body = [urwid.Text(title), urwid.Divider()]
    for c in choices:
        button = urwid.Button(c)
        urwid.connect_signal(button, 'click', item_chosen, c)
        body.append(urwid.AttrMap(button, None, focus_map='reversed'))
    return urwid.ListBox(urwid.SimpleFocusListWalker(body))

def item_chosen(button, choice):
    response = urwid.Text([u'You chose ', choice, u'\n'])
    done = urwid.Button(u'Ok')
    urwid.connect_signal(done, 'click', exit_program)
    main.original_widget = urwid.Filler(urwid.Pile([response,
        urwid.AttrMap(done, None, focus_map='reversed')]))

def exit_program(button):
    raise urwid.ExitMainLoop()

main = urwid.Padding(menu(u'Pythons', choices), left=2, right=2)
top = urwid.Overlay(main, urwid.SolidFill(u'\N{MEDIUM SHADE}'),
    align='center', width=('relative', 60),
    valign='middle', height=('relative', 60),
    min_width=20, …
Run Code Online (Sandbox Code Playgroud)

python linux console urwid

2
推荐指数
1
解决办法
2618
查看次数

如何在 urwid 中指定边界?

我是 urwid 的新手,认为我误解了一些东西。我不明白为什么这不起作用。而且我不明白错误消息。

#!/usr/bin/env python3
import urwid

def show_or_exit(key):
    if key in ('q', 'Q'):
        raise urwid.ExitMainLoop()
    txt.set_text(repr(key))

txt = urwid.Text('FooBar')

fil = urwid.Filler(txt, valign='middle', height=('relative', 70))
box = urwid.LineBox(fil)
pad = urwid.Padding(box, align='center', width=('relative', 85))

loop = urwid.MainLoop(pad, unhandled_input=show_or_exit)
loop.run()
Run Code Online (Sandbox Code Playgroud)

python-3.x urwid

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

如何使用“print”函数清除控制台行

前提

我试图基本上清除控制台行,但不是在不使用空格的情况下清除整个控制台窗口,这样我就不会从上次打印的内容中获得额外的字符。例如:

# This causes characters from the last thing printed:
print("I don't know you.", end="\r")
print("Hello Jim!", end="\r")

# Yields the following (without the quotations) -->
# "Hello Jim!ow you."
Run Code Online (Sandbox Code Playgroud)

现在要解决这个问题可以这样做:

# This causes characters from the last thing printed:
print("I don't know you.", end="\r")
print("Hello Jim!", end="\r")

# Yields the following (without the quotations) -->
# "Hello Jim!ow you."
Run Code Online (Sandbox Code Playgroud)

问题

我如何

  1. 只是打印出来"Hello Jim!"而不是"Hello Jim! "(两者显然都没有引号)
  2. 清除该行
  3. 虽然没有清除整个控制台(这样我就可以输出除最后一行之外的其他内容)

具体来说,当改变尺寸时(例如控制台宽度从 17 到 30),控制台中会发生类似的情况,在我的情况下,这种情况经常发生:

Hello Jim! …
Run Code Online (Sandbox Code Playgroud)

python console urwid

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

@ code构造在python中意味着什么?

我正在使用urwid提供的wicd应用程序查看文件wicd-curses.py.有一个名为wrap_exceptions的函数,然后在文件的其他几个地方,我发现了一些像@wrap_exceptions这样的代码,它发生在其他几个函数之前.这是什么意思 ?

python-2.7 urwid

0
推荐指数
1
解决办法
140
查看次数