Exemplo n.º 1
0
    def theme(self):
        """ Return a dictionary of preferences
        """
        d = {}  # The result dict

        d['name'] = self.name

        if 'foreground' in self.general and 'background' in self.general:
            fg_color = Color(self.general['foreground'])
            # Do not use transparency for the foreground
            fg_color.a = 1.0
            bg_color = Color(self.general['background'])
        else:
            # Warn if theme does not provide these essential elements
            GPS.Console("Messages").write(
                "Background or foreground not found in textmate theme '%s'.\n"
                % self.name)

            fg_color = Color("#000000")
            bg_color = Color("#ffffff")

        fg_lum = fg_color.get_luminosity()
        bg_lum = bg_color.get_luminosity()

        # The right way to get the luminosity of a theme is to compare the
        # background and the foreground.

        is_light = bg_lum > fg_lum
        light_val = is_light * 1 + (not is_light) * -1  # to use in equations

        # Go through all the scopes being specified, and attempt to find
        # a match for a GPS pref
        for theme_pref_dict in self.o['settings'][1:]:
            prefs = to_GPS_prefs(theme_pref_dict)
            for p in prefs:
                d[p[0]] = p[1]

        # Get the general settings

        d["editor_fg"] = fg_color
        d["editor_bg"] = bg_color

        # Compute the selection

        # ??? The selection is generally too close to the line highlight
        # in textmate themes: do not read the selection from these themes.

        # if 'selection' in self.general:
        #     d['@theme_selected_bg_color'] = self.general['selection']
        #     d['@editor_bg_selection'] = self.general['selection']

        # ... instead, invert the default fg and bg.

        d['theme_selected_bg'] = fg_color
        d['theme_selected_fg'] = bg_color

        # Compute nice browser settings

        d["browsers_bg"] = bg_color

        d['browser_decoration_fg'] = fg_color.lighten(0.07 * light_val)
        d['browser_decoration_bg'] = bg_color.lighten(-0.05 * light_val)

        # Caret

        if 'caret' in self.general:
            # The following preferences are derived from the caret color:
            # caret, current line, and current block.

            d["caret"] = Color(self.general['caret'])

        # Ignore the line highlight in textmate themes. instead,
        # compute them from the background.

        cl_color = bg_color.lighten(-0.15 * light_val)
        cl_color.a = 0.5
        d["current_line"] = cl_color

        cb_color = fg_color.lighten(0.25 * light_val)
        cb_color.a = 0.5
        d["current_block"] = cb_color
        d["annotations"] = ("DEFAULT", transparent, cl_color)

        # Compute values for the auto-highlight-occurrences

        # For the simple case, compute the color by lightening accordingly
        # the editor's bakckground color.
        e_simple_color = bg_color.lighten(-0.25 * light_val)
        e_simple_color.a = 0.5
        d["ephemeral_simple"] = ("DEFAULT", transparent, e_simple_color)

        # For the smart cases, use preferably the keywords fg color but
        # applying some alpha to it. Otherwise fallback to the default
        # foreground color with some alpha too.
        e_smart_color = Color(from_hex=fg_color.to_hex6_string())
        if "keywords" in d:
            e_smart_color = Color(from_hex=d["keywords"][1].to_hex6_string())

        e_smart_color.a = 0.2

        d["ephemeral_smart"] = ("DEFAULT", transparent, e_smart_color)

        return Theme(self.name, is_light, d)
Exemplo n.º 2
0
    from gi.repository import Gtk, Gdk
except ImportError:
    pass

logger = GPS.Logger("COLORSCHEMES")

STYLE_WARNING = GPS.Style.create_from_preferences(
    "editor-warnings", "", "Medium-Importance-Messages-Highlight")
STYLE_ERROR = GPS.Style.create_from_preferences(
    "editor-errors", "", "High-Importance-Messages-Highlight")

_VIEW_TITLE = "Color Theme"

default = Theme(
    "Default", True, {
        "theme_selected_bg": Rgba(74, 144, 217),
        "theme_selected_fg": Rgba(255, 255, 255, 255),
    })

darkside = Theme("Darkside", False, {})

color_theme_pref = GPS.Preference("/Color-Theme").create(
    "Color theme", "string", "Darkside")

monokai = Theme(
    "Monokai", False, {
        "debugger_current": Rgba(58, 71, 54, 153),
        "current_line": Rgba(73, 72, 62),
        "editor_fg": Rgba(248, 248, 242),
        "editor_bg": Rgba(39, 40, 34),
        "hyperlinks": ("DEFAULT", Rgba(114, 159, 207), transparent),