diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2017-11-14 12:13:03 +0000 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2017-11-14 12:13:03 +0000 |
commit | bd7b52988c99ef34fd49f52c8a9d335941144450 (patch) | |
tree | 2616f8245dc94433eb3a14e4b5b18f34b61c3030 | |
parent | 395435c68dc656641e7bdb53da88773482dd55b5 (diff) | |
download | poezio-bd7b52988c99ef34fd49f52c8a9d335941144450.tar.gz poezio-bd7b52988c99ef34fd49f52c8a9d335941144450.tar.bz2 poezio-bd7b52988c99ef34fd49f52c8a9d335941144450.tar.xz poezio-bd7b52988c99ef34fd49f52c8a9d335941144450.zip |
yapf -ir
-rw-r--r-- | poezio/colors.py | 16 | ||||
-rw-r--r-- | poezio/tabs/muctab.py | 8 | ||||
-rwxr-xr-x | poezio/theming.py | 6 | ||||
-rw-r--r-- | poezio/user.py | 8 | ||||
-rw-r--r-- | poezio/windows/base_wins.py | 3 | ||||
-rw-r--r-- | poezio/windows/inputs.py | 3 | ||||
-rw-r--r-- | poezio/xhtml.py | 5 |
7 files changed, 34 insertions, 15 deletions
diff --git a/poezio/colors.py b/poezio/colors.py index 8f086991..6a398a0d 100644 --- a/poezio/colors.py +++ b/poezio/colors.py @@ -5,14 +5,15 @@ import math # BT.601 (YCbCr) constants, see XEP-0392 K_R = 0.299 K_G = 0.587 -K_B = 1-K_R-K_G +K_B = 1 - K_R - K_G + def ncurses_color_to_rgb(color): if color <= 15: try: (r, g, b) = curses.color_content(color) except: # fallback in faulty terminals (e.g. xterm) - (r, g, b) = curses.color_content(color%8) + (r, g, b) = curses.color_content(color % 8) r = r / 1000 * 5 g = g / 1000 * 5 b = b / 1000 * 5 @@ -28,12 +29,14 @@ def ncurses_color_to_rgb(color): r = g = b = color / 24 * 5 return r / 5, g / 5, b / 5 + def rgb_to_ycbcr(r, g, b): y = K_R * r + K_G * g + K_B * b cr = (r - y) / (1 - K_R) / 2 cb = (b - y) / (1 - K_B) / 2 return y, cb, cr + def generate_ccg_palette(curses_palette, reference_y): cbcr_palette = {} for curses_color in curses_palette: @@ -56,12 +59,14 @@ def generate_ccg_palette(curses_palette, reference_y): for angle, (_, curses_color) in cbcr_palette.items() } + def text_to_angle(text): hf = hashlib.sha1() hf.update(text.encode("utf-8")) hue = int.from_bytes(hf.digest()[:2], "little") return hue / 65535 * math.pi * 2 + def angle_to_cbcr_edge(angle): cr = math.sin(angle) cb = math.cos(angle) @@ -69,14 +74,16 @@ def angle_to_cbcr_edge(angle): factor = 0.5 / abs(cr) else: factor = 0.5 / abs(cb) - return cb*factor, cr*factor + return cb * factor, cr * factor + def cbcr_to_angle(cb, cr): magn = math.sqrt(cb**2 + cr**2) if magn > 0: cr /= magn cb /= magn - return math.atan2(cr, cb) % (2*math.pi) + return math.atan2(cr, cb) % (2 * math.pi) + def ccg_palette_lookup(palette, angle): # try quick lookup first @@ -97,6 +104,7 @@ def ccg_palette_lookup(palette, angle): return best + def ccg_text_to_color(palette, text): angle = text_to_angle(text) return ccg_palette_lookup(palette, angle) diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 13feb552..328c65ee 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -1076,8 +1076,9 @@ class MucTab(ChatTab): def enable_self_ping_event(self): delay = config.get_by_tabname( "self_ping_delay", self.general_jid, default=0) - interval = int(config.get_by_tabname( - "self_ping_interval", self.general_jid, default=delay)) + interval = int( + config.get_by_tabname( + "self_ping_interval", self.general_jid, default=delay)) if interval <= 0: # use 0 or some negative value to disable it return self.disable_self_ping_event() @@ -1091,7 +1092,8 @@ class MucTab(ChatTab): self.self_ping_event = None def send_self_ping(self): - timeout = config.get_by_tabname("self_ping_timeout", self.general_jid, default=60) + timeout = config.get_by_tabname( + "self_ping_timeout", self.general_jid, default=60) to = self.name + "/" + self.own_nick self.core.xmpp.plugin['xep_0199'].send_ping( jid=to, diff --git a/poezio/theming.py b/poezio/theming.py index b5c9d516..5cdd89ae 100755 --- a/poezio/theming.py +++ b/poezio/theming.py @@ -373,6 +373,7 @@ class Theme(object): prepare_ccolor_palette(self) return self.CCG_PALETTE + # This is the default theme object, used if no theme is defined in the conf theme = Theme() @@ -467,7 +468,8 @@ def to_curses_attr(color_tuple): if 'u' in additional_val: curses_pair = curses_pair | curses.A_UNDERLINE if 'i' in additional_val: - curses_pair = curses_pair | (curses.A_ITALIC if hasattr(curses, 'A_ITALIC') else curses.A_REVERSE) + curses_pair = curses_pair | (curses.A_ITALIC if hasattr( + curses, 'A_ITALIC') else curses.A_REVERSE) if 'a' in additional_val: curses_pair = curses_pair | curses.A_BLINK return curses_pair @@ -517,6 +519,7 @@ def update_themes_dir(option=None, value=None): log.debug('Theme load path: %s', load_path) + def prepare_ccolor_palette(theme): """ Prepare the Consistent Color Generation (XEP-0392) palette for a theme. @@ -538,6 +541,7 @@ def prepare_ccolor_palette(theme): theme.CCG_Y, ) + def reload_theme(): theme_name = config.get('theme') global theme diff --git a/poezio/user.py b/poezio/user.py index 40d042f8..c69d241c 100644 --- a/poezio/user.py +++ b/poezio/user.py @@ -56,13 +56,13 @@ class User(object): if theme.ccg_palette: # use XEP-0392 CCG fg_color = colors.ccg_text_to_color( - theme.ccg_palette, - self.jid.bare if self.jid and self.jid.bare else self.nick - ) + theme.ccg_palette, self.jid.bare + if self.jid and self.jid.bare else self.nick) self.color = fg_color, -1 else: mod = len(theme.LIST_COLOR_NICKNAMES) - nick_pos = int(md5(self.nick.encode('utf-8')).hexdigest(), 16) % mod + nick_pos = int(md5(self.nick.encode('utf-8')).hexdigest(), + 16) % mod self.color = theme.LIST_COLOR_NICKNAMES[nick_pos] def update(self, affiliation, show, status, role): diff --git a/poezio/windows/base_wins.py b/poezio/windows/base_wins.py index 8163dad5..70271765 100644 --- a/poezio/windows/base_wins.py +++ b/poezio/windows/base_wins.py @@ -101,7 +101,8 @@ class Win(object): if y is not None and x is not None: self.move(y, x) next_attr_char = text.find(FORMAT_CHAR) - attr_italic = curses.A_ITALIC if hasattr(curses, 'A_ITALIC') else curses.A_REVERSE + attr_italic = curses.A_ITALIC if hasattr( + curses, 'A_ITALIC') else curses.A_REVERSE while next_attr_char != -1 and text: if next_attr_char + 1 < len(text): attr_char = text[next_attr_char + 1].lower() diff --git a/poezio/windows/inputs.py b/poezio/windows/inputs.py index d2ea5fbb..512395f0 100644 --- a/poezio/windows/inputs.py +++ b/poezio/windows/inputs.py @@ -485,7 +485,8 @@ class Input(Win): if y is not None and x is not None: self.move(y, x) format_char = find_first_format_char(text, chars) - attr_italic = curses.A_ITALIC if hasattr(curses, 'A_ITALIC') else curses.A_REVERSE + attr_italic = curses.A_ITALIC if hasattr( + curses, 'A_ITALIC') else curses.A_REVERSE while format_char != -1: if text[format_char] == '\n': attr_char = '|' diff --git a/poezio/xhtml.py b/poezio/xhtml.py index 28f50b5a..170ea8d3 100644 --- a/poezio/xhtml.py +++ b/poezio/xhtml.py @@ -213,9 +213,11 @@ def get_body_from_message_stanza(message, content = content if content else message['body'] return content or " " + def rgb_to_html(rgb): r, g, b = rgb - return '#%02X%02X%02X' % (round(r*255), round(g*255), round(b*255)) + return '#%02X%02X%02X' % (round(r * 255), round(g * 255), round(b * 255)) + def ncurses_color_to_html(color): """ @@ -225,6 +227,7 @@ def ncurses_color_to_html(color): """ return rgb_to_html(ncurses_color_to_rgb(color)) + def _parse_css_color(name): if name[0] == '#': name = name[1:] |