Пример #1
0
import re
import urwid
import math
from urwid.display_common import _BASIC_COLORS as BASIC_COLORS
from urwid.display_common import _BASIC_COLOR_VALUES as BASIC_COLOR_VALUES
from urwid.display_common import _ATTRIBUTES as STYLES
from urwid_utils.util import get_const_identifiers

STYLES = list(zip([n.upper() for n in STYLES], STYLES))

BASIC_COLOR_MAP = dict(zip(BASIC_COLOR_VALUES, BASIC_COLORS))


def rgb_distance(c1, c2):
    (r1, g1, b1) = c1
    (r2, g2, b2) = c2
    return math.sqrt((r1 - r2)**2 + (g1 - g2)**2 + (b1 - b2)**2)


def nearest_basic_color(high_color):

    closest_colors = sorted(BASIC_COLOR_MAP.keys(),
                            key=lambda color: rgb_distance(color, high_color))
    return BASIC_COLOR_MAP[closest_colors[0]]


color_const = get_const_identifiers(urwid.display_common, STYLES)
color_const['STYLES'] = STYLES
globals().update(color_const)
__all__ = list(color_const.keys())
Пример #2
0
# -*- coding: utf-8 -*-

import urwid
from urwid_utils.util import is_valid_identifier, get_const_identifiers
from urwid.escape import input_sequences, _keyconv

class KeySequence(str):

    def __new__(cls, data='', eggs=0):
        return super(KeySequence, cls).__new__(cls, data)

keys = [k for s,k in input_sequences] + list(_keyconv.values())

keys = set([k for k in keys if isinstance(k, str)])

key_const = {}
for key in keys:
    attr_name = key.replace(' ', '_').upper()
    if is_valid_identifier(attr_name):
        key_const[attr_name] = KeySequence(key)

key_const.update(get_const_identifiers(urwid.escape))
key_const.pop('ESC')         # FIXME: is this necessary?
key_const['ESCAPE'] = 'esc'  # FIXME: is this necessary?
globals().update(key_const)
__all__ = list(key_const.keys())
Пример #3
0
# -*- coding: utf-8 -*-

import re
from urwid_utils.util import is_valid_identifier, get_const_identifiers
from urwid import widget, command_map

MISC_CONST_VAL = [
    'cursor left',
    'cursor max left',
    'fixed bottom',
    'fixed left',
    'fixed right',
    'fixed top',
]
MISC_CONST_NAMES = [v.replace(' ', '_').upper() for v in MISC_CONST_VAL]
MISC_CONST = list(zip(MISC_CONST_NAMES, MISC_CONST_VAL))
MISC_CONST.append(('FOCUS_HEADER', 'header'))
MISC_CONST.append(('FOCUS_BODY', 'body'))
MISC_CONST.append(('FOCUS_FOOTER', 'footer'))

const = get_const_identifiers(widget, command_map, MISC_CONST)
globals().update(const)
__all__ = list(const.keys())
Пример #4
0
# -*- coding: utf-8 -*-

import urwid
from urwid_utils.util import is_valid_identifier, get_const_identifiers
from urwid.escape import input_sequences, _keyconv

keys = [k for s, k in input_sequences] + list(_keyconv.values())
keys = set([k for k in keys if isinstance(k, str)])

key_const = {}
for key in keys:
    attr_name = key.replace(' ', '_').upper()
    if is_valid_identifier(attr_name):
        key_const[attr_name] = str(key) if key else ""

key_const.update(get_const_identifiers(urwid.escape))
key_const.pop('ESC')  # FIXME: is this necessary?
key_const['ESCAPE'] = 'esc'  # FIXME: is this necessary?
globals().update(key_const)
__all__ = list(key_const.keys())
Пример #5
0
import re
import urwid
import math
from urwid.display_common import _BASIC_COLORS as BASIC_COLORS
from urwid.display_common import _BASIC_COLOR_VALUES as BASIC_COLOR_VALUES
from urwid.display_common import _ATTRIBUTES as STYLES
from urwid_utils.util import get_const_identifiers

STYLES = list(zip([n.upper() for n in STYLES], STYLES))

BASIC_COLOR_MAP = dict(zip(BASIC_COLOR_VALUES, BASIC_COLORS))

def rgb_distance(c1, c2):
    (r1,g1,b1) = c1
    (r2,g2,b2) = c2
    return math.sqrt((r1 - r2)**2 + (g1 - g2) ** 2 + (b1 - b2) **2)

def nearest_basic_color(high_color):

    closest_colors = sorted(
        BASIC_COLOR_MAP.keys(),
        key=lambda color: rgb_distance(color, high_color)
    )
    return BASIC_COLOR_MAP[closest_colors[0]]


color_const = get_const_identifiers(urwid.display_common, STYLES)
color_const['STYLES'] = STYLES
globals().update(color_const)
__all__ = list(color_const.keys())