From 5eb0aa6c288b16432261e54174cbc31cc944afd1 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Wed, 24 Dec 2014 14:48:58 +0000 Subject: [PATCH 1/2] Added property name setters in Color __init__ --- kivy/graphics/context_instructions.pyx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kivy/graphics/context_instructions.pyx b/kivy/graphics/context_instructions.pyx index a28a52a8f..2f9c8b688 100644 --- a/kivy/graphics/context_instructions.pyx +++ b/kivy/graphics/context_instructions.pyx @@ -225,6 +225,12 @@ cdef class Color(ContextInstruction): else: self.set_state('color', [1.0, 1.0, 1.0, 1.0]) + for property_name in ['r', 'g', 'b', 'a', + 'rgb', 'rgba', 'hsv', + 'h', 's', 'v']: + if property_name in kwargs: + setattr(self, property_name, kwargs['property_name']) + property rgba: '''RGBA color, list of 4 values in 0-1 range. ''' From 417ca16365d1704489869c2293c1f3c79568d4af Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Wed, 24 Dec 2014 15:06:15 +0000 Subject: [PATCH 2/2] doc: Added doc for color property setting in init --- kivy/graphics/context_instructions.pyx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kivy/graphics/context_instructions.pyx b/kivy/graphics/context_instructions.pyx index 2f9c8b688..77f9041c2 100644 --- a/kivy/graphics/context_instructions.pyx +++ b/kivy/graphics/context_instructions.pyx @@ -183,7 +183,12 @@ cdef class Color(ContextInstruction): # using hsv mode + alpha c = Color(0, 1, 1, .2, mode='hsv') - In kv lang:: + You can also set color components that are available as properties + by passing them as keyword arguments:: + + c = Color(b=0.5) # sets the blue component only + + In kv lang you can set the color properties directly:: : canvas: @@ -229,7 +234,7 @@ cdef class Color(ContextInstruction): 'rgb', 'rgba', 'hsv', 'h', 's', 'v']: if property_name in kwargs: - setattr(self, property_name, kwargs['property_name']) + setattr(self, property_name, kwargs[property_name]) property rgba: '''RGBA color, list of 4 values in 0-1 range.