Example #1
0
 def __init__(self, parent, scheme='x11'):
     ColorSingleChoiceDialog.__init__(self, parent)
     
     self.SetTitle('Pick a color')
     self.m_staticText_message.SetLabel('Select a color in "%s":'%scheme)
     
     self.choice = get_colors_in_schcme(scheme)
     
     self.updateList()
     
     self.m_list.Bind(wx.EVT_LEFT_DCLICK, self.onOK)
Example #2
0
    def __init__(self, parent, scheme='x11'):
        ColorSingleChoiceDialog.__init__(self, parent)

        self.SetTitle('Pick a color')
        self.m_staticText_message.SetLabel('Select a color in "%s":' % scheme)

        self.choice = get_colors_in_schcme(scheme)

        self.updateList()

        self.m_list.Bind(wx.EVT_LEFT_DCLICK, self.onOK)
Example #3
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 #4
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