Skip to content

Commit 45519c6

Browse files
committed
apply theme
1 parent a84011b commit 45519c6

File tree

8 files changed

+140
-11
lines changed

8 files changed

+140
-11
lines changed

.settings/org.eclipse.core.resources.prefs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ encoding//Test/TestColorThief.py=utf-8
99
encoding//Test/TestDownProgress.py=utf-8
1010
encoding//Test/TestGitTree.py=utf-8
1111
encoding//Test/TestGradientUtils.py=utf-8
12+
encoding//Test/TestLoadGradientFile.py=utf-8
1213
encoding//Test/TestMainwindowStyle.py=utf-8
1314
encoding//Test/TestPreviewWidget.py=utf-8
1415
encoding//Test/TestPropertyAnimation.py=utf-8

Resources/Themes/Default/style.qss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ QLineEdit {
8686
max-width: 130px;
8787
max-height: 130px;
8888
background: transparent;
89-
qproperty-shadowColor: rgba(33, 33, 33, 255);
89+
qproperty-shadowColor: rgba(255, 255, 255, 255);
9090
qproperty-image: "Resources/Images/Avatars/avatar.png";
9191
}
9292

Test/TestLoadGradientFile.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
Created on 2019年2月1日
6+
@author: Irony
7+
@site: https://pyqt5.com https://github.com/892768447
8+
@email: 892768447@qq.com
9+
@file: Test.TestLoadGradientFile
10+
@description:
11+
"""
12+
from PyQt5.QtCore import QSettings, Qt
13+
from PyQt5.QtGui import QLinearGradient
14+
from PyQt5.QtWidgets import QWidget
15+
16+
from Utils.GradientUtils import GradientUtils
17+
18+
19+
__Author__ = 'Irony'
20+
__Copyright__ = 'Copyright (c) 2019'
21+
22+
23+
class Window(QWidget):
24+
25+
def __init__(self, *args, **kwargs):
26+
super(Window, self).__init__(*args, **kwargs)
27+
self.setAttribute(Qt.WA_StyledBackground, True)
28+
29+
setting = QSettings('gradient.ini', QSettings.IniFormat)
30+
setting.setIniCodec('UTF-8')
31+
32+
gradient = setting.value('gradient')
33+
print(gradient)
34+
if gradient:
35+
gradient = GradientUtils.toGradient(gradient)
36+
print(gradient)
37+
gradient = GradientUtils.styleSheetCode(gradient)
38+
print(gradient)
39+
self.setStyleSheet('background: {};'.format(gradient))
40+
41+
gradient = QLinearGradient(0, 0, 1, 1)
42+
gradient.setColorAt(0, Qt.red)
43+
gradient.setColorAt(0.5, Qt.green)
44+
gradient.setColorAt(1, Qt.blue)
45+
46+
gradient = GradientUtils.toJson(gradient)
47+
print(gradient)
48+
setting.setValue('gradient', gradient)
49+
setting.sync()
50+
51+
52+
if __name__ == '__main__':
53+
import sys
54+
from PyQt5.QtWidgets import QApplication
55+
app = QApplication(sys.argv)
56+
w = Window()
57+
w.show()
58+
sys.exit(app.exec_())

Test/gradient.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[General]
2+
gradient=@Variant(\0\0\0\b\0\0\0\x5\0\0\0\b\0t\0y\0p\0\x65\0\0\0\x2\0\0\0\0\0\0\0\n\0s\0t\0o\0p\0s\0\0\0\t\0\0\0\x3\0\0\0\x7f\0\0\0\xePyQt_PyObject\0\0\0\0V\x80\x3G\0\0\0\0\0\0\0\0\x63sip\n_unpickle_type\nq\0X\v\0\0\0PyQt5.QtGuiq\x1X\x6\0\0\0QColorq\x2(K\xffK\0K\0K\xfftq\x3\x87q\x4Rq\x5\x86q\x6.\0\0\0\x7f\0\0\0\xePyQt_PyObject\0\0\0\0V\x80\x3G?\xe0\0\0\0\0\0\0\x63sip\n_unpickle_type\nq\0X\v\0\0\0PyQt5.QtGuiq\x1X\x6\0\0\0QColorq\x2(K\0K\xffK\0K\xfftq\x3\x87q\x4Rq\x5\x86q\x6.\0\0\0\x7f\0\0\0\xePyQt_PyObject\0\0\0\0V\x80\x3G?\xf0\0\0\0\0\0\0\x63sip\n_unpickle_type\nq\0X\v\0\0\0PyQt5.QtGuiq\x1X\x6\0\0\0QColorq\x2(K\0K\0K\xffK\xfftq\x3\x87q\x4Rq\x5\x86q\x6.\0\0\0\n\0s\0t\0\x61\0r\0t\0\0\0\x1a\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\f\0s\0p\0r\0\x65\0\x61\0\x64\0\0\0\x2\0\0\0\0\0\0\0\x12\0\x66\0i\0n\0\x61\0l\0S\0t\0o\0p\0\0\0\x1a?\xf0\0\0\0\0\0\0?\xf0\0\0\0\0\0\0)

Utils/GradientUtils.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
@file: Utils.GradientUtils
1010
@description: 渐变颜色工具类
1111
"""
12-
from PyQt5.QtGui import QGradient, QColor
12+
from PyQt5.QtCore import QPointF
13+
from PyQt5.QtGui import QGradient, QColor, QLinearGradient, QRadialGradient,\
14+
QConicalGradient
1315

