2424__Copyright__ = "Copyright (c) 2019 Irony"
2525__Version__ = "Version 1.0"
2626
27- StyleTemplate = """
27+ # 修改背景图片
28+ StylePictureTemplate = """
2829#widgetMain {{
2930 border-image: url({0}); /*背景图片*/
3031}}
32+ """
3133
34+ # 修改颜色
35+ StyleColorTemplate = """
3236/*工具栏*/
3337#widgetTools {{
34- background-color: rgba(38, 38, 38 , 10);
38+ background-color: rgba({0}, {1}, {2} , 10);
3539}}
3640
3741/*存放网页控件*/
4145
4246/*搜索框中的按钮*/
4347#buttonSearch {{
44- qproperty-bgColor: rgba({1 }, {2 }, {3 }, 255);
48+ qproperty-bgColor: rgba({0 }, {1 }, {2 }, 255);
4549}}
4650
4751/*返回顶部,主页按钮*/
4852#buttonBackToUp, #buttonHome {{
49- qproperty-bgColor: rgba({1 }, {2 }, {3 }, 255);
53+ qproperty-bgColor: rgba({0 }, {1 }, {2 }, 255);
5054}}
5155
5256/*工具栏中的按钮*/
5357#buttonGithub, #buttonQQ, #buttonGroup {{
54- background: rgba({1 }, {2 }, {3 }, 255);
58+ background: rgba({0 }, {1 }, {2 }, 255);
5559}}
5660
5761/*登录窗口*/
5862#widgetLogin {{
59- background: rgba({1 }, {2 }, {3 }, 210);
63+ background: rgba({0 }, {1 }, {2 }, 210);
6064}}
6165
6266/*激活状态*/
6367#widgetLogin[_active="true"] {{
64- border: 1px solid rgba({1 }, {2 }, {3 }, 255);
68+ border: 1px solid rgba({0 }, {1 }, {2 }, 255);
6569}}
6670"""
6771
72+ # 渐变颜色
73+ StyleGradientTemplate = """
74+ """
75+
6876
6977class ThemeManager :
7078
@@ -114,18 +122,32 @@ def loadUserTheme(cls, theme='Default'):
114122 Setting .setValue ('theme' , theme )
115123
116124 @classmethod
117- def loadColourfulTheme (cls , color ):
125+ def loadColourfulTheme (cls , color , widget = None ):
118126 """基于当前设置主题颜色
119127 :param cls:
120128 :param color: 背景颜色
129+ :param widget: 指定控件
121130 """
122- pass
131+ cls .ThemeName = Setting .value ('theme' , 'Default' , str )
132+ # 加载主题取样式
133+ path = cls .stylePath ()
134+ AppLog .info ('stylePath: {}' .format (path ))
135+ try :
136+ styleSheet = open (path , 'rb' ).read ().decode (
137+ 'utf-8' , errors = 'ignore' )
138+ # 需要替换部分样式
139+ styleSheet += StyleColorTemplate .format (* color )
140+ widget = widget or QApplication .instance ()
141+ widget .setStyleSheet (styleSheet )
142+ except Exception as e :
143+ AppLog .exception (e )
123144
124145 @classmethod
125- def loadPictureTheme (cls , image = None ):
146+ def loadPictureTheme (cls , image = None , widget = None ):
126147 """设置图片背景的主题
127148 :param cls:
128149 :param image: 背景图片
150+ :param widget: 指定控件
129151 """
130152 cls .ThemeName = Setting .value ('theme' , 'Default' , str )
131153 # 加载主题取样式
@@ -140,10 +162,10 @@ def loadPictureTheme(cls, image=None):
140162 color_thief = ColorThief (image )
141163 color = color_thief .get_color ()
142164 AppLog .info ('dominant color: {}' .format (str (color )))
143- styleSheet += StyleTemplate .format (
144- os . path . abspath ( image ).replace ('\\ ' , '/' ),
145- * color )
146- QApplication . instance () .setStyleSheet (styleSheet )
165+ styleSheet += StylePictureTemplate .format ( os . path . abspath (
166+ image ).replace ('\\ ' , '/' )) + StyleColorTemplate . format ( * color )
167+ widget = widget or QApplication . instance ( )
168+ widget .setStyleSheet (styleSheet )
147169 except Exception as e :
148170 AppLog .exception (e )
149171
0 commit comments