Python urwid.AttrSpec() Examples
The following are 7
code examples of urwid.AttrSpec().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
urwid
, or try the search function
.
Example #1
Source File: TodoWidget.py From topydo with GNU General Public License v3.0 | 5 votes |
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)} )
Example #2
Source File: image.py From sclack with GNU General Public License v3.0 | 5 votes |
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
Example #3
Source File: components.py From sclack with GNU General Public License v3.0 | 5 votes |
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'))
Example #4
Source File: components.py From sclack with GNU General Public License v3.0 | 5 votes |
def __init__(self, id, name, color=None, is_app=False): self.id = id if not color: color = '333333' color = '#{}'.format(shorten_hex(color)) markup = [ (urwid.AttrSpec(color, 'h235'), '{} '.format(name)) ] if is_app: markup.append(('app_badge', '[APP]')) super(User, self).__init__(markup)
Example #5
Source File: loading.py From sclack with GNU General Public License v3.0 | 5 votes |
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 ])
Example #6
Source File: common.py From sen with MIT License | 4 votes |
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
Example #7
Source File: ui_msgwidget.py From ncTelegram with GNU General Public License v3.0 | 4 votes |
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