Example #1
0
 def StringToValue(self, s, flags):
     
     s = remove_double_quote(s).strip()
     # For emtpy value.
     if s == '': 
         return True, None
     
     # Try to parse hex string.
     if s[0] == '#':
         try:
             if len(s) == 7: # RGB.
                 r, g, b = colour.hex2rgb(s)
                 return True, (255*r,255*g,255*b)
             elif len(s) == 9: # RGBA.
                 r, g, b = colour.hex2rgb(s[:-2])
                 a = int(s[-2:], 16)
                 return True, (255*r,255*g,255*b,a)
             else:
                 return False
         except:
             return False
     # Try to parse HSV string.
     elif s[0].isdigit() or s[0] == '.': # Try to parse numbers
         try:
             # If get single int value.
             if s.isdigit():
                 return True, int(s)
             else:
                 h,s,v = map(float, s.split(' '))
                 rgb = wx.Image.HSVtoRGB(wx.Image_HSVValue(h,s,v))
                 return True, (rgb.red, rgb.green, rgb.blue)
         except:
             return False
         
     # Color in string.
     else:
         scheme = self.__get_current_scheme()
         if scheme is None:
             return True, s
         
         colors = get_colors_in_schcme(scheme).keys()
         if s.lower() not in colors:
             return False
         
         return True, s
Example #2
0
	def cb4( self, color, dontconvert=False ):
		if isinstance( color, str ):
			regex = re.compile( r'^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$', re.IGNORECASE )
			if regex.match( color ):
				if dontconvert is False:
					rgb = colour.hex2rgb( color )
					color = colour.rgb2hsv( rgb )
				else:
					print("pass")
					return color
			else:
				return "hexidecimal:", color, "isn't a hexidecimal"
		elif isinstance( color, list ):
			rgb = colour.hsv2rgb(  tuple( color[:3] ) )
			color = colour.rgb2hex( rgb, force_long=True )
		else:
				return False
		return color
 def get(self):
     return hex2rgb(self['bg'])
 def get(self):
     colours = []
     for colList in self.colGrid:
         for box in colList:
             colours.append(hex2rgb(self.itemcget(box, 'fill')))
     return colours