def testHexToRGB(self): """Test that the conversion of a hex string to rgb is acurate""" hexstr = ("#FF0000", "#00FF00", "#0000FF", "#000000", "#FFFFFF") rgb = ((255, 0, 0), (0, 255, 0), (0, 0, 255), (0, 0, 0), (255, 255, 255)) for hval, rgbval in zip(hexstr, rgb): convert = tuple(util.HexToRGB(hval)) self.assertEquals( convert, rgbval, "(HexToRGB(%s) == %s) != %s" % (hval, convert, str(rgbval)))
def AddColor(self, si_color): """Takes a style item and adds it to the table if has not already been defined in the table. @param si_color: color to add to table @type si_color: hex color string """ if si_color not in self._index: rgb = util.HexToRGB(si_color.split(u',')[0]) color = "\\red%d\\green%d\\blue%d;" % tuple(rgb) self._index.append(si_color) self._tbl[si_color] = color else: pass
def GetDefaultBackColour(self, as_hex=False): """Gets the background color of the default style and returns a Colour object. Otherwise returns white if the default style is not found. @keyword hex: return a hex string or colour object @type hex: bool @return: wx.Colour of default style background or hex value @rtype: wx.Colour or string """ back = self.GetItemByName('default_style').GetBack() if back == wx.EmptyString: back = u"#FFFFFF" if not as_hex: rgb = util.HexToRGB(back[1:]) back = wx.Colour(red=rgb[0], green=rgb[1], blue=rgb[2]) return back
def GetDefaultForeColour(self, as_hex=False): """Gets the foreground color of the default style and returns a Colour object. Otherwise returns Black if the default style is not found. @keyword as_hex: return a hex string or colour object @type as_hex: bool @return: wx.Colour of default style foreground or hex value @rtype: wx.Colour or string """ fore = self.GetItemByName('default_style').GetFore() if fore == wx.EmptyString: fore = u"#000000" if not as_hex: rgb = util.HexToRGB(fore[1:]) fore = wx.Colour(red=rgb[0], green=rgb[1], blue=rgb[2]) return fore