File indexing completed on 2024-09-22 04:08:47

0001 """
0002 SPDX-FileCopyrightText: 2017 Eliakin Costa <eliakim170@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-2.0-or-later
0005 """
0006 from PyQt5.QtGui import QColor, QTextCharFormat, QFont
0007 
0008 
0009 def _format(color, style='', darker=100, lighter=100):
0010     """Return a QTextCharFormat with the given attributes.
0011     """
0012     _color = QColor(color)
0013     _color = _color.darker(darker)
0014     _color = _color.lighter(lighter)
0015 
0016     fmt = QTextCharFormat()
0017     fmt.setForeground(_color)
0018     if 'bold' in style:
0019         fmt.setFontWeight(QFont.Bold)
0020     if 'italic' in style:
0021         fmt.setFontItalic(True)
0022 
0023     return fmt
0024 
0025 
0026 class DefaultSyntaxStyle(object):
0027 
0028     # Syntax styles that combines with dark backgrounds
0029     STYLES = {
0030         'keyword': _format('cyan'),
0031         'operator': _format('orange'),
0032         'brace': _format('gray'),
0033         'defclass': _format('black', 'bold'),
0034         'string': _format('magenta'),
0035         'string2': _format('darkMagenta'),
0036         'comment': _format('darkGreen', 'italic'),
0037         'self': _format('black', 'italic'),
0038         'numbers': _format('brown'),
0039         'background': _format('white'),
0040         'foreground': _format('black'),
0041     }
0042 
0043     def __getitem__(self, key):
0044         return self.STYLES[key]
0045 
0046 
0047 class PythonVimSyntaxStyle(object):
0048 
0049     """ It based in the colorschemme of the Vim editor for python code http://www.vim.org/scripts/script.php?script_id=790 """
0050     # Syntax styles that combines with dark backgrounds
0051     STYLES = {
0052         'keyword': _format('yellow', darker=125),
0053         'operator': _format('magenta', darker=150),
0054         'brace': _format('white'),
0055         'defclass': _format('orange', 'bold'),
0056         'string': _format('green', lighter=160),
0057         'string2': _format('lightGray', 'italic', darker=120),
0058         'comment': _format('gray', 'italic'),
0059         'self': _format('blue', lighter=170),
0060         'numbers': _format('yellow', lighter=130),
0061         'background': _format('black'),
0062         'foreground': _format('white'),
0063     }
0064 
0065     def __getitem__(self, key):
0066         return self.STYLES[key]
0067 
0068 
0069 class BreezeDarkSyntaxStyle(object):
0070 
0071     """ Based on KDE Breeze widget style """
0072     # A dark syntax style.
0073     STYLES = {
0074         'keyword': _format('#eff0f1', 'bold'),
0075         'operator': _format('#eff0f1'),
0076         'brace': _format('#eff0f1'),
0077         'defclass': _format('#27ae60', 'bold'),
0078         'string': _format('#da4453'),
0079         'string2': _format('#da4453'),
0080         'comment': _format('#7f8c8d', 'italic'),
0081         'self': _format('#3daee9'),
0082         'numbers': _format('#f67400'),
0083         'background': _format('#232629'),
0084         'foreground': _format('#eff0f1'),
0085     }
0086 
0087     def __getitem__(self, key):
0088         return self.STYLES[key]
0089 
0090 
0091 class BreezeLightSyntaxStyle(object):
0092 
0093     """ Based on KDE Breeze widget style """
0094     # A light syntax style.
0095     STYLES = {
0096         'keyword': _format('#31363b', 'bold'),
0097         'operator': _format('#31363b'),
0098         'brace': _format('#31363b'),
0099         'defclass': _format('#27ae60', 'bold'),
0100         'string': _format('#da4453'),
0101         'string2': _format('#da4453'),
0102         'comment': _format('#7f8c8d', 'italic'),
0103         'self': _format('#3daee9'),
0104         'numbers': _format('#f67400'),
0105         'background': _format('#fcfcfc'),
0106         'foreground': _format('#31363b'),
0107     }
0108 
0109     def __getitem__(self, key):
0110         return self.STYLES[key]
0111 
0112 
0113 class BlenderSyntaxStyle(object):
0114 
0115     """ Based on KDE Breeze widget style """
0116     # A light syntax style.
0117     STYLES = {
0118         'keyword': _format('#606002'),
0119         'operator': _format('#4c4c4c'),
0120         'brace': _format('#4c4c4c'),
0121         'defclass': _format('#000000'),
0122         'string': _format('#650202'),
0123         'string2': _format('#650202'),
0124         'comment': _format('#006432'),
0125         'self': _format('#000000'),
0126         'numbers': _format('#0000c8'),
0127         'background': _format('#999999'),
0128         'foreground': _format('#000000'),
0129     }
0130 
0131     def __getitem__(self, key):
0132         return self.STYLES[key]
0133 
0134 
0135 class SolarizedDarkSyntaxStyle(object):
0136 
0137     """ Based on http://ethanschoonover.com/solarized """
0138     # A dark syntax style.
0139     STYLES = {
0140         'keyword': _format('#6b9500'),
0141         'operator': _format('#839496'),
0142         'brace': _format('#839496'),
0143         'defclass': _format('#248bd2', 'bold'),
0144         'string': _format('#29a198'),
0145         'string2': _format('#29a198'),
0146         'comment': _format('#586e75', 'italic'),
0147         'self': _format('#248bd2'),
0148         'numbers': _format('#b58900'),
0149         'background': _format('#002a35'),
0150         'foreground': _format('#839496'),
0151     }
0152 
0153     def __getitem__(self, key):
0154         return self.STYLES[key]
0155 
0156 
0157 class SolarizedLightSyntaxStyle(object):
0158 
0159     """ Based on http://ethanschoonover.com/solarized """
0160     # A light syntax style.
0161     STYLES = {
0162         'keyword': _format('#6b9500'),
0163         'operator': _format('#839496'),
0164         'brace': _format('#839496'),
0165         'defclass': _format('#248bd2', 'bold'),
0166         'string': _format('#29a198'),
0167         'string2': _format('#29a198'),
0168         'comment': _format('#586e75', 'italic'),
0169         'self': _format('#248bd2'),
0170         'numbers': _format('#b58900'),
0171         'background': _format('#fdf6e3'),
0172         'foreground': _format('#839496'),
0173     }
0174 
0175     def __getitem__(self, key):
0176         return self.STYLES[key]