Merge pull request #2784 from inclement/color_init

Added property name setters in Color __init__
This commit is contained in:
dessant 2015-01-21 23:29:00 +02:00
commit b3b20e92b9
1 changed files with 12 additions and 1 deletions

View File

@ -183,7 +183,12 @@ cdef class Color(ContextInstruction):
# using hsv mode + alpha # using hsv mode + alpha
c = Color(0, 1, 1, .2, mode='hsv') 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::
<Rule>: <Rule>:
canvas: canvas:
@ -225,6 +230,12 @@ cdef class Color(ContextInstruction):
else: else:
self.set_state('color', [1.0, 1.0, 1.0, 1.0]) 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: property rgba:
'''RGBA color, list of 4 values in 0-1 range. '''RGBA color, list of 4 values in 0-1 range.
''' '''