denoted 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- denoted/__init__.py +1 -0
- denoted/_vendor/__init__.py +0 -0
- denoted/_vendor/qt_themes/LICENSE +21 -0
- denoted/_vendor/qt_themes/__init__.py +19 -0
- denoted/_vendor/qt_themes/_builtin.py +324 -0
- denoted/_vendor/qt_themes/_theme.py +271 -0
- denoted/assets/denoted.ico +0 -0
- denoted/assets/denoted.png +0 -0
- denoted/assets/denoted.svg +16 -0
- denoted/assets/make_icon.py +54 -0
- denoted/cli.py +75 -0
- denoted/export.py +306 -0
- denoted/fonts.py +29 -0
- denoted/format.py +1044 -0
- denoted/hive.py +130 -0
- denoted/mockup.py +188 -0
- denoted/scheme.py +215 -0
- denoted/viewer.py +811 -0
- denoted/widgets.py +705 -0
- denoted-1.0.0.dist-info/METADATA +62 -0
- denoted-1.0.0.dist-info/RECORD +25 -0
- denoted-1.0.0.dist-info/WHEEL +5 -0
- denoted-1.0.0.dist-info/entry_points.txt +5 -0
- denoted-1.0.0.dist-info/licenses/LICENSE +21 -0
- denoted-1.0.0.dist-info/top_level.txt +1 -0
denoted/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Beat Reichenbach
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from ._theme import (
|
|
2
|
+
Theme,
|
|
3
|
+
get_theme,
|
|
4
|
+
get_themes,
|
|
5
|
+
set_theme,
|
|
6
|
+
set_widget_theme,
|
|
7
|
+
update_palette,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
'Theme',
|
|
12
|
+
'get_theme',
|
|
13
|
+
'get_themes',
|
|
14
|
+
'set_theme',
|
|
15
|
+
'set_widget_theme',
|
|
16
|
+
'update_palette',
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
__version__ = '0.4.1'
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
BUILTIN = {
|
|
2
|
+
'atom_one': {
|
|
3
|
+
'primary': '#c678dd',
|
|
4
|
+
'secondary': '#61afef',
|
|
5
|
+
'magenta': '#C678DD',
|
|
6
|
+
'red': '#E06C75',
|
|
7
|
+
'orange': '#D19A66',
|
|
8
|
+
'yellow': '#e5c07b',
|
|
9
|
+
'green': '#98c379',
|
|
10
|
+
'cyan': '#56b6c2',
|
|
11
|
+
'blue': '#61afef',
|
|
12
|
+
'text': '#abb2bf',
|
|
13
|
+
'subtext1': '#abb2bf',
|
|
14
|
+
'subtext0': '#abb2bf',
|
|
15
|
+
'overlay2': '#5c6370',
|
|
16
|
+
'overlay1': '#5c6370',
|
|
17
|
+
'overlay0': '#5c6370',
|
|
18
|
+
'surface2': '#4b5263',
|
|
19
|
+
'surface1': '#4b5263',
|
|
20
|
+
'surface0': '#4b5263',
|
|
21
|
+
'base': '#282c34',
|
|
22
|
+
'mantle': '#282c34',
|
|
23
|
+
'crust': '#282c34',
|
|
24
|
+
},
|
|
25
|
+
'blender': {
|
|
26
|
+
'primary': '#4772b3',
|
|
27
|
+
'secondary': '#f1a355',
|
|
28
|
+
'magenta': '#c673b8',
|
|
29
|
+
'red': '#e2605b',
|
|
30
|
+
'orange': '#f1a355',
|
|
31
|
+
'yellow': '#f1dc55',
|
|
32
|
+
'green': '#7bcc7b',
|
|
33
|
+
'cyan': '#6CC1B3',
|
|
34
|
+
'blue': '#5db6ea',
|
|
35
|
+
'text': '#ffffff',
|
|
36
|
+
'subtext1': '#e6e6e6',
|
|
37
|
+
'subtext0': '#d9d9d9',
|
|
38
|
+
'overlay2': '#B9B9B9',
|
|
39
|
+
'overlay1': '#989898',
|
|
40
|
+
'overlay0': '#848484',
|
|
41
|
+
'surface2': '#6C6C6C',
|
|
42
|
+
'surface1': '#545454',
|
|
43
|
+
'surface0': '#3d3d3d',
|
|
44
|
+
'base': '#303030',
|
|
45
|
+
'mantle': '#282828',
|
|
46
|
+
'crust': '#1d1d1d',
|
|
47
|
+
},
|
|
48
|
+
'catppuccin_frappe': {
|
|
49
|
+
'primary': '#ca9ee6',
|
|
50
|
+
'secondary': '#8caaee',
|
|
51
|
+
'magenta': '#ca9ee6',
|
|
52
|
+
'red': '#e78284',
|
|
53
|
+
'orange': '#ef9f76',
|
|
54
|
+
'yellow': '#e5c890',
|
|
55
|
+
'green': '#a6d189',
|
|
56
|
+
'cyan': '#99d1db',
|
|
57
|
+
'blue': '#8caaee',
|
|
58
|
+
'text': '#c6d0f5',
|
|
59
|
+
'subtext1': '#b5bfe2',
|
|
60
|
+
'subtext0': '#a5adce',
|
|
61
|
+
'overlay2': '#949cbb',
|
|
62
|
+
'overlay1': '#838ba7',
|
|
63
|
+
'overlay0': '#737994',
|
|
64
|
+
'surface2': '#626880',
|
|
65
|
+
'surface1': '#51576d',
|
|
66
|
+
'surface0': '#414559',
|
|
67
|
+
'base': '#303446',
|
|
68
|
+
'mantle': '#292c3c',
|
|
69
|
+
'crust': '#232634',
|
|
70
|
+
},
|
|
71
|
+
'catppuccin_latte': {
|
|
72
|
+
'primary': '#8839ef',
|
|
73
|
+
'secondary': '#1e66f5',
|
|
74
|
+
'magenta': '#8839ef',
|
|
75
|
+
'red': '#d20f39',
|
|
76
|
+
'orange': '#fe640b',
|
|
77
|
+
'yellow': '#df8e1d',
|
|
78
|
+
'green': '#40a02b',
|
|
79
|
+
'cyan': '#04a5e5',
|
|
80
|
+
'blue': '#1e66f5',
|
|
81
|
+
'text': '#4c4f69',
|
|
82
|
+
'subtext1': '#5c5f77',
|
|
83
|
+
'subtext0': '#6c6f85',
|
|
84
|
+
'overlay2': '#7c7f93',
|
|
85
|
+
'overlay1': '#8c8fa1',
|
|
86
|
+
'overlay0': '#9ca0b0',
|
|
87
|
+
'surface2': '#acb0be',
|
|
88
|
+
'surface1': '#bcc0cc',
|
|
89
|
+
'surface0': '#ccd0da',
|
|
90
|
+
'base': '#dce0e8',
|
|
91
|
+
'mantle': '#e6e9ef',
|
|
92
|
+
'crust': '#eff1f5',
|
|
93
|
+
},
|
|
94
|
+
'catppuccin_macchiato': {
|
|
95
|
+
'primary': '#c6a0f6',
|
|
96
|
+
'secondary': '#8aadf4',
|
|
97
|
+
'magenta': '#c6a0f6',
|
|
98
|
+
'red': '#ed8796',
|
|
99
|
+
'orange': '#f5a97f',
|
|
100
|
+
'yellow': '#eed49f',
|
|
101
|
+
'green': '#a6da95',
|
|
102
|
+
'cyan': '#91d7e3',
|
|
103
|
+
'blue': '#8aadf4',
|
|
104
|
+
'text': '#cad3f5',
|
|
105
|
+
'subtext1': '#b8c0e0',
|
|
106
|
+
'subtext0': '#a5adcb',
|
|
107
|
+
'overlay2': '#939ab7',
|
|
108
|
+
'overlay1': '#8087a2',
|
|
109
|
+
'overlay0': '#6e738d',
|
|
110
|
+
'surface2': '#5b6078',
|
|
111
|
+
'surface1': '#494d64',
|
|
112
|
+
'surface0': '#363a4f',
|
|
113
|
+
'base': '#24273a',
|
|
114
|
+
'mantle': '#1e2030',
|
|
115
|
+
'crust': '#181926',
|
|
116
|
+
},
|
|
117
|
+
'catppuccin_mocha': {
|
|
118
|
+
'primary': '#cba6f7',
|
|
119
|
+
'secondary': '#89b4fa',
|
|
120
|
+
'magenta': '#cba6f7',
|
|
121
|
+
'red': '#f38ba8',
|
|
122
|
+
'orange': '#fab387',
|
|
123
|
+
'yellow': '#f9e2af',
|
|
124
|
+
'green': '#a6e3a1',
|
|
125
|
+
'cyan': '#89dceb',
|
|
126
|
+
'blue': '#89b4fa',
|
|
127
|
+
'text': '#cdd6f4',
|
|
128
|
+
'subtext1': '#bac2de',
|
|
129
|
+
'subtext0': '#a6adc8',
|
|
130
|
+
'overlay2': '#9399b2',
|
|
131
|
+
'overlay1': '#7f849c',
|
|
132
|
+
'overlay0': '#6c7086',
|
|
133
|
+
'surface2': '#585b70',
|
|
134
|
+
'surface1': '#45475a',
|
|
135
|
+
'surface0': '#313244',
|
|
136
|
+
'base': '#1e1e2e',
|
|
137
|
+
'mantle': '#181825',
|
|
138
|
+
'crust': '#11111b',
|
|
139
|
+
},
|
|
140
|
+
'dracula': {
|
|
141
|
+
'primary': '#bd93f9',
|
|
142
|
+
'secondary': '#ff79c6',
|
|
143
|
+
'magenta': '#bd93f9',
|
|
144
|
+
'red': '#ff5555',
|
|
145
|
+
'orange': '#ffb86c',
|
|
146
|
+
'yellow': '#f1fa8c',
|
|
147
|
+
'green': '#50fa7b',
|
|
148
|
+
'cyan': '#8be9fd',
|
|
149
|
+
'blue': '#6272a4',
|
|
150
|
+
'text': '#f8f8f2',
|
|
151
|
+
'subtext1': '#DADBD9',
|
|
152
|
+
'subtext0': '#BCBDBF',
|
|
153
|
+
'overlay2': '#9EA0A6',
|
|
154
|
+
'overlay1': '#80828D',
|
|
155
|
+
'overlay0': '#626573',
|
|
156
|
+
'surface2': '#44475a',
|
|
157
|
+
'surface1': '#3B3D4E',
|
|
158
|
+
'surface0': '#313442',
|
|
159
|
+
'base': '#2D2F3C',
|
|
160
|
+
'mantle': '#282a36',
|
|
161
|
+
'crust': '#1d1b22',
|
|
162
|
+
},
|
|
163
|
+
'github_dark': {
|
|
164
|
+
'primary': '#79c0ff',
|
|
165
|
+
'secondary': '#56d364',
|
|
166
|
+
'magenta': '#d2a8ff',
|
|
167
|
+
'red': '#ffa198',
|
|
168
|
+
'orange': '#ffa657',
|
|
169
|
+
'yellow': '#e3b341',
|
|
170
|
+
'green': '#56d364',
|
|
171
|
+
'cyan': '#68CAB2',
|
|
172
|
+
'blue': '#79c0ff',
|
|
173
|
+
'text': '#d1d7e0',
|
|
174
|
+
'subtext1': '#BEC4CD',
|
|
175
|
+
'subtext0': '#ABB1BA',
|
|
176
|
+
'overlay2': '#989EA7',
|
|
177
|
+
'overlay1': '#858B94',
|
|
178
|
+
'overlay0': '#727882',
|
|
179
|
+
'surface2': '#5F656F',
|
|
180
|
+
'surface1': '#4C525C',
|
|
181
|
+
'surface0': '#3E444E',
|
|
182
|
+
'base': '#262c36',
|
|
183
|
+
'mantle': '#212830',
|
|
184
|
+
'crust': '#151b23',
|
|
185
|
+
},
|
|
186
|
+
'github_light': {
|
|
187
|
+
'primary': '#79c0ff',
|
|
188
|
+
'secondary': '#56d364',
|
|
189
|
+
'magenta': '#d2a8ff',
|
|
190
|
+
'red': '#ffa198',
|
|
191
|
+
'orange': '#ffa657',
|
|
192
|
+
'yellow': '#e3b341',
|
|
193
|
+
'green': '#56d364',
|
|
194
|
+
'cyan': '#68CAB2',
|
|
195
|
+
'blue': '#79c0ff',
|
|
196
|
+
'text': '#1f2328',
|
|
197
|
+
'subtext1': '#212830',
|
|
198
|
+
'subtext0': '#262c36',
|
|
199
|
+
'overlay2': '#444952',
|
|
200
|
+
'overlay1': '#61666E',
|
|
201
|
+
'overlay0': '#7F838A',
|
|
202
|
+
'surface2': '#9DA1A6',
|
|
203
|
+
'surface1': '#BBBEC2',
|
|
204
|
+
'surface0': '#D8DBDE',
|
|
205
|
+
'base': '#f6f8fa',
|
|
206
|
+
'mantle': '#FBFCFD',
|
|
207
|
+
'crust': '#ffffff',
|
|
208
|
+
},
|
|
209
|
+
'modern_dark': {
|
|
210
|
+
'primary': '#2aa5da',
|
|
211
|
+
'secondary': '#2ad7da',
|
|
212
|
+
'magenta': '#b351de',
|
|
213
|
+
'red': '#da4d2a',
|
|
214
|
+
'orange': '#da8a2a',
|
|
215
|
+
'yellow': '#d7da2a',
|
|
216
|
+
'green': '#2ada6f',
|
|
217
|
+
'cyan': '#2ad7da',
|
|
218
|
+
'blue': '#2aa5da',
|
|
219
|
+
'text': '#c8c8c8',
|
|
220
|
+
'subtext1': '#b2b2b2',
|
|
221
|
+
'subtext0': '#9b9b9b',
|
|
222
|
+
'overlay2': '#858585',
|
|
223
|
+
'overlay1': '#6f6f6f',
|
|
224
|
+
'overlay0': '#585858',
|
|
225
|
+
'surface2': '#424242',
|
|
226
|
+
'surface1': '#3c3c3c',
|
|
227
|
+
'surface0': '#353535',
|
|
228
|
+
'base': '#2a2a2a',
|
|
229
|
+
'mantle': '#1f1f1f',
|
|
230
|
+
'crust': '#141414',
|
|
231
|
+
},
|
|
232
|
+
'modern_light': {
|
|
233
|
+
'primary': '#2aa5da',
|
|
234
|
+
'secondary': '#2ad7da',
|
|
235
|
+
'magenta': '#b351de',
|
|
236
|
+
'red': '#da4d2a',
|
|
237
|
+
'orange': '#da8a2a',
|
|
238
|
+
'yellow': '#d7da2a',
|
|
239
|
+
'green': '#2ada6f',
|
|
240
|
+
'cyan': '#2ad7da',
|
|
241
|
+
'blue': '#2aa5da',
|
|
242
|
+
'text': '#000000',
|
|
243
|
+
'subtext1': '#131517',
|
|
244
|
+
'subtext0': '#2d3032',
|
|
245
|
+
'overlay2': '#484b4d',
|
|
246
|
+
'overlay1': '#626568',
|
|
247
|
+
'overlay0': '#7d8084',
|
|
248
|
+
'surface2': '#979b9f',
|
|
249
|
+
'surface1': '#b1b6ba',
|
|
250
|
+
'surface0': '#ccd0d5',
|
|
251
|
+
'base': '#e6ebf0',
|
|
252
|
+
'mantle': '#eef2f6',
|
|
253
|
+
'crust': '#ffffff',
|
|
254
|
+
},
|
|
255
|
+
'monokai': {
|
|
256
|
+
'primary': '#ffd866',
|
|
257
|
+
'secondary': '#ff6188',
|
|
258
|
+
'magenta': '#ab9df2',
|
|
259
|
+
'red': '#ff6188',
|
|
260
|
+
'orange': '#fc9867',
|
|
261
|
+
'yellow': '#ffd866',
|
|
262
|
+
'green': '#a9dc76',
|
|
263
|
+
'cyan': '#91dcaf',
|
|
264
|
+
'blue': '#78dce8',
|
|
265
|
+
'text': '#fcfcfa',
|
|
266
|
+
'subtext1': '#c1c0c0',
|
|
267
|
+
'subtext0': '#c1c0c0',
|
|
268
|
+
'overlay2': '#939293',
|
|
269
|
+
'overlay1': '#939293',
|
|
270
|
+
'overlay0': '#727072',
|
|
271
|
+
'surface2': '#5b595c',
|
|
272
|
+
'surface1': '#4e4c4f',
|
|
273
|
+
'surface0': '#403e41',
|
|
274
|
+
'base': '#2d2a2e',
|
|
275
|
+
'mantle': '#221f22',
|
|
276
|
+
'crust': '#19181a',
|
|
277
|
+
},
|
|
278
|
+
'nord': {
|
|
279
|
+
'primary': '#81a1c1',
|
|
280
|
+
'secondary': '#88c0d0',
|
|
281
|
+
'magenta': '#b48ead',
|
|
282
|
+
'red': '#bf616a',
|
|
283
|
+
'orange': '#d08770',
|
|
284
|
+
'yellow': '#ebcb8b',
|
|
285
|
+
'green': '#a3be8c',
|
|
286
|
+
'cyan': '#88c0d0',
|
|
287
|
+
'blue': '#81a1c1',
|
|
288
|
+
'text': '#eceff4',
|
|
289
|
+
'subtext1': '#e5e9f0',
|
|
290
|
+
'subtext0': '#d8dee9',
|
|
291
|
+
'overlay2': '#d8dee9',
|
|
292
|
+
'overlay1': '#d8dee9',
|
|
293
|
+
'overlay0': '#4c566a',
|
|
294
|
+
'surface2': '#4c566a',
|
|
295
|
+
'surface1': '#434c5e',
|
|
296
|
+
'surface0': '#3b4252',
|
|
297
|
+
'base': '#3b4252',
|
|
298
|
+
'mantle': '#2e3440',
|
|
299
|
+
'crust': '#2e3440',
|
|
300
|
+
},
|
|
301
|
+
'one_dark_two': {
|
|
302
|
+
'primary': '#62bac6',
|
|
303
|
+
'secondary': '#eac786',
|
|
304
|
+
'magenta': '#c88bda',
|
|
305
|
+
'red': '#e27881',
|
|
306
|
+
'orange': '#e79c7e',
|
|
307
|
+
'yellow': '#eac786',
|
|
308
|
+
'green': '#98c379',
|
|
309
|
+
'cyan': '#62bac6',
|
|
310
|
+
'blue': '#71b9f4',
|
|
311
|
+
'text': '#e6e6e6',
|
|
312
|
+
'subtext1': '#c9ccd3',
|
|
313
|
+
'subtext0': '#abb2bf',
|
|
314
|
+
'overlay2': '#969dab',
|
|
315
|
+
'overlay1': '#818896',
|
|
316
|
+
'overlay0': '#6c7280',
|
|
317
|
+
'surface2': '#5b626d',
|
|
318
|
+
'surface1': '#4a505a',
|
|
319
|
+
'surface0': '#393e47',
|
|
320
|
+
'base': '#282c34',
|
|
321
|
+
'mantle': '#21252b',
|
|
322
|
+
'crust': '#1d1f23',
|
|
323
|
+
},
|
|
324
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This python script and those along with it related to 'qt_themes' are all sourced from
|
|
3
|
+
Beat Reichenbach's (https://github.com/beatreichenbach/qt-themes) qt-themes repository.
|
|
4
|
+
It is being used in accordance with its issued MIT License.
|
|
5
|
+
(https://github.com/beatreichenbach/qt-themes/blob/main/LICENSE)
|
|
6
|
+
It has been modified to work with PyQt6.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import dataclasses
|
|
11
|
+
import json
|
|
12
|
+
import logging
|
|
13
|
+
import os
|
|
14
|
+
import pathlib
|
|
15
|
+
from json import JSONDecodeError
|
|
16
|
+
|
|
17
|
+
from PyQt6 import QtGui, QtWidgets
|
|
18
|
+
|
|
19
|
+
from ._builtin import BUILTIN
|
|
20
|
+
|
|
21
|
+
ColorGroup = QtGui.QPalette.ColorGroup
|
|
22
|
+
ColorRole = QtGui.QPalette.ColorRole
|
|
23
|
+
|
|
24
|
+
THEMES = 'QT_THEMES'
|
|
25
|
+
PROPERTY_NAME = 'theme'
|
|
26
|
+
|
|
27
|
+
logger = logging.getLogger(__package__)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclasses.dataclass
|
|
31
|
+
class Theme:
|
|
32
|
+
primary: QtGui.QColor
|
|
33
|
+
secondary: QtGui.QColor
|
|
34
|
+
|
|
35
|
+
magenta: QtGui.QColor
|
|
36
|
+
red: QtGui.QColor
|
|
37
|
+
orange: QtGui.QColor
|
|
38
|
+
yellow: QtGui.QColor
|
|
39
|
+
green: QtGui.QColor
|
|
40
|
+
cyan: QtGui.QColor
|
|
41
|
+
blue: QtGui.QColor
|
|
42
|
+
|
|
43
|
+
text: QtGui.QColor
|
|
44
|
+
subtext1: QtGui.QColor
|
|
45
|
+
subtext0: QtGui.QColor
|
|
46
|
+
overlay2: QtGui.QColor
|
|
47
|
+
overlay1: QtGui.QColor
|
|
48
|
+
overlay0: QtGui.QColor
|
|
49
|
+
surface2: QtGui.QColor
|
|
50
|
+
surface1: QtGui.QColor
|
|
51
|
+
surface0: QtGui.QColor
|
|
52
|
+
base: QtGui.QColor
|
|
53
|
+
mantle: QtGui.QColor
|
|
54
|
+
crust: QtGui.QColor
|
|
55
|
+
|
|
56
|
+
def is_dark_theme(self) -> bool:
|
|
57
|
+
return self.text.value() > self.base.value()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def get_theme(name: str | None = None) -> Theme | None:
|
|
61
|
+
"""
|
|
62
|
+
Return the theme with `name` if found and valid.
|
|
63
|
+
|
|
64
|
+
If no name is provided, return the current theme applied to the QApplication. This
|
|
65
|
+
only works in the same Python session.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
if name is None:
|
|
69
|
+
if application := QtWidgets.QApplication.instance():
|
|
70
|
+
return application.property(PROPERTY_NAME)
|
|
71
|
+
else:
|
|
72
|
+
return None
|
|
73
|
+
|
|
74
|
+
if name in BUILTIN:
|
|
75
|
+
return _from_data(BUILTIN[name])
|
|
76
|
+
|
|
77
|
+
file_name = f'{name}.json'
|
|
78
|
+
themes_paths = _get_paths()
|
|
79
|
+
for themes_path in themes_paths:
|
|
80
|
+
path = themes_path / file_name
|
|
81
|
+
if path.exists():
|
|
82
|
+
break
|
|
83
|
+
else:
|
|
84
|
+
logger.warning(f'Cannot find theme {file_name!r}.')
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
try:
|
|
88
|
+
return _load(path)
|
|
89
|
+
except (JSONDecodeError, TypeError):
|
|
90
|
+
logger.warning(f'Invalid theme {str(path)!r}.')
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def get_themes() -> dict[str, Theme]:
|
|
95
|
+
"""Return all valid themes found on disk as a dictionary."""
|
|
96
|
+
|
|
97
|
+
themes_paths = _get_paths()
|
|
98
|
+
themes = {name: _from_data(data) for name, data in BUILTIN.items()}
|
|
99
|
+
for themes_path in themes_paths:
|
|
100
|
+
if not themes_path.is_dir():
|
|
101
|
+
continue
|
|
102
|
+
for path in themes_path.iterdir():
|
|
103
|
+
if not path.is_file() or path.suffix != '.json':
|
|
104
|
+
continue
|
|
105
|
+
try:
|
|
106
|
+
themes[path.stem] = _load(path)
|
|
107
|
+
except (JSONDecodeError, TypeError):
|
|
108
|
+
logger.warning(f'Invalid theme {str(path)!r}.')
|
|
109
|
+
continue
|
|
110
|
+
|
|
111
|
+
return themes
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def update_palette(palette: QtGui.QPalette, theme: Theme) -> None:
|
|
115
|
+
"""Set the theme for the given QPalette."""
|
|
116
|
+
|
|
117
|
+
# Colors
|
|
118
|
+
highlighted_color = theme.primary
|
|
119
|
+
if highlighted_color.valueF() > 0.5:
|
|
120
|
+
highlighted_text_color = theme.mantle
|
|
121
|
+
else:
|
|
122
|
+
highlighted_text_color = theme.text
|
|
123
|
+
|
|
124
|
+
h, s, v, a = theme.text.getHsvF() # ty: ignore[not-iterable]
|
|
125
|
+
bright_text_color = QtGui.QColor.fromHsvF(h, s, 1 - v, a)
|
|
126
|
+
|
|
127
|
+
# Normal
|
|
128
|
+
if theme.is_dark_theme():
|
|
129
|
+
palette.setColor(ColorRole.Base, theme.mantle)
|
|
130
|
+
palette.setColor(ColorRole.AlternateBase, theme.base)
|
|
131
|
+
else:
|
|
132
|
+
palette.setColor(ColorRole.Base, theme.crust)
|
|
133
|
+
palette.setColor(ColorRole.AlternateBase, theme.mantle)
|
|
134
|
+
palette.setColor(ColorRole.Window, theme.base)
|
|
135
|
+
palette.setColor(ColorRole.WindowText, theme.text)
|
|
136
|
+
palette.setColor(ColorRole.PlaceholderText, theme.overlay1)
|
|
137
|
+
palette.setColor(ColorRole.Text, theme.text)
|
|
138
|
+
palette.setColor(ColorRole.Button, theme.base)
|
|
139
|
+
palette.setColor(ColorRole.ButtonText, theme.text)
|
|
140
|
+
palette.setColor(ColorRole.BrightText, bright_text_color)
|
|
141
|
+
palette.setColor(ColorRole.ToolTipBase, theme.mantle)
|
|
142
|
+
palette.setColor(ColorRole.ToolTipText, theme.overlay2)
|
|
143
|
+
|
|
144
|
+
palette.setColor(ColorRole.Highlight, highlighted_color)
|
|
145
|
+
palette.setColor(ColorRole.HighlightedText, highlighted_text_color)
|
|
146
|
+
palette.setColor(ColorRole.Link, theme.secondary)
|
|
147
|
+
palette.setColor(ColorRole.LinkVisited, theme.secondary)
|
|
148
|
+
|
|
149
|
+
palette.setColor(ColorRole.Light, theme.crust)
|
|
150
|
+
palette.setColor(ColorRole.Midlight, theme.mantle)
|
|
151
|
+
palette.setColor(ColorRole.Mid, theme.surface0)
|
|
152
|
+
palette.setColor(ColorRole.Dark, theme.surface1)
|
|
153
|
+
palette.setColor(ColorRole.Shadow, theme.overlay0)
|
|
154
|
+
|
|
155
|
+
# Inactive
|
|
156
|
+
palette.setColor(ColorGroup.Inactive, ColorRole.Highlight, theme.surface1)
|
|
157
|
+
palette.setColor(ColorGroup.Inactive, ColorRole.Link, theme.surface1)
|
|
158
|
+
palette.setColor(ColorGroup.Inactive, ColorRole.LinkVisited, theme.surface1)
|
|
159
|
+
|
|
160
|
+
# Disabled
|
|
161
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.WindowText, theme.overlay1)
|
|
162
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.Base, theme.base)
|
|
163
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.AlternateBase, theme.base)
|
|
164
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.Text, theme.overlay1)
|
|
165
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.PlaceholderText, theme.overlay1)
|
|
166
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.Button, theme.base)
|
|
167
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.ButtonText, theme.overlay1)
|
|
168
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.BrightText, theme.mantle)
|
|
169
|
+
|
|
170
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.Highlight, theme.surface2)
|
|
171
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.HighlightedText, theme.surface0)
|
|
172
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.Link, theme.surface0)
|
|
173
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.LinkVisited, theme.surface0)
|
|
174
|
+
|
|
175
|
+
try:
|
|
176
|
+
# PySide2 compatibility
|
|
177
|
+
palette.setColor(ColorRole.Accent, theme.secondary)
|
|
178
|
+
palette.setColor(ColorGroup.Inactive, ColorRole.Accent, theme.surface1)
|
|
179
|
+
palette.setColor(ColorGroup.Disabled, ColorRole.Accent, theme.surface2)
|
|
180
|
+
except AttributeError:
|
|
181
|
+
pass
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def set_theme(theme: Theme | str | None, style: str | None = 'fusion') -> None:
|
|
185
|
+
"""
|
|
186
|
+
Set the theme and style for the current QApplication.
|
|
187
|
+
By default, set the fusion style as it works the best with QPalette ColorRoles.
|
|
188
|
+
"""
|
|
189
|
+
|
|
190
|
+
# Set style
|
|
191
|
+
if style:
|
|
192
|
+
QtWidgets.QApplication.setStyle(style)
|
|
193
|
+
|
|
194
|
+
# Reset theme
|
|
195
|
+
if not theme:
|
|
196
|
+
QtWidgets.QApplication.setPalette(QtGui.QPalette())
|
|
197
|
+
if application := QtWidgets.QApplication.instance():
|
|
198
|
+
application.setProperty(PROPERTY_NAME, None)
|
|
199
|
+
return
|
|
200
|
+
|
|
201
|
+
# Set theme
|
|
202
|
+
if isinstance(theme, str):
|
|
203
|
+
theme = get_theme(theme)
|
|
204
|
+
if not theme:
|
|
205
|
+
return
|
|
206
|
+
|
|
207
|
+
palette = QtGui.QPalette()
|
|
208
|
+
update_palette(palette, theme)
|
|
209
|
+
QtWidgets.QApplication.setPalette(palette)
|
|
210
|
+
if application := QtWidgets.QApplication.instance():
|
|
211
|
+
application.setProperty(PROPERTY_NAME, theme)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def set_widget_theme(
|
|
215
|
+
widget: QtWidgets.QWidget, theme: Theme | str | None, style: str | None = 'fusion'
|
|
216
|
+
) -> None:
|
|
217
|
+
"""
|
|
218
|
+
Set the theme and style for the given QWidget.
|
|
219
|
+
By default, set the fusion style as it works the best with QPalette ColorRoles.
|
|
220
|
+
"""
|
|
221
|
+
|
|
222
|
+
# Set style
|
|
223
|
+
if style:
|
|
224
|
+
widget.setStyle(QtWidgets.QStyleFactory.create(style))
|
|
225
|
+
|
|
226
|
+
# Reset theme
|
|
227
|
+
if not theme:
|
|
228
|
+
widget.setPalette(QtGui.QPalette())
|
|
229
|
+
widget.setProperty(PROPERTY_NAME, None)
|
|
230
|
+
return
|
|
231
|
+
|
|
232
|
+
# Set theme
|
|
233
|
+
if isinstance(theme, str):
|
|
234
|
+
theme = get_theme(theme)
|
|
235
|
+
if not theme:
|
|
236
|
+
return
|
|
237
|
+
|
|
238
|
+
palette = QtGui.QPalette()
|
|
239
|
+
update_palette(palette, theme)
|
|
240
|
+
widget.setPalette(palette)
|
|
241
|
+
widget.setProperty(PROPERTY_NAME, theme)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _from_data(data: dict[str, str]) -> Theme:
|
|
245
|
+
colors = {key: QtGui.QColor(value) for key, value in data.items()}
|
|
246
|
+
return Theme(**colors)
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _load(path: os.PathLike[str]) -> Theme:
|
|
250
|
+
"""
|
|
251
|
+
Return the theme from `path`.
|
|
252
|
+
|
|
253
|
+
:raises FileNotFoundError: if theme cannot be found.
|
|
254
|
+
:raises TypeError: if theme has unexpected data.
|
|
255
|
+
:raises JSONDecodeError: if theme is invalid json.
|
|
256
|
+
"""
|
|
257
|
+
|
|
258
|
+
with pathlib.Path(path).open() as f:
|
|
259
|
+
data = json.load(f)
|
|
260
|
+
colors = {key: QtGui.QColor(value) for key, value in data.items()}
|
|
261
|
+
return Theme(**colors)
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _get_paths() -> tuple[pathlib.Path, ...]:
|
|
265
|
+
"""Return all paths to search for themes."""
|
|
266
|
+
|
|
267
|
+
paths = []
|
|
268
|
+
if env_path := os.getenv(THEMES):
|
|
269
|
+
paths.extend(pathlib.Path(path) for path in env_path.split(os.pathsep))
|
|
270
|
+
logger.debug(f'Color themes paths: {paths}')
|
|
271
|
+
return tuple(paths)
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" width="256" height="256">
|
|
2
|
+
<rect x="36" y="26" width="184" height="210" rx="22" fill="#f4f6f8"/>
|
|
3
|
+
<path d="M36 48a22 22 0 0 1 22-22h140a22 22 0 0 1 22 22v34H36z" fill="#2f9be0"/>
|
|
4
|
+
<g fill="#e8eef3" stroke="#1d6fae" stroke-width="5">
|
|
5
|
+
<rect x="68" y="12" width="20" height="40" rx="10"/>
|
|
6
|
+
<rect x="118" y="12" width="20" height="40" rx="10"/>
|
|
7
|
+
<rect x="168" y="12" width="20" height="40" rx="10"/>
|
|
8
|
+
</g>
|
|
9
|
+
<g fill="#aab4bd">
|
|
10
|
+
<rect x="62" y="108" width="132" height="12" rx="6"/>
|
|
11
|
+
<rect x="62" y="138" width="104" height="12" rx="6"/>
|
|
12
|
+
<rect x="62" y="168" width="132" height="12" rx="6"/>
|
|
13
|
+
<rect x="62" y="198" width="66" height="12" rx="6"/>
|
|
14
|
+
</g>
|
|
15
|
+
<rect x="138" y="190" width="8" height="28" rx="3" fill="#2f9be0"/>
|
|
16
|
+
</svg>
|