forked from MineevS/DMM_ClusteringSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoader.py
80 lines (58 loc) · 2.45 KB
/
Loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This Python file uses the following encoding: utf-8
from PySide6.QtCore import (
QFile,
QTextStream,
)
import qstylizer.parser # pip install qstylizer
import qstylizer.parser
from Frameworks_interface import rc_resource
THEME_FIRST_PATH = ':/qss/ThemeFirst.css'
THEME_SECOND_PATH = ':/qss/ThemeSecond.css'
class Loader:
def __init__(self):
pass
@staticmethod
def load_style_app(theme_current) -> str:
path_style = (THEME_SECOND_PATH, THEME_FIRST_PATH)[theme_current == 'theme_first']
styleF = QFile(path_style)
# TODO
# Реализовать проверку наличия/отсутствия тем в путях.
if not styleF.exists():
print("ERR: Styles not loaded")
exit(1)
if styleF.open(
QFile.OpenModeFlag.ReadOnly | QFile.OpenModeFlag.Text):
qssstr = styleF.readAll().toStdString()
return qssstr
@staticmethod
def change_color_theme(theme_current, color, msg):
style = Loader.load_style_app(theme_current)
css = qstylizer.parser.parse(style)
match msg:
case 'фон':
css.QMainWindow.backgroundColor.setValue(color)
css.QDialog.backgroundColor.setValue(color)
# css.QLabel.backgroundColor.setValue(color)
css.QLabel['#labelClassA'].backgroundColor.setValue(color)
css.QMenuBar.backgroundColor.setValue(color)
css.QDockWidget.backgroundColor.setValue(color)
case 'текст':
css.QMainWindow.color.setValue(color)
css.QDialog.color.setValue(color)
#css.QDockWidget.color.setValue(color)
css.QLabel['#labelClassA'].color.setValue(color)
css.QMenuBar.color.setValue(color)
case 'слайдер':
css['QSliderButton'].backgroundColor.setValue(color)
path_style = (THEME_SECOND_PATH, THEME_FIRST_PATH)[theme_current == 'theme_first']
styleF = QFile(path_style)
# TODO
# Реализовать проверку наличия/отсутствия тем в путях.
if styleF.exists():
pass
if styleF.open(
QFile.OpenModeFlag.WriteOnly | QFile.OpenModeFlag.Truncate):
stream_out = QTextStream(styleF)
stream_out << css.toString()
styleF.close()
return css.toString()