def blue(values, feature, parent): """ Returns the blue component of a color <p><h4>Syntax</h4> blue(<i>color</i>)</p> <p><h4>Arguments</h4> <i> color</i> → a color<br></p> <p><h4>Example</h4> <!-- Show example of function.--> blue('0,0,255') → 255</p> """ try: return QgsSymbolLayerV2Utils.decodeColor(values[0]).blue() except: return None
def alpha(values, feature, parent): """ Returns the alpha component of a color <p><h4>Syntax</h4> alpha(<i>color</i>)</p> <p><h4>Arguments</h4> <i> color</i> → a color<br></p> <p><h4>Example</h4> <!-- Show example of function.--> alpha('255,255,255,125') → 125</p> """ try: return QgsSymbolLayerV2Utils.decodeColor(values[0]).alpha() except: return None
def hsv_value(values, feature, parent): """ Returns the hsv value component of a color, an integer between 0-100 <p><h4>Syntax</h4> hsv_value(<i>color</i>)</p> <p><h4>Arguments</h4> <i> color</i> → a color<br></p> <p><h4>Example</h4> <!-- Show example of function.--> hsv_value('125,255,125') → 100</p> """ try: # Value ranges from 0 - 100 return int(QgsSymbolLayerV2Utils.decodeColor(values[0]).valueF() * 100) except: return None
def lightness(values, feature, parent): """ Returns the lightness of a color, an integer between 0-100 <p><h4>Syntax</h4> lightness(<i>color</i>)</p> <p><h4>Arguments</h4> <i> color</i> → a color<br></p> <p><h4>Example</h4> <!-- Show example of function.--> lightness('125,255,125') → 74</p> """ try: # Lightness ranges from 0 - 100 return int(QgsSymbolLayerV2Utils.decodeColor(values[0]).lightnessF() * 100) except: return None
def saturation(values, feature, parent): """ Returns the saturation of a color, an integer between 0-100 <p><h4>Syntax</h4> saturation(<i>color</i>)</p> <p><h4>Arguments</h4> <i> color</i> → a color<br></p> <p><h4>Example</h4> <!-- Show example of function.--> saturation('125,255,125') → 50</p> """ try: # Saturation ranges from 0 - 100 return int(QgsSymbolLayerV2Utils.decodeColor(values[0]).saturationF() * 100) except: return None
def hue(values, feature, parent): """ Returns the hue component of a color, an integer between 0-360 <p><h4>Syntax</h4> hue(<i>color</i>)</p> <p><h4>Arguments</h4> <i> color</i> → a color<br></p> <p><h4>Example</h4> <!-- Show example of function.--> hue('255,0,0') → 0</p> """ try: # Hue ranges from 0 - 360 return int(QgsSymbolLayerV2Utils.decodeColor(values[0]).hueF() * 360) except: return None
def lightness(values, feature, parent): """ Returns the lightness of a color, an integer between 0-100 <p><h4>Syntax</h4> lightness(<i>color</i>)</p> <p><h4>Arguments</h4> <i> color</i> → a color<br></p> <p><h4>Example</h4> <!-- Show example of function.--> lightness('125,255,125') → 74</p> """ try: # Lightness ranges from 0 - 100 return int( QgsSymbolLayerV2Utils.decodeColor(values[0]).lightnessF() * 100) except: return None
def saturation(values, feature, parent): """ Returns the saturation of a color, an integer between 0-100 <p><h4>Syntax</h4> saturation(<i>color</i>)</p> <p><h4>Arguments</h4> <i> color</i> → a color<br></p> <p><h4>Example</h4> <!-- Show example of function.--> saturation('125,255,125') → 50</p> """ try: # Saturation ranges from 0 - 100 return int( QgsSymbolLayerV2Utils.decodeColor(values[0]).saturationF() * 100) except: return None
def set_alpha(values, feature, parent): """ Sets the alpha component of a color <p><h4>Syntax</h4> set_alpha(<i>color</i>, <i>alpha</i>)</p> <p><h4>Arguments</h4> <i> color</i> → a color<br> <i> alpha</i> → an alpha value between 0 and 255<br></p> <p><h4>Example</h4> <!-- Show example of function.--> set_alpha('255,255,255,255', 125) → '255,255,255,125'</p> """ try: color = QgsSymbolLayerV2Utils.decodeColor(values[0]) color.setAlpha(values[1]) return QgsSymbolLayerV2Utils.encodeColor(color) except: return None
def set_hsv_value(values, feature, parent): """ Sets the value of a color <p><h4>Syntax</h4> set_hsv_value(<i>color</i>, <i>value</i>)</p> <p><h4>Arguments</h4> <i> color</i> → a color<br> <i> value</i> → a integer between 0 and 100<br></p> <p><h4>Example</h4> <!-- Show example of function.--> set_hsv_value('0,255,0,255', 50) → '0,128,0,255'</p> """ try: color = QgsSymbolLayerV2Utils.decodeColor(values[0]) color.setHsvF(color.hueF(), color.saturationF(), values[1] / 100.0, color.alphaF()) return QgsSymbolLayerV2Utils.encodeColor(color) except: return None
def set_hue(values, feature, parent): """ Sets the hue component of a color <p><h4>Syntax</h4> set_hue(<i>color</i>, <i>hue</i>)</p> <p><h4>Arguments</h4> <i> color</i> → a color<br> <i> hue</i> → a integer between 0 and 360<br></p> <p><h4>Example</h4> <!-- Show example of function.--> set_hue('0,255,0,255', 0) → '255,0,0,255'</p> """ try: color = QgsSymbolLayerV2Utils.decodeColor(values[0]) color.setHslF(values[1] / 360.0, color.saturationF(), color.lightnessF(), color.alphaF()) return QgsSymbolLayerV2Utils.encodeColor(color) except: return None