- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
最佳答案
您可以使用 Urwid 绘制任何可在终端中使用纯 Unicode 文本绘制的内容,并为每个字符指定前景色和背景色。
考虑到这一点,不可能绘制出与模型中完全相同的图形,因为要绘制边框,您需要使用 the Unicode box drawing characters ,这会占用更多空间。
我开始写一个例子,但遗憾的是现在没有时间完善它。
我在这里分享未完成的状态(工作,但选择外观有问题),希望您会发现它有用,并且可以作为一个足够好的起点供您摆弄。
截图:
代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, absolute_import, division
import urwid
PALETTE = [
('normal', '', ''),
('bold', 'bold', ''),
('blue', 'bold', 'dark blue'),
('highlight', 'black', 'dark blue'),
]
def show_or_exit(key):
if key in ('q', 'Q', 'esc'):
raise urwid.ExitMainLoop()
class CustomButton(urwid.Button):
button_left = urwid.Text('[')
button_right = urwid.Text(']')
def custom_button(*args, **kwargs):
b = CustomButton(*args, **kwargs)
b = urwid.AttrMap(b, '', 'highlight')
b = urwid.Padding(b, left=4, right=4)
return b
class BoxButton(urwid.WidgetWrap):
_border_char = u'─'
def __init__(self, label, on_press=None, user_data=None):
padding_size = 2
border = self._border_char * (len(label) + padding_size * 2)
cursor_position = len(border) + padding_size
self.top = u'┌' + border + u'┐\n'
self.middle = u'│ ' + label + u' │\n'
self.bottom = u'└' + border + u'┘'
# self.widget = urwid.Text([self.top, self.middle, self.bottom])
self.widget = urwid.Pile([
urwid.Text(self.top[:-1]),
urwid.Text(self.middle[:-1]),
urwid.Text(self.bottom),
])
self.widget = urwid.AttrMap(self.widget, '', 'highlight')
# self.widget = urwid.Padding(self.widget, 'center')
# self.widget = urwid.Filler(self.widget)
# here is a lil hack: use a hidden button for evt handling
self._hidden_btn = urwid.Button('hidden %s' % label, on_press, user_data)
super(BoxButton, self).__init__(self.widget)
def selectable(self):
return True
def keypress(self, *args, **kw):
return self._hidden_btn.keypress(*args, **kw)
def mouse_event(self, *args, **kw):
return self._hidden_btn.mouse_event(*args, **kw)
if __name__ == '__main__':
header = urwid.Text('Header')
footer = urwid.Text('Footer')
onclick = lambda w: footer.set_text('clicked: %r' % w)
widget = urwid.Pile([
header,
urwid.Text('Simple custom buttons:'),
urwid.Columns([
custom_button('OK', on_press=onclick),
custom_button('Cancel', on_press=onclick),
]),
urwid.Text('Box bordered buttons:'),
urwid.Columns([
urwid.Padding(BoxButton('OK', on_press=onclick), left=4, right=4),
BoxButton('Cancel', on_press=onclick),
]),
footer,
])
widget = urwid.Filler(widget, 'top')
loop = urwid.MainLoop(widget, PALETTE, unhandled_input=show_or_exit)
loop.run()
关于python - 如何使 python 库 "urwid"的按钮看起来漂亮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52252730/
在通过REST Request Body方法发出搜索请求时,例如 GET /bank/_search { "query": { "match_all": {} }, "sort": [
有没有办法检测用户是否停止滑动?也许 bij 鼠标输入检查之类的。我尝试在 onSliderChange 事件中使用鼠标 isButton0Release 和 hasFocus 来检查用户是否停止滑动
(来源:google.com) 最近,我发现我的应用程序中显示的汉字相当难看。 我想我应该让它们“消除锯齿”。但是,我如何在 Java 中做到这一点? 仅供引用,我没有明确选择要在 GUI 应用程序中
我正在创建一个网站,根据某些条件(即是否登录、是否填写表格等),不同页面的外观可能会有很大差异。这使得需要在不同的时间输出不同的html block 。 但是,这样做会使我的 php 代码看起来很糟糕
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
如果我有一个类包含例如几个将用向量填充的槽,那么问题通常会出现。如果我想让这个类的对象或多或少透明,我会为它实现 print-object。在这里我遇到了问题: 如果我在一行中打印所有内容,REPL
我有一个允许上传到我网站的文件扩展名列表。 我用 jQuery Validation plugin 检查它们. 如果他们选择了不受支持的扩展程序,我会显示一条错误消息。 看起来像 var msg =
在一个本身嵌套在一个或多个父数组/结构/union 中的数组/结构/union 中读取多个数字/字符串的最佳方法是什么? 没有临时变量的第一个例子: printf("%d %d\n", a[9][3]
我是 AngularJS 的新手。我目前在为我的观点编写漂亮的 url 时遇到问题。我已经设置了 $locationProvider.html5Mode(true);删除 #从地址栏中显示的网址。但是
我有一个带有 ElasticSearch 的自动完成 jquery 功能。输入第一个字母时出现以下错误。 跨源请求被阻止:同源策略不允许读取 http://localhost:9200/test12/
我是一名优秀的程序员,十分优秀!