From 85f2e0bc5ab1b077f31e8414b2311df6c058b7a4 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Mon, 19 Nov 2012 16:56:53 +0100 Subject: [PATCH] utils: simplify get_hex_from_color --- kivy/utils.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/kivy/utils.py b/kivy/utils.py index 398a0026b..5daaccdbc 100644 --- a/kivy/utils.py +++ b/kivy/utils.py @@ -95,14 +95,16 @@ def get_color_from_hex(s): def get_hex_from_color(color): - '''Transform from kivy color to hex''' - hex_clr = '#' - for clr in color: - clr = hex(int(clr * 255))[2:] - if len(str(clr)) < 2: - clr = ''.join(('0', str(clr))) - hex_clr += clr - return hex_clr + '''Transform from kivy color to hex:: + + >>> get_hex_from_color((0, 1, 0)) + '#00ff00' + >>> get_hex_from_color((.25, .77, .90, .5)) + '#3fc4e57f' + + .. versionadded:: 1.5.0 + ''' + return '#' + ''.join(['{0:02x}'.format(int(x * 255)) for x in color]) def get_random_color(alpha=1.0):