Ejemplo n.º 1
0
	def parse_scheme(self, scheme_path):
		if int(sublime.version()) >= 3000:
			xml = sublime.load_resource(scheme_path)
			try:
				plist = parser.parse_string(xml)
			except (parser.PropertyListParseError):
				print('Error parsing ' + scheme_path)
				return (0, 0, 0)
		else:
			xml = os.path.join(sublime.packages_path(), scheme_path.replace('Packages/', ''))
			try:
				plist = parser.parse_file(xml)
			except (parser.PropertyListParseError):
				print('Error parsing ' + scheme_path)
				return (0, 0, 0)

		try:
			background_colour = plist['settings'][0]['settings']['background'].lstrip('#')
		except (KeyError): # tmTheme is missing a background colour
			return (0, 0, 0)

		if len(background_colour) is 3:
			# Shorthand value, e.g. #111
			# Repeat the values for correct base 16 conversion
			r, g, b = background_colour[:1] + background_colour[:1], background_colour[1:2] + background_colour[1:2], background_colour[2:] + background_colour[2:]
		else:
			# Full-length colour value, e.g. #111111 or #FFEEEEEE
			# Here we assume the order of hex values is #AARRGGBB
			# and so work backwards from the end of the string.
			r, g, b = background_colour[-6:-4], background_colour[-4:-2], background_colour[-2:]

		r, g, b = [int(n, 16) for n in (r, g, b)]
		return (r, g, b)
Ejemplo n.º 2
0
    def parse_scheme(self, scheme_path):
        if not is_ST2:
            try:
                xml = sublime.load_resource(scheme_path)
            except:
                print('Error loading ' + scheme_path)
                return False
            try:
                plist = parser.parse_string(xml)
            except (parser.PropertyListParseError):
                print('Error parsing ' + scheme_path)
                return False
        else:
            xml = os.path.join(sublime.packages_path(),
                               scheme_path.replace('Packages/', ''))
            try:
                plist = parser.parse_file(xml)
            except (parser.PropertyListParseError):
                print('Error parsing ' + scheme_path)
                return False

        try:
            background_color = plist['settings'][0]['settings'][
                'background'].lstrip('#')
        except (KeyError):  # tmTheme is missing a background color
            return False

        if len(background_color) is 3:
            # Shorthand value, e.g. #111
            # Repeat the values for correct base 16 conversion.
            r, g, b = [background_color[i:i + 1] * 2 for i in range(0, 3)]
        else:
            # Full-length color value, e.g. #111111 or #FFEEEEEE
            # Here we assume the order of hex values is #RRGGBB
            # or #RRGGBBAA and only use six characters.
            r, g, b = [background_color[i:i + 2] for i in range(0, 6, 2)]

        try:
            r, g, b = [int(n, 16) for n in (r, g, b)]
        except (ValueError):  # Error converting the hex value
            return False

        return (r, g, b)
Ejemplo n.º 3
0
	def parse_scheme(self, scheme_path):
		if not is_ST2:
			try:
				xml = sublime.load_resource(scheme_path)
			except:
				print('Error loading ' + scheme_path)
				return False
			try:
				plist = parser.parse_string(xml)
			except (parser.PropertyListParseError):
				print('Error parsing ' + scheme_path)
				return False
		else:
			xml = os.path.join(sublime.packages_path(), scheme_path.replace('Packages/', ''))
			try:
				plist = parser.parse_file(xml)
			except (parser.PropertyListParseError):
				print('Error parsing ' + scheme_path)
				return False

		try:
			background_color = plist['settings'][0]['settings']['background'].lstrip('#')
		except (KeyError): # tmTheme is missing a background color
			return False

		if len(background_color) is 3:
			# Shorthand value, e.g. #111
			# Repeat the values for correct base 16 conversion.
			r, g, b = [background_color[i:i+1] * 2 for i in range(0, 3)]
		else:
			# Full-length color value, e.g. #111111 or #FFEEEEEE
			# Here we assume the order of hex values is #RRGGBB
			# or #RRGGBBAA and only use six characters.
			r, g, b = [background_color[i:i+2] for i in range(0, 6, 2)]

		try:
			r, g, b = [int(n, 16) for n in (r, g, b)]
		except (ValueError): # Error converting the hex value
			return False

		return (r, g, b)
Ejemplo n.º 4
0
    def parse_scheme(self, scheme_path):
        if int(sublime.version()) >= 3000:
            xml = sublime.load_resource(scheme_path)
            try:
                plist = parser.parse_string(xml)
            except (parser.PropertyListParseError):
                print('Error parsing ' + scheme_path)
                return (0, 0, 0)
        else:
            xml = os.path.join(sublime.packages_path(),
                               scheme_path.replace('Packages/', ''))
            try:
                plist = parser.parse_file(xml)
            except (parser.PropertyListParseError):
                print('Error parsing ' + scheme_path)
                return (0, 0, 0)

        try:
            background_colour = plist['settings'][0]['settings'][
                'background'].lstrip('#')
        except (KeyError):  # tmTheme is missing a background colour
            return (0, 0, 0)

        if len(background_colour) is 3:
            # Shorthand value, e.g. #111
            # Repeat the values for correct base 16 conversion
            r, g, b = background_colour[:1] + background_colour[:1], background_colour[
                1:2] + background_colour[1:2], background_colour[
                    2:] + background_colour[2:]
        else:
            # Full-length colour value, e.g. #111111 or #FFEEEEEE
            # Here we assume the order of hex values is #AARRGGBB
            # and so work backwards from the end of the string.
            r, g, b = background_colour[-6:-4], background_colour[
                -4:-2], background_colour[-2:]

        r, g, b = [int(n, 16) for n in (r, g, b)]
        return (r, g, b)