示例#1
0
    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)))
示例#2
0
    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
示例#3
0
    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
示例#4
0
    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