本文整理汇总了Python中urwid.AttrSpec方法的典型用法代码示例。如果您正苦于以下问题:Python urwid.AttrSpec方法的具体用法?Python urwid.AttrSpec怎么用?Python urwid.AttrSpec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urwid
的用法示例。
在下文中一共展示了urwid.AttrSpec方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_progress
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrSpec [as 别名]
def update_progress(self):
color = to_urwid_color(progress_color(self.todo)) if config().colors() else PaletteItem.DEFAULT
self.progress_bar.set_attr_map(
{None: urwid.AttrSpec(PaletteItem.DEFAULT, color, 256)}
)
示例2: ansi_to_urwid
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrSpec [as 别名]
def ansi_to_urwid(ansi_text):
result = []
ansi_text = ansi_text.decode('utf-8')
for instruction in ansi_text.split('\x1B['):
try:
attr, text = instruction.split('m', 1)
except:
attr = '0'
text = instruction.split('m', 1)
attr_list = [int(code) for code in attr.split(';')]
attr_list.sort()
foreground = -1
background = -1
for attr in attr_list:
if attr <= 29:
pass
elif attr <= 37:
foreground = attr - 30
elif attr <= 47:
background = attr - 40
elif attr <= 94:
foreground = foreground + 8
elif attr >= 100 and attr <= 104:
background = background + 8
foreground = color_list[foreground]
background = color_list[background]
result.append((urwid.AttrSpec(foreground, background), text))
return result
示例3: __init__
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrSpec [as 别名]
def __init__(self, widget, color):
body = urwid.LineBox(widget,
lline=get_icon('block'),
tlcorner=get_icon('block_top'),
blcorner=get_icon('block_bottom'),
tline='', trcorner='', rline='', bline='', brcorner='')
super(Box, self).__init__(body, urwid.AttrSpec(color, 'h235'))
示例4: __init__
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrSpec [as 别名]
def __init__(self):
super(SlackBot, self).__init__([
urwid.Text([
(urwid.AttrSpec(pair[1], pair[2]), pair[0]) for pair in row
], align='center')
for row in self._matrix
])
示例5: strip_from_ansi_esc_sequences
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrSpec [as 别名]
def strip_from_ansi_esc_sequences(text):
"""
find ANSI escape sequences in text and remove them
:param text: str
:return: list, should be passed to ListBox
"""
# esc[ + values + control character
# h, l, p commands are complicated, let's ignore them
seq_regex = r"\x1b\[[0-9;]*[mKJusDCBAfH]"
regex = re.compile(seq_regex)
start = 0
response = ""
for match in regex.finditer(text):
end = match.start()
response += text[start:end]
start = match.end()
response += text[start:len(text)]
return response
# def colorize_text(text):
# """
# finds ANSI color escapes in text and transforms them to urwid
#
# :param text: str
# :return: list, should be passed to ListBox
# """
# # FIXME: not finished
# response = []
# # http://ascii-table.com/ansi-escape-sequences.php
# regex_pattern = r"(?:\x1b\[(\d+)?(?:;(\d+))*m)([^\x1b]+)" # [%d;%d;...m
# regex = re.compile(regex_pattern, re.UNICODE)
# for match in regex.finditer(text):
# groups = match.groups()
# t = groups[-1]
# color_specs = groups[:-1]
# urwid_spec = translate_asci_sequence(color_specs)
# if urwid_spec:
# item = (urwid.AttrSpec(urwid_spec, "main_list_dg"), t)
# else:
# item = t
# item = urwid.AttrMap(urwid.Text(t, align="left", wrap="any"), "main_list_dg", "main_list_white")
# response.append(item)
# return response
示例6: translate_color
# 需要导入模块: import urwid [as 别名]
# 或者: from urwid import AttrSpec [as 别名]
def translate_color(raw_text):
formated_text = []
raw_text = raw_text.decode("utf-8")
for at in raw_text.split("\x1b["):
try:
attr, text = at.split("m",1)
except:
attr = '0'
text = at.split("m",1)
list_attr = [ int(i) for i in attr.split(';') ]
list_attr.sort()
fg = -1
bg = -1
for elem in list_attr:
if elem <= 29:
pass
elif elem <= 37:
fg = elem - 30
elif elem <= 47:
bg = elem - 40
elif elem <= 94:
fg = fg + 8
elif elem >= 100 and elem <= 104:
bg = bg + 8
fgcolor = color_list[fg]
bgcolor = color_list[bg]
if fg < 0:
fgcolor = ''
if bg < 0:
bgcolor = ''
if list_attr == [0]:
fgcolor = ''
bgcolor = ''
formated_text.append((urwid.AttrSpec(fgcolor, bgcolor), text))
return formated_text
# vim: ai ts=4 sw=4 et sts=4