X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=xonstat%2Futil.py;h=1bea47c94d8100e3047464dc6601657d010d9de3;hb=8c670addca3e7870b12252cfed7b546c43ff4560;hp=e88c6b35942b1ac5af3bb8fbc2fec9ba9bdd7121;hpb=82ef398df91182a3f1bcc446092300b65ab83556;p=xonotic%2Fxonstat.git diff --git a/xonstat/util.py b/xonstat/util.py old mode 100755 new mode 100644 index e88c6b3..1bea47c --- a/xonstat/util.py +++ b/xonstat/util.py @@ -42,16 +42,16 @@ _qfont_table = [ # Hex-colored spans for decimal color codes ^0 - ^9 _dec_spans = [ - "", - "", - "", - "", - "", - "", - "", - "", - "", - "" + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" ] # Color code patterns @@ -80,19 +80,25 @@ def strip_colors(qstr=''): if qstr == None: qstr = '' return _all_colors.sub('', qstr) - - + + def hex_repl(match): - # Convert hex to 8 bits and to 0.0-1.0 scale - r = 255. / int(match.group(1) * 2, 16) - g = 255. / int(match.group(2) * 2, 16) - b = 255. / int(match.group(3) * 2, 16) + """Convert Darkplaces hex color codes to CSS rgb. + Brighten colors with HSL light value less than 50%""" + + # Extend hex char to 8 bits and to 0.0-1.0 scale + r = int(match.group(1) * 2, 16) / 255.0 + g = int(match.group(2) * 2, 16) / 255.0 + b = int(match.group(3) * 2, 16) / 255.0 + + # Check if color is too dark hue, light, satur = rgb_to_hls(r, g, b) if light < _contrast_threshold: light = _contrast_threshold - # Get new rgb in 0-255 scale - r, g, b = map((255).__mul__, hls_to_rgb(hue, light, satur)) - return ''.format(r, g, b) + r, g, b = hls_to_rgb(hue, light, satur) + + # Convert back to 0-255 scale for css + return '' % (255 * r, 255 * g, 255 * b) def html_colors(qstr=''): @@ -112,7 +118,7 @@ def pretty_date(time=False): pretty string like 'an hour ago', 'Yesterday', '3 months ago', 'just now', etc """ - now = datetime.now() + now = datetime.utcnow() if type(time) is int: diff = now - datetime.fromtimestamp(time) elif isinstance(time,datetime):