Krita Source Code Documentation
Loading...
Searching...
No Matches
syntaxstyles.py
Go to the documentation of this file.
1"""
2SPDX-FileCopyrightText: 2017 Eliakin Costa <eliakim170@gmail.com>
3
4SPDX-License-Identifier: GPL-2.0-or-later
5"""
6try:
7 from PyQt6.QtGui import QColor, QTextCharFormat, QFont
8except:
9 from PyQt5.QtGui import QColor, QTextCharFormat, QFont
10
11
12def _format(color, style='', darker=100, lighter=100):
13 """Return a QTextCharFormat with the given attributes.
14 """
15 _color = QColor(color)
16 _color = _color.darker(darker)
17 _color = _color.lighter(lighter)
18
19 fmt = QTextCharFormat()
20 fmt.setForeground(_color)
21 if 'bold' in style:
22 fmt.setFontWeight(QFont.Weight.Bold)
23 if 'italic' in style:
24 fmt.setFontItalic(True)
25
26 return fmt
27
28
29class DefaultSyntaxStyle(object):
30
31 # Syntax styles that combines with dark backgrounds
32 STYLES = {
33 'keyword': _format('cyan'),
34 'operator': _format('orange'),
35 'brace': _format('gray'),
36 'defclass': _format('black', 'bold'),
37 'string': _format('magenta'),
38 'string2': _format('darkMagenta'),
39 'comment': _format('darkGreen', 'italic'),
40 'self': _format('black', 'italic'),
41 'numbers': _format('brown'),
42 'background': _format('white'),
43 'foreground': _format('black'),
44 }
45
46 def __getitem__(self, key):
47 return self.STYLES[key]
48
49
51
52 """ It based in the colorschemme of the Vim editor for python code http://www.vim.org/scripts/script.php?script_id=790 """
53 # Syntax styles that combines with dark backgrounds
54 STYLES = {
55 'keyword': _format('yellow', darker=125),
56 'operator': _format('magenta', darker=150),
57 'brace': _format('white'),
58 'defclass': _format('orange', 'bold'),
59 'string': _format('green', lighter=160),
60 'string2': _format('lightGray', 'italic', darker=120),
61 'comment': _format('gray', 'italic'),
62 'self': _format('blue', lighter=170),
63 'numbers': _format('yellow', lighter=130),
64 'background': _format('black'),
65 'foreground': _format('white'),
66 }
67
68 def __getitem__(self, key):
69 return self.STYLES[key]
70
71
73
74 """ Based on KDE Breeze widget style """
75 # A dark syntax style.
76 STYLES = {
77 'keyword': _format('#eff0f1', 'bold'),
78 'operator': _format('#eff0f1'),
79 'brace': _format('#eff0f1'),
80 'defclass': _format('#27ae60', 'bold'),
81 'string': _format('#da4453'),
82 'string2': _format('#da4453'),
83 'comment': _format('#7f8c8d', 'italic'),
84 'self': _format('#3daee9'),
85 'numbers': _format('#f67400'),
86 'background': _format('#232629'),
87 'foreground': _format('#eff0f1'),
88 }
89
90 def __getitem__(self, key):
91 return self.STYLES[key]
92
93
95
96 """ Based on KDE Breeze widget style """
97 # A light syntax style.
98 STYLES = {
99 'keyword': _format('#31363b', 'bold'),
100 'operator': _format('#31363b'),
101 'brace': _format('#31363b'),
102 'defclass': _format('#27ae60', 'bold'),
103 'string': _format('#da4453'),
104 'string2': _format('#da4453'),
105 'comment': _format('#7f8c8d', 'italic'),
106 'self': _format('#3daee9'),
107 'numbers': _format('#f67400'),
108 'background': _format('#fcfcfc'),
109 'foreground': _format('#31363b'),
110 }
111
112 def __getitem__(self, key):
113 return self.STYLES[key]
114
115
116class BlenderSyntaxStyle(object):
117
118 """ Based on KDE Breeze widget style """
119 # A light syntax style.
120 STYLES = {
121 'keyword': _format('#606002'),
122 'operator': _format('#4c4c4c'),
123 'brace': _format('#4c4c4c'),
124 'defclass': _format('#000000'),
125 'string': _format('#650202'),
126 'string2': _format('#650202'),
127 'comment': _format('#006432'),
128 'self': _format('#000000'),
129 'numbers': _format('#0000c8'),
130 'background': _format('#999999'),
131 'foreground': _format('#000000'),
132 }
133
134 def __getitem__(self, key):
135 return self.STYLES[key]
136
137
139
140 """ Based on http://ethanschoonover.com/solarized """
141 # A dark syntax style.
142 STYLES = {
143 'keyword': _format('#6b9500'),
144 'operator': _format('#839496'),
145 'brace': _format('#839496'),
146 'defclass': _format('#248bd2', 'bold'),
147 'string': _format('#29a198'),
148 'string2': _format('#29a198'),
149 'comment': _format('#586e75', 'italic'),
150 'self': _format('#248bd2'),
151 'numbers': _format('#b58900'),
152 'background': _format('#002a35'),
153 'foreground': _format('#839496'),
154 }
155
156 def __getitem__(self, key):
157 return self.STYLES[key]
158
159
161
162 """ Based on http://ethanschoonover.com/solarized """
163 # A light syntax style.
164 STYLES = {
165 'keyword': _format('#6b9500'),
166 'operator': _format('#839496'),
167 'brace': _format('#839496'),
168 'defclass': _format('#248bd2', 'bold'),
169 'string': _format('#29a198'),
170 'string2': _format('#29a198'),
171 'comment': _format('#586e75', 'italic'),
172 'self': _format('#248bd2'),
173 'numbers': _format('#b58900'),
174 'background': _format('#fdf6e3'),
175 'foreground': _format('#839496'),
176 }
177
178 def __getitem__(self, key):
179 return self.STYLES[key]
_format(color, style='', darker=100, lighter=100)