Package muntjac :: Package addon :: Package invient :: Module color
[hide private]
[frames] | no frames]

Source Code for Module muntjac.addon.invient.color

  1  # @INVIENT_COPYRIGHT@ 
  2  #  
  3  # Licensed under the Apache License, Version 2.0 (the "License");  
  4  # you may not use this file except in compliance with the License.  
  5  # You may obtain a copy of the License at  
  6  #  
  7  #     http://www.apache.org/licenses/LICENSE-2.0  
  8  #  
  9  # Unless required by applicable law or agreed to in writing, software  
 10  # distributed under the License is distributed on an "AS IS" BASIS,  
 11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
 12  # See the License for the specific language governing permissions and  
 13  # limitations under the License. 
 14   
 15  from muntjac.addon.invient.paint import IPaint 
 16  from muntjac.addon.colorpicker.color import Color 
 17   
 18   
19 -class Color(IPaint):
20 """The Color interface represents RBG and RBGA colors. 21 Do not confuse with L{Color} class. This is a simplified 22 version of L{Color} for the purpose of InvientCharts 23 24 @author: Invient 25 @author: Richard Lincoln 26 """ 27 pass
28 29
30 -class RGB(Color):
31 """Represents RBG color value. 32 33 @author: Invient 34 @author: Richard Lincoln 35 """ 36
37 - def __init__(self, red, green, blue):
38 """Creates an RGB color with the specified red, green, and blue values. 39 The values must be in the range (0 - 255). 40 41 @param red: 42 the red component in a color 43 @param green: 44 the green component in a color 45 @param blue: 46 the blue component in a color 47 """ 48 super(RGB, self).__init__() 49 errorCompString = '' 50 hasError = False 51 if (red < 0) or (red > 255): 52 hasError = True 53 errorCompString = ' Red ' 54 55 if (green < 0) or (green > 255): 56 hasError = True 57 errorCompString += ' Green' 58 59 if (blue < 0) or (blue > 255): 60 hasError = True 61 errorCompString += ' Blue' 62 63 if hasError: 64 raise ValueError('Color parameter outside of expected range:' 65 + errorCompString) 66 67 self._red = red 68 self._green = green 69 self._blue = blue
70 71
72 - def getRed(self):
73 """@return: Returns the red component in the range (0-255).""" 74 return self._red
75 76
77 - def getGreen(self):
78 """@return: Returns the green component in the range (0-255).""" 79 return self._green
80 81
82 - def getBlue(self):
83 """@return: Returns the blue component in the range (0-255).""" 84 return self._blue
85 86
87 - def getString(self):
88 """@return: Returns string representation of this RBG.""" 89 return ('rgb(' + str(self._red) + ',' + str(self._green) + ',' 90 + str(self._blue) + ')')
91 92
93 - def __str__(self):
94 """@return: Returns string representation of this RBG.""" 95 return ('RGB [red=' + str(self._red) + ', green=' + str(self._green) 96 + ', blue=' + str(self._blue) + ']')
97 98
99 -class RGBA(RGB):
100 """Represents RGBA color value. 101 102 @author Invient 103 @author: Richard Lincoln 104 """ 105
106 - def __init__(self, red, green, blue, alpha):
107 """Creates an RGBA color with the specified red, green, blue and alpha 108 values. The red, green and blue values must be in the range (0 - 109 255). The alpha value must be in the range (0.0-1.0). The alpha value 110 deaults to 1.0 111 112 @param red: 113 the red component in a color 114 @param green: 115 the green component in a color 116 @param blue: 117 the blue component in a color 118 @param alpha: 119 the alpha component in a color 120 """ 121 super(RGBA, self).__init__(red, green, blue) 122 123 if (alpha < 0.0) or (alpha > 1.0): 124 errorCompString = ' Alpha' 125 raise ValueError('Color parameter outside of expected range: ' 126 + errorCompString) 127 128 self._alpha = alpha
129 130
131 - def getAlpha(self):
132 """@return: Returns the alpha component in the range (0.0-1.0).""" 133 return self._alpha
134 135
136 - def getString(self):
137 """@return: Returns string representation of this RGBA""" 138 return ('rgba(' + str(self.getRed()) + ',' + str(self.getGreen()) 139 + ',' + str(self.getBlue()) + ',' + str(self._alpha) + ')')
140 141
142 - def __str__(self):
143 """@return: Returns string representation of this RGBA""" 144 return ('RGBA [alpha=' + str(self._alpha) 145 + ', red=' + str(self.getRed()) 146 + ', green=' + str(self.getGreen()) 147 + ', blue=' + str(self.getBlue()) 148 + ']')
149