当前位置: 首页>>代码示例>>Python>>正文


Python urwid.AttrSpec方法代码示例

本文整理汇总了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)}
        ) 
开发者ID:bram85,项目名称:topydo,代码行数:8,代码来源:TodoWidget.py

示例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 
开发者ID:haskellcamargo,项目名称:sclack,代码行数:30,代码来源:image.py

示例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')) 
开发者ID:haskellcamargo,项目名称:sclack,代码行数:9,代码来源:components.py

示例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
        ]) 
开发者ID:haskellcamargo,项目名称:sclack,代码行数:9,代码来源:loading.py

示例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 
开发者ID:TomasTomecek,项目名称:sen,代码行数:48,代码来源:common.py

示例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 
开发者ID:Nanoseb,项目名称:ncTelegram,代码行数:47,代码来源:ui_msgwidget.py


注:本文中的urwid.AttrSpec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。