def existing_style(pref_name, name="", prio=-1): """ Creates a new style to apply when a matcher succeeds, using an existing style as a basis. This probably should not be used directly, but one should use one of the existing styles declared in :func:`Highlighter.common` :param string pref_name: The name of the preference to bind to the style :param string name: The name of the style, used for the underlying gtk tag :param int prio: The priority of the style compared to others. Higher priority styles will take precedence over lower priority ones. -1 means default priority: tags added last have precedence. :rtype: highlighter.engine.Style """ try: from highlighter.engine import Style, HighlighterModule style_id = "{0}_hl".format(name if name else pref_name) pref = GPS.Preference(pref_name) pref.tag = None HighlighterModule.preferences[style_id] = pref return Style(style_id, prio, pref) except Exception: pass # TODO: remove this exception handler, used for doc framework
def new_style(lang, name, label, doc, foreground_colors, background_colors=("transparent", "transparent"), font_style="default", prio=-1): """ Creates a new style to apply when a matcher successfully matches a portion of text. A style is the conflation of - An editor tag with corresponding text style - A user preference that will be added to the corresponding language page :param string lang: The language for which this style will be applicable . This is used to automatically store the preference associated with this style in the right preferences subcategory. :param string name: The name of the style, used to identify it. :param string label: The label that will be shown in the preferences dialog for this style. :param string doc: The documentation that will be shown in the preferences dialog for this style. :param foreground_colors: The foreground colors of the style, expressed as a tuple of two CSS-like strings, for example ("#224488", "#FF6677"). The first color is used for light themes, the second is used for dark themes :type foreground_colors: string, string :param background_colors: The background colors of the style. :type background_colors: string, string :param string font_style: : The style of the font, one of "default", "normal", "bold", "italic" or "bold_italic" :param prio: The priority of the style. This determines which style will prevail if two styles are applied to the same portion of text. See :func:`Highlighter.region` -1 means default priority: tags added last have precedence. :rtype: highlighter.engine.Style """ try: from highlighter.engine import Style, HighlighterModule import theme_handling from theme_handling import Color, transparent dark_bg_color = None light_bg_color = None if background_colors[0] == "transparent": light_bg_color = transparent else: light_bg_color = Color(background_colors[0]) if background_colors[1] == "transparent": dark_bg_color = transparent else: dark_bg_color = Color(background_colors[1]) style_id = "{0}_{1}".format(lang, name) pref_name = "Editor/Fonts & Colors:{0}/{1}".format(lang, name) pref = GPS.Preference(pref_name) pref.create_style(label, doc, foreground_colors[0], light_bg_color.to_rgba_string(), font_style) theme_handling.variant_prefs[style_id] = pref_name theme_handling.common_dark[style_id] = (font_style.upper(), Color(foreground_colors[1]), dark_bg_color) theme_handling.common_light[style_id] = (font_style.upper(), Color(foreground_colors[0]), light_bg_color) pref.tag = None HighlighterModule.preferences[style_id] = pref return Style(style_id, prio, pref) except Exception: raise # TODO: remove this exception handler, used for doc framework