當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。