1"""
2Copyright (c) 2017 Eliakin Costa <eliakim170@gmail.com>
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17"""
18from PyQt5.QtGui import QColor, QTextCharFormat, QFont
19
20
21def _format(color, style='', darker=100, lighter=100):
22    """Return a QTextCharFormat with the given attributes.
23    """
24    _color = QColor(color)
25    _color = _color.darker(darker)
26    _color = _color.lighter(lighter)
27
28    fmt = QTextCharFormat()
29    fmt.setForeground(_color)
30    if 'bold' in style:
31        fmt.setFontWeight(QFont.Bold)
32    if 'italic' in style:
33        fmt.setFontItalic(True)
34
35    return fmt
36
37
38class DefaultSyntaxStyle(object):
39
40    # Syntax styles that combines with dark backgrounds
41    STYLES = {
42        'keyword': _format('cyan'),
43        'operator': _format('orange'),
44        'brace': _format('gray'),
45        'defclass': _format('black', 'bold'),
46        'string': _format('magenta'),
47        'string2': _format('darkMagenta'),
48        'comment': _format('darkGreen', 'italic'),
49        'self': _format('black', 'italic'),
50        'numbers': _format('brown'),
51        'background': _format('white'),
52        'foreground': _format('black'),
53    }
54
55    def __getitem__(self, key):
56        return self.STYLES[key]
57
58
59class PythonVimSyntaxStyle(object):
60
61    """ It based in the colorschemme of the Vim editor for python code http://www.vim.org/scripts/script.php?script_id=790 """
62    # Syntax styles that combines with dark backgrounds
63    STYLES = {
64        'keyword': _format('yellow', darker=125),
65        'operator': _format('magenta', darker=150),
66        'brace': _format('white'),
67        'defclass': _format('orange', 'bold'),
68        'string': _format('green', lighter=160),
69        'string2': _format('lightGray', 'italic', darker=120),
70        'comment': _format('gray', 'italic'),
71        'self': _format('blue', lighter=170),
72        'numbers': _format('yellow', lighter=130),
73        'background': _format('black'),
74        'foreground': _format('white'),
75    }
76
77    def __getitem__(self, key):
78        return self.STYLES[key]
79
80
81class BreezeDarkSyntaxStyle(object):
82
83    """ Based on KDE Breeze widget style """
84    # A dark syntax style.
85    STYLES = {
86        'keyword': _format('#eff0f1', 'bold'),
87        'operator': _format('#eff0f1'),
88        'brace': _format('#eff0f1'),
89        'defclass': _format('#27ae60', 'bold'),
90        'string': _format('#da4453'),
91        'string2': _format('#da4453'),
92        'comment': _format('#7f8c8d', 'italic'),
93        'self': _format('#3daee9'),
94        'numbers': _format('#f67400'),
95        'background': _format('#232629'),
96        'foreground': _format('#eff0f1'),
97    }
98
99    def __getitem__(self, key):
100        return self.STYLES[key]
101
102
103class BreezeLightSyntaxStyle(object):
104
105    """ Based on KDE Breeze widget style """
106    # A light syntax style.
107    STYLES = {
108        'keyword': _format('#31363b', 'bold'),
109        'operator': _format('#31363b'),
110        'brace': _format('#31363b'),
111        'defclass': _format('#27ae60', 'bold'),
112        'string': _format('#da4453'),
113        'string2': _format('#da4453'),
114        'comment': _format('#7f8c8d', 'italic'),
115        'self': _format('#3daee9'),
116        'numbers': _format('#f67400'),
117        'background': _format('#fcfcfc'),
118        'foreground': _format('#31363b'),
119    }
120
121    def __getitem__(self, key):
122        return self.STYLES[key]
123
124
125class BlenderSyntaxStyle(object):
126
127    """ Based on KDE Breeze widget style """
128    # A light syntax style.
129    STYLES = {
130        'keyword': _format('#606002'),
131        'operator': _format('#4c4c4c'),
132        'brace': _format('#4c4c4c'),
133        'defclass': _format('#000000'),
134        'string': _format('#650202'),
135        'string2': _format('#650202'),
136        'comment': _format('#006432'),
137        'self': _format('#000000'),
138        'numbers': _format('#0000c8'),
139        'background': _format('#999999'),
140        'foreground': _format('#000000'),
141    }
142
143    def __getitem__(self, key):
144        return self.STYLES[key]
145
146
147class SolarizedDarkSyntaxStyle(object):
148
149    """ Based on http://ethanschoonover.com/solarized """
150    # A dark syntax style.
151    STYLES = {
152        'keyword': _format('#6b9500'),
153        'operator': _format('#839496'),
154        'brace': _format('#839496'),
155        'defclass': _format('#248bd2', 'bold'),
156        'string': _format('#29a198'),
157        'string2': _format('#29a198'),
158        'comment': _format('#586e75', 'italic'),
159        'self': _format('#248bd2'),
160        'numbers': _format('#b58900'),
161        'background': _format('#002a35'),
162        'foreground': _format('#839496'),
163    }
164
165    def __getitem__(self, key):
166        return self.STYLES[key]
167
168
169class SolarizedLightSyntaxStyle(object):
170
171    """ Based on http://ethanschoonover.com/solarized """
172    # A light syntax style.
173    STYLES = {
174        'keyword': _format('#6b9500'),
175        'operator': _format('#839496'),
176        'brace': _format('#839496'),
177        'defclass': _format('#248bd2', 'bold'),
178        'string': _format('#29a198'),
179        'string2': _format('#29a198'),
180        'comment': _format('#586e75', 'italic'),
181        'self': _format('#248bd2'),
182        'numbers': _format('#b58900'),
183        'background': _format('#fdf6e3'),
184        'foreground': _format('#839496'),
185    }
186
187    def __getitem__(self, key):
188        return self.STYLES[key]
189