From e8e5f6c756a9aa18c078d6441c62a6f736d2fd70 Mon Sep 17 00:00:00 2001 From: David Mazary Date: Sun, 18 Mar 2012 15:34:35 -0300 Subject: [PATCH] Change font color instead of using a css class. --- xonstat/util.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/xonstat/util.py b/xonstat/util.py index 75db20f..0afa654 100755 --- a/xonstat/util.py +++ b/xonstat/util.py @@ -1,5 +1,5 @@ import re -from colorsys import rgb_to_hls +from colorsys import rgb_to_hls, hls_to_rgb from cgi import escape as html_escape from datetime import datetime @@ -59,6 +59,9 @@ _all_colors = re.compile(r'\^(\d|x[\dA-Fa-f]{3})') _dec_colors = re.compile(r'\^(\d)') _hex_colors = re.compile(r'\^x([\dA-Fa-f])([\dA-Fa-f])([\dA-Fa-f])') +# On a light scale of 0 (black) to 255 (white) +_contrash_threshold = 128 + def qfont_decode(qstr=''): """ Convert the qfont characters in a string to ascii. @@ -84,8 +87,10 @@ def hex_repl(match): g = match.group(2) * 2 b = match.group(3) * 2 hue, light, satur = rgb_to_hls(int(r, 16), int(g, 16), int(b, 16)) - klass = 'text_dark' if light < 0x80 else 'text_light' - return ''.format(r, g, b, klass) + if light < _contrash_threshold: + light = _contrash_threshold + r, g, b = hls_to_rgb(hue, light, satur) + return ''.format(r, g, b) def html_colors(qstr=''): -- 2.39.2