1416

1517
__Author__ = 'Irony'
@@ -98,6 +100,44 @@ def _styleSheetFillName(cls, gradient):
98100
gradient.type(), ' not supported!')
99101
return ''
100102

103+
@classmethod
104+
def toJson(cls, gradient):
105+
"""把渐变转成字典
106+
:param cls:
107+
:param gradient: 渐变
108+
"""
109+
return {
110+
'type': gradient.type(),
111+
'spread': gradient.spread(),
112+
'start': gradient.start(),
113+
'finalStop': QPointF(1, 1) if hasattr(gradient, 'ex') else gradient.finalStop(),
114+
'stops': gradient.stops()
115+
}
116+
117+
@classmethod
118+
def toGradient(cls, data):
119+
"""把字典转成渐变
120+
:param cls:
121+
:param data: 字典数据
122+
"""
123+
gtype = data.get('type', -1)
124+
if gtype == QGradient.LinearGradient:
125+
gradient = QLinearGradient()
126+
elif gtype == QGradient.RadialGradient:
127+
gradient = QRadialGradient()
128+
elif gtype == QGradient.ConicalGradient:
129+
gradient = QConicalGradient()
130+
else:
131+
gradient = QLinearGradient()
132+
gradient.setSpread(data.get('spread', QGradient.PadSpread))
133+
gradient.setStart(data.get('start', QPointF(0, 0)))
134+
gradient.setFinalStop(data.get('finalStop', QPointF(1, 1)))
135+
stops = data.get('stops', None)
136+
if stops:
137+
gradient.setStops(stops)
138+
139+
return gradient
140+
101141
@classmethod
102142
def styleSheetCode(cls, colorgradient):
103143
"""颜色或渐变转字符串

Utils/ThemeManager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
4949
/*工具栏*/
5050
#widgetTools {{
51-
background-color: rgba({0}, {1}, {2}, 20);
51+
background-color: rgba({0}, {1}, {2}, 60);
5252
}}
5353
5454
/*工具栏中的按钮*/
@@ -155,7 +155,7 @@
155155
156156
/*工具栏*/
157157
#widgetTools {{
158-
background-color: rgba({0}, {1}, {2}, 20);
158+
background-color: rgba({0}, {1}, {2}, 60);
159159
}}
160160
161161
/*工具栏中的按钮*/

Widgets/MainWindowBase.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
import webbrowser
1414

1515
from PyQt5.QtCore import pyqtSlot, QUrl
16+
from PyQt5.QtGui import QColor
1617
from PyQt5.QtWebKit import QWebSettings
1718
from PyQt5.QtWebKitWidgets import QWebPage
1819

1920
from Utils import Constants
20-
from Utils.CommonUtil import Signals
21+
from Utils.CommonUtil import Signals, Setting, AppLog
22+
from Utils.GradientUtils import GradientUtils
2123
from Utils.NetworkAccessManager import NetworkAccessManager
2224
from Utils.ThemeManager import ThemeManager
25+
from Widgets.Dialogs.SkinDialog import SkinDialog
2326
from Widgets.ToolTip import ToolTip
2427

2528

@@ -36,8 +39,6 @@ def _initUi(self):
3639
self.buttonNormal.setVisible(False)
3740
# 隐藏目录树的滑动条
3841
self.treeViewCatalogs.verticalScrollBar().setVisible(False)
39-
# 加载主题
40-
ThemeManager.loadTheme()
4142
# 加载鼠标样式
4243
ThemeManager.loadCursor(self.widgetMain)
4344
ThemeManager.setPointerCursors([
@@ -56,6 +57,22 @@ def _initUi(self):
5657
ToolTip.bind(self.buttonHome)
5758
# 头像提示控件
5859
ToolTip.bind(self.buttonHead)
60+
# 加载主题
61+
colourful = Setting.value('colourful')
62+
picture = Setting.value('picture', '', str)
63+
AppLog.debug('colourful: %s', str(colourful))
64+
AppLog.debug('picture: %s', picture)
65+
if picture:
66+
ThemeManager.loadPictureTheme(picture)
67+
elif colourful:
68+
if isinstance(picture, QColor):
69+
ThemeManager.loadColourfulTheme(colourful)
70+
else:
71+
# json数据转渐变
72+
ThemeManager.loadColourfulTheme(
73+
GradientUtils.toGradient(colourful))
74+
else:
75+
ThemeManager.loadTheme()
5976

6077
def _initSignals(self):
6178
"""初始化信号槽"""
@@ -94,7 +111,9 @@ def _initWebView(self):
94111
def on_buttonSkin_clicked(self):
95112
"""选择主题样式
96113
"""
97-
pass
114+
if not hasattr(self, 'skinDialog'):
115+
self.skinDialog = SkinDialog(self)
116+
self.skinDialog.exec_()
98117

99118
@pyqtSlot()
100119
def on_buttonIssues_clicked(self):

Widgets/Skins/PreviewWidget.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
import os
1313

1414
from PyQt5.QtCore import Qt, pyqtSlot, QTimer
15-
from PyQt5.QtGui import QPixmap
15+
from PyQt5.QtGui import QPixmap, QColor
1616
from PyQt5.QtWidgets import QWidget, QGraphicsDropShadowEffect
1717

1818
from UiFiles.Ui_MainWindow import Ui_FormMainWindow
1919
from UiFiles.Ui_PreviewWidget import Ui_FormPreviewWidget
2020
from Utils.CommonUtil import Setting
21+
from Utils.GradientUtils import GradientUtils
2122
from Utils.ThemeManager import ThemeManager
2223

2324

@@ -109,9 +110,17 @@ def on_buttonPreviewApply_clicked(self):
109110
if self._which == self.Theme:
110111
ThemeManager.loadUserTheme(
111112
os.path.basename(os.path.dirname(self._poc)))
113+
Setting.setValue('picture', None)
114+
Setting.setValue('colourful', None)
112115
elif self._which == self.Color:
113116
ThemeManager.loadColourfulTheme(self._poc)
114-
Setting.setValue('colourful', self._poc)
117+
if isinstance(self._poc, QColor):
118+
Setting.setValue('colourful', self._poc)
119+
else:
120+
# 渐变需要转成字典数据
121+
Setting.setValue('colourful', GradientUtils.toJson(self._poc))
122+
Setting.setValue('picture', None)
115123
elif self._which == self.Picture:
116124
ThemeManager.loadPictureTheme(self._poc)
117-
Setting.setValue('picture', self._poc)
125+
Setting.setValue('colourful', None)
126+
Setting.setValue('picture', self._poc.replace('\\', '/'))

0 commit comments

Comments
 (0)