Python webcolors.hex_to_rgb() Examples

The following are 22 code examples of webcolors.hex_to_rgb(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module webcolors , or try the search function .
Example #1
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def alternatingAddFunc(self):
        if self.alternatingList.count() == 2:
            self.error("Alternating cannot have more than two colors")
        else:
            hex_color = pick("Color")
            if hex_color is None:
                return
            color = "#" + hex_color.lower()
            actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
            if not actual:
                actual = closest
            self.alternatingList.addItem(QListWidgetItem(actual + "(" + color + ")")) 
Example #2
Source File: flux_led.py    From homebridge-magichome with MIT License 5 votes vote down vote up
def color_object_to_tuple(color):
		global webcolors_available

		# see if it's already a color tuple
		if type(color) is tuple and len(color) == 3:
			return color

		# can't convert non-string
		if type(color) is not str:
			return None
		color = color.strip()

		if webcolors_available:
			# try to convert from an english name
			try:
				return webcolors.name_to_rgb(color)
			except ValueError:
				pass
			except:
				pass

			# try to convert an web hex code
			try:
				return webcolors.hex_to_rgb(webcolors.normalize_hex(color))
			except ValueError:
				pass
			except:
				pass

		# try to convert a string RGB tuple
		try:
			val = ast.literal_eval(color)
			if type(val) is not tuple or len(val) != 3:
				raise Exception
			return val
		except:
			pass
		return None 
Example #3
Source File: AYABPNGBuilder.py    From knittingpattern with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _convert_rrggbb_to_image_color(self, rrggbb):
        """:return: the color that is used by the image"""
        return webcolors.hex_to_rgb(rrggbb) 
Example #4
Source File: images.py    From blockdiag with Apache License 2.0 5 votes vote down vote up
def color_to_rgb(color):
    import webcolors
    if color == 'none' or isinstance(color, (list, tuple)):
        rgb = color
    elif re.match('#', color):
        rgb = webcolors.hex_to_rgb(color)
    else:
        rgb = webcolors.name_to_rgb(color)

    return rgb 
Example #5
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def animatedEditFunc(self):
        hex_color = pick("Color")
        if hex_color is None:
            return
        color = "#" + hex_color.lower()
        actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
        if not actual:
            actual = closest
        
        for widgetItem in self.animatedTable.selectedItems():
            if widgetItem.column() != 0:
                widgetItem.setText(actual + "(" + color + ")")
                widgetItem.setBackground(QColor(*webcolors.hex_to_rgb(color)))
                if self.animatedList.currentRow() != -1:
                    self.animatedColors[self.animatedList.currentRow()][widgetItem.row()] = color[1:] 
Example #6
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def populateAnimatedColors(self, colors):
        for index, i in enumerate(colors):
            actual, closest = get_colour_name(webcolors.hex_to_rgb('#' + i))
            if not actual:
                actual = closest
            self.animatedTable.setItem(index, 0, QTableWidgetItem(str(index+1)))
            self.animatedTable.setItem(index, 1, QTableWidgetItem(actual + '(#' + i + ')'))
            self.animatedTable.item(index, 1).setBackground(QColor(*webcolors.hex_to_rgb('#' + i))) 
Example #7
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def populateAnimated(self):
        actual, closest = get_colour_name(webcolors.hex_to_rgb('#FFFFFF'))
        if not actual:
            actual = closest
        for i in range(40):
            self.animatedTable.setItem(i, 0, QTableWidgetItem(str(i+1)))
            self.animatedTable.setItem(i, 1, QTableWidgetItem(actual + '(#FFFFFF)')) 
Example #8
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def customEditFunc(self):
        hex_color = pick("Color")
        if hex_color is None:
            return
        color = "#" + hex_color.lower()
        actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
        if not actual:
            actual = closest
        
        for widgetItem in self.customTable.selectedItems():
            if widgetItem.column() != 0:
                widgetItem.setText(actual + "(" + color + ")")
                widgetItem.setBackground(QColor(*webcolors.hex_to_rgb(color))) 
Example #9
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def audioLevelAddFunc(self):
        hex_color = pick("Color")
        if hex_color is None:
            return
        color = "#" + hex_color.lower()
        actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
        if not actual:
            actual = closest
        self.audioLevelList.addItem(QListWidgetItem(actual + "(" + color + ")")) 
Example #10
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def wingsAddFunc(self):
        if self.wingsList.count() == 1:
            self.error("Wings cannot have more than 1 color")
        else:
            hex_color = pick("Color")
            if hex_color is None:
                return
            color = "#" + hex_color.lower()
            actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
            if not actual:
                actual = closest
            self.wingsList.addItem(QListWidgetItem(actual + "(" + color + ")")) 
Example #11
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def candleAddFunc(self):
        if self.candleList.count() == 1:
            self.error("Candle cannot have more than 1 color")
        else:
            hex_color = pick("Color")
            if hex_color is None:
                return
            color = "#" + hex_color.lower()
            actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
            if not actual:
                actual = closest
            self.candleList.addItem(QListWidgetItem(actual + "(" + color + ")")) 
Example #12
Source File: __main__.py    From flux_led with GNU Lesser General Public License v3.0 5 votes vote down vote up
def color_object_to_tuple(color):
        global webcolors_available

        # see if it's already a color tuple
        if type(color) is tuple and len(color) in [3, 4, 5]:
            return color

        # can't convert non-string
        if type(color) is not str:
            return None
        color = color.strip()

        if webcolors_available:
            # try to convert from an english name
            try:
                return webcolors.name_to_rgb(color)
            except ValueError:
                pass
            except:
                pass

            # try to convert an web hex code
            try:
                return webcolors.hex_to_rgb(webcolors.normalize_hex(color))
            except ValueError:
                pass
            except:
                pass

        # try to convert a string RGB tuple
        try:
            val = ast.literal_eval(color)
            if type(val) is not tuple or len(val) not in [3, 4, 5]:
                raise Exception
            return val
        except:
            pass
        return None 
Example #13
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def pulseAddFunc(self):
        color = "#" + pick("Color").lower()
        actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
        if not actual:
            actual = closest
        self.pulseList.addItem(QListWidgetItem(actual + "(" + color + ")")) 
Example #14
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def marqueeAddFunc(self):
        if self.marqueeList.count() == 1:
            self.error("Marquee cannot have more than one color")
        else:
            hex_color = pick("Color")
            if hex_color is None:
                return
            color = "#" + hex_color.lower()
            actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
            if not actual:
                actual = closest
            self.marqueeList.addItem(QListWidgetItem(actual + "(" + color + ")")) 
Example #15
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def fadingAddFunc(self):
        hex_color = pick("Color")
        if hex_color is None:
            return
        color = "#" + hex_color.lower()
        actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
        if not actual:
            actual = closest
        self.fadingList.addItem(QListWidgetItem(actual + "(" + color + ")")) 
Example #16
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def breathingAddFunc(self):
        color = "#" + pick("Color").lower()
        actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
        if not actual:
            actual = closest
        self.breathingList.addItem(QListWidgetItem(actual + "(" + color + ")")) 
Example #17
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def fixedAddFunc(self):
        if self.fixedList.count() == 1:
            self.error("Fixed cannot have more than one color")
        else:
            hex_color = pick("Color")
            if hex_color is None:
                return
            color = "#" + hex_color.lower()
            actual, closest = get_colour_name(webcolors.hex_to_rgb(color))
            if not actual:
                actual = closest
            self.fixedList.addItem(QListWidgetItem(actual + "(" + color + ")")) 
Example #18
Source File: hue_ui.py    From hue-plus with GNU General Public License v3.0 5 votes vote down vote up
def closest_colour(requested_colour):
    min_colours = {}
    for key, name in webcolors.css3_hex_to_names.items():
        r_c, g_c, b_c = webcolors.hex_to_rgb(key)
        rd = (r_c - requested_colour[0]) ** 2
        gd = (g_c - requested_colour[1]) ** 2
        bd = (b_c - requested_colour[2]) ** 2
        min_colours[(rd + gd + bd)] = name
    return min_colours[min(min_colours.keys())] 
Example #19
Source File: colors.py    From ImageSoup with MIT License 5 votes vote down vote up
def closest_color(requested_color):
    min_colors = {}
    for key, name in webcolors.css3_hex_to_names.items():
        r_c, g_c, b_c = webcolors.hex_to_rgb(key)
        rd = (r_c - requested_color[0]) ** 2
        gd = (g_c - requested_color[1]) ** 2
        bd = (b_c - requested_color[2]) ** 2
        min_colors[(rd + gd + bd)] = name
    return min_colors[min(min_colors.keys())] 
Example #20
Source File: Utils_Image.py    From Tensorflow_Object_Tracking_Video with MIT License 5 votes vote down vote up
def closest_colour(requested_colour):
    min_colours = {}
    for key, name in webcolors.css3_hex_to_names.items():
        r_c, g_c, b_c = webcolors.hex_to_rgb(key)
        rd = (r_c - requested_colour[0]) ** 2
        gd = (g_c - requested_colour[1]) ** 2
        bd = (b_c - requested_colour[2]) ** 2
        min_colours[(rd + gd + bd)] = name
    return min_colours[min(min_colours.keys())] 
Example #21
Source File: com.py    From wordinserter with MIT License 5 votes vote down vote up
def hex_to_wdcolor(value):
        """
        Receive a HEX color attribute string like '#9bbb59' (or '9bbb59') and transform it to a numeric constant
        in order to use it as a Selection.Font.Color attribute (as an item of WdColor enumeration)
        :param value: A HEX color attribute
        :return: A numeric WDCOLOR value
        """
        rgbstrlst = webcolors.hex_to_rgb(value)
        return int(rgbstrlst[0]) + 0x100 * int(rgbstrlst[1]) + 0x10000 * int(rgbstrlst[2]) 
Example #22
Source File: color.py    From ssbio with MIT License 5 votes vote down vote up
def closest_colour(requested_colour):
    min_colours = {}
    for key, name in webcolors.css3_hex_to_names.items():
        r_c, g_c, b_c = webcolors.hex_to_rgb(key)
        rd = (r_c - requested_colour[0]) ** 2
        gd = (g_c - requested_colour[1]) ** 2
        bd = (b_c - requested_colour[2]) ** 2
        min_colours[(rd + gd + bd)] = name
    return min_colours[min(min_colours.keys())]