mirror of
https://github.com/fergalmoran/picard.git
synced 2026-02-17 13:13:58 +00:00
Let user configure syntax highlighting colors
This commit is contained in:
@@ -52,6 +52,13 @@ _COLOR_DESCRIPTIONS = {
|
||||
'tagstatus_added': N_("Tag added"),
|
||||
'tagstatus_changed': N_("Tag changed"),
|
||||
'tagstatus_removed': N_("Tag removed"),
|
||||
'syntax_hl_error': N_("Error syntax highlight"),
|
||||
'syntax_hl_escape': N_("Escape syntax highlight"),
|
||||
'syntax_hl_func': N_("Function syntax highlight"),
|
||||
'syntax_hl_noop': N_("Noop syntax highlight"),
|
||||
'syntax_hl_special': N_("Special syntax highlight"),
|
||||
'syntax_hl_unicode': N_("Unicode syntax highlight"),
|
||||
'syntax_hl_var': N_("Variable syntax highlight"),
|
||||
}
|
||||
|
||||
|
||||
@@ -97,6 +104,22 @@ register_color(_DARK, 'row_highlight', '#90907E')
|
||||
register_color(_LIGHT, 'first_cover_hl', 'darkgoldenrod')
|
||||
register_color(_DARK, 'first_cover_hl', 'orange')
|
||||
|
||||
# syntax highlighting colors
|
||||
register_color(_LIGHT, 'syntax_hl_error', 'blue')
|
||||
register_color(_LIGHT, 'syntax_hl_escape', 'darkRed')
|
||||
register_color(_LIGHT, 'syntax_hl_func', 'blue')
|
||||
register_color(_LIGHT, 'syntax_hl_noop', 'darkGray')
|
||||
register_color(_LIGHT, 'syntax_hl_special', 'blue')
|
||||
register_color(_LIGHT, 'syntax_hl_unicode', 'darkRed')
|
||||
register_color(_LIGHT, 'syntax_hl_var', 'darkCyan')
|
||||
register_color(_DARK, 'syntax_hl_error', '#FF57A0')
|
||||
register_color(_DARK, 'syntax_hl_escape', '#4BEF1F')
|
||||
register_color(_DARK, 'syntax_hl_func', '#FF57A0')
|
||||
register_color(_DARK, 'syntax_hl_noop', '#04E7D5')
|
||||
register_color(_DARK, 'syntax_hl_special', '#FF57A0')
|
||||
register_color(_DARK, 'syntax_hl_unicode', '#4BEF1F')
|
||||
register_color(_DARK, 'syntax_hl_var', '#FCBB51')
|
||||
|
||||
|
||||
class InterfaceColors:
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
|
||||
from collections import namedtuple
|
||||
from enum import Enum
|
||||
|
||||
from PyQt6 import (
|
||||
@@ -73,24 +72,6 @@ if IS_WIN or IS_MACOS:
|
||||
elif not IS_HAIKU:
|
||||
AVAILABLE_UI_THEMES.extend([UiTheme.SYSTEM])
|
||||
|
||||
SyntaxTheme = namedtuple('SyntaxTheme', 'func var escape special noop')
|
||||
|
||||
light_syntax_theme = SyntaxTheme(
|
||||
func=QtGui.QColor(QtCore.Qt.GlobalColor.blue),
|
||||
var=QtGui.QColor(QtCore.Qt.GlobalColor.darkCyan),
|
||||
escape=QtGui.QColor(QtCore.Qt.GlobalColor.darkRed),
|
||||
special=QtGui.QColor(QtCore.Qt.GlobalColor.blue),
|
||||
noop=QtGui.QColor(QtCore.Qt.GlobalColor.darkGray),
|
||||
)
|
||||
|
||||
dark_syntax_theme = SyntaxTheme(
|
||||
func=QtGui.QColor(255, 87, 160, 255), # magenta
|
||||
var=QtGui.QColor(252, 187, 81, 255), # orange
|
||||
escape=QtGui.QColor(75, 239, 31, 255), # green
|
||||
special=QtGui.QColor(255, 87, 160, 255), # magenta
|
||||
noop=QtGui.QColor(4, 231, 213, 255), # cyan
|
||||
)
|
||||
|
||||
|
||||
class MacOverrideStyle(QtWidgets.QProxyStyle):
|
||||
"""Override the default style to fix some platform specific issues"""
|
||||
@@ -144,10 +125,6 @@ class BaseTheme:
|
||||
def accent_color(self): # pylint: disable=no-self-use
|
||||
return None
|
||||
|
||||
@property
|
||||
def syntax_theme(self):
|
||||
return dark_syntax_theme if self.is_dark_theme else light_syntax_theme
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def update_palette(self, palette, dark_theme, accent_color):
|
||||
if accent_color:
|
||||
|
||||
@@ -31,7 +31,7 @@ from picard.i18n import gettext as _
|
||||
from picard.script import script_function_documentation_all
|
||||
|
||||
from picard.ui import FONT_FAMILY_MONOSPACE
|
||||
from picard.ui.theme import theme
|
||||
from picard.ui.colors import interface_colors
|
||||
|
||||
|
||||
DOCUMENTATION_HTML_TEMPLATE = '''
|
||||
@@ -97,7 +97,7 @@ class ScriptingDocumentationWidget(QtWidgets.QWidget):
|
||||
|
||||
html = DOCUMENTATION_HTML_TEMPLATE % {
|
||||
'html': "<dl>%s</dl>" % funcdoc,
|
||||
'script_function_fg': theme.syntax_theme.func.name(),
|
||||
'script_function_fg': interface_colors.get_qcolor('syntax_hl_func').name(),
|
||||
'monospace_font': FONT_FAMILY_MONOSPACE,
|
||||
'dir': text_direction,
|
||||
'inline_start': 'right' if text_direction == 'rtl' else 'left'
|
||||
|
||||
@@ -59,7 +59,7 @@ from picard.util.tags import (
|
||||
)
|
||||
|
||||
from picard.ui import FONT_FAMILY_MONOSPACE
|
||||
from picard.ui.theme import theme
|
||||
from picard.ui.colors import interface_colors
|
||||
|
||||
|
||||
EXTRA_VARIABLES = (
|
||||
@@ -114,7 +114,7 @@ class HighlightFormat(QtGui.QTextCharFormat):
|
||||
def __init__(self, fg_color=None, italic=False, bold=False):
|
||||
super().__init__()
|
||||
if fg_color is not None:
|
||||
self.setForeground(fg_color)
|
||||
self.setForeground(interface_colors.get_qcolor(fg_color))
|
||||
if italic:
|
||||
self.setFontItalic(True)
|
||||
if bold:
|
||||
@@ -125,16 +125,15 @@ class TaggerScriptSyntaxHighlighter(QtGui.QSyntaxHighlighter):
|
||||
|
||||
def __init__(self, document):
|
||||
super().__init__(document)
|
||||
syntax_theme = theme.syntax_theme
|
||||
|
||||
self.textcharformats = {
|
||||
'escape': HighlightFormat(fg_color=syntax_theme.escape),
|
||||
'func': HighlightFormat(fg_color=syntax_theme.func, bold=True),
|
||||
'noop': HighlightFormat(fg_color=syntax_theme.noop, bold=True, italic=True),
|
||||
'special': HighlightFormat(fg_color=syntax_theme.special),
|
||||
'unicode': HighlightFormat(fg_color=syntax_theme.escape, italic=True),
|
||||
'unknown_func': HighlightFormat(fg_color=syntax_theme.special, italic=True),
|
||||
'var': HighlightFormat(fg_color=syntax_theme.var),
|
||||
'escape': HighlightFormat(fg_color='syntax_hl_escape'),
|
||||
'func': HighlightFormat(fg_color='syntax_hl_func', bold=True),
|
||||
'noop': HighlightFormat(fg_color='syntax_hl_noop', bold=True, italic=True),
|
||||
'special': HighlightFormat(fg_color='syntax_hl_special'),
|
||||
'unicode': HighlightFormat(fg_color='syntax_hl_unicode', italic=True),
|
||||
'unknown_func': HighlightFormat(fg_color='syntax_hl_error', italic=True),
|
||||
'var': HighlightFormat(fg_color='syntax_hl_var'),
|
||||
}
|
||||
|
||||
self.rules = list(self.func_rules())
|
||||
|
||||
Reference in New Issue
Block a user