def at(self, v0, v1, t): """ Returns the color value along the path at time t for a path whose start value is v0, and whose end value is v1. """ c0 = normalized_color(v0, has_alpha=True, as_int=False) c1 = normalized_color(v1, has_alpha=True, as_int=False) h0, l0, s0 = rgb_to_hls(*c0[:3]) h1, l1, s1 = rgb_to_hls(*c1[:3]) return hls_to_rgb( h0 + ((h1 - h0) * t * self.use_h), l0 + ((l1 - l0) * t * self.use_l), s0 + ((s1 - s0) * t * self.use_s) ) + (c0[3] + ((c1[3] - c0[3]) * t * self.use_a),)
def validate ( self, object, name, value ): """ Validates that a specified value is valid for this facet. """ try: return normalized_color( value, True, False ) except: self.error( object, name, value )
def validate ( self, object, name, value ): """ Validates that a specified value is valid for this facet. """ try: r, g, b, a = normalized_color( value, True ) return (((255 - a) << 24) + (r << 16) + (g << 8) + b) except: self.error( object, name, value )
def validate ( self, object, name, value ): """ Validates that a specified value is valid for this facet. """ try: from colorsys import rgb_to_hls h, l, s = rgb_to_hls( *normalized_color( value, False, False ) ) return ( int( round( 360.0 * h ) ) % 360, l, s ) except: self.error( object, name, value )
def convert_to_color ( object, name, value ): """ Converts a number into a QColor object. """ if isinstance( value, QColor ): return value if isinstance( value, ColorTypes ): return QColor( *normalized_color( value, has_alpha = True ) ) color = None if isinstance( value, basestring ): # Allow for spaces in the string value: value = value.replace( ' ', '' ) else: # Try the toolkit agnostic format: try: tup = eval( value ) if isinstance( tup, tuple ): if 3 <= len( tup ) <= 4: try: color = QColor( *tup ) except TypeError: raise FacetError else: raise FacetError except: pass if color is None: # Let the constructor handle the value: try: color = QColor( value ) except TypeError: raise FacetError if color.isValid(): return color raise FacetError