Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
k54kdk
PyQt Fluent Widgets
提交
1734a8ae
P
PyQt Fluent Widgets
项目概览
k54kdk
/
PyQt Fluent Widgets
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PyQt Fluent Widgets
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
1734a8ae
编写于
3月 22, 2023
作者:
之一Yo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加修改主题时是否保存配置的选项
上级
6af6c121
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
20 deletion
+30
-20
qfluentwidgets/common/config.py
qfluentwidgets/common/config.py
+8
-11
qfluentwidgets/common/style_sheet.py
qfluentwidgets/common/style_sheet.py
+22
-9
未找到文件。
qfluentwidgets/common/config.py
浏览文件 @
1734a8ae
...
@@ -253,7 +253,7 @@ class QConfig(QObject):
...
@@ -253,7 +253,7 @@ class QConfig(QObject):
themeChanged
=
pyqtSignal
(
Theme
)
themeChanged
=
pyqtSignal
(
Theme
)
themeMode
=
OptionsConfigItem
(
themeMode
=
OptionsConfigItem
(
"
MainWindow
"
,
"ThemeMode"
,
Theme
.
AUTO
,
OptionsValidator
(
Theme
),
EnumSerializer
(
Theme
))
"
QFluentWidgets
"
,
"ThemeMode"
,
Theme
.
AUTO
,
OptionsValidator
(
Theme
),
EnumSerializer
(
Theme
))
def
__init__
(
self
):
def
__init__
(
self
):
super
().
__init__
()
super
().
__init__
()
...
@@ -265,18 +265,21 @@ class QConfig(QObject):
...
@@ -265,18 +265,21 @@ class QConfig(QObject):
""" get the value of config item """
""" get the value of config item """
return
item
.
value
return
item
.
value
def
set
(
self
,
item
,
value
):
def
set
(
self
,
item
,
value
,
save
=
True
):
""" set the value of config item """
""" set the value of config item """
if
item
.
value
==
value
:
if
item
.
value
==
value
:
return
return
item
.
value
=
value
item
.
value
=
value
self
.
save
()
if
save
:
self
.
save
()
if
item
.
restart
:
if
item
.
restart
:
self
.
_cfg
.
appRestartSig
.
emit
()
self
.
_cfg
.
appRestartSig
.
emit
()
if
item
is
self
.
_cfg
.
themeMode
:
if
item
is
self
.
_cfg
.
themeMode
:
self
.
theme
=
value
self
.
_cfg
.
themeChanged
.
emit
(
value
)
self
.
_cfg
.
themeChanged
.
emit
(
value
)
def
toDict
(
self
,
serialize
=
True
):
def
toDict
(
self
,
serialize
=
True
):
...
@@ -300,6 +303,7 @@ class QConfig(QObject):
...
@@ -300,6 +303,7 @@ class QConfig(QObject):
return
items
return
items
def
save
(
self
):
def
save
(
self
):
""" save config """
self
.
_cfg
.
file
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
self
.
_cfg
.
file
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
with
open
(
self
.
_cfg
.
file
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
with
open
(
self
.
_cfg
.
file
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
json
.
dump
(
self
.
_cfg
.
toDict
(),
f
,
ensure_ascii
=
False
,
indent
=
4
)
json
.
dump
(
self
.
_cfg
.
toDict
(),
f
,
ensure_ascii
=
False
,
indent
=
4
)
...
@@ -345,14 +349,7 @@ class QConfig(QObject):
...
@@ -345,14 +349,7 @@ class QConfig(QObject):
if
items
.
get
(
key
)
is
not
None
:
if
items
.
get
(
key
)
is
not
None
:
items
[
key
].
deserializeFrom
(
value
)
items
[
key
].
deserializeFrom
(
value
)
if
self
.
get
(
self
.
themeMode
)
==
Theme
.
AUTO
:
self
.
theme
=
self
.
get
(
self
.
themeMode
)
theme
=
darkdetect
.
theme
()
if
theme
:
self
.
_cfg
.
_theme
=
Theme
(
theme
)
else
:
self
.
_cfg
.
_theme
=
Theme
.
LIGHT
else
:
self
.
_cfg
.
_theme
=
self
.
get
(
self
.
themeMode
)
@
property
@
property
def
theme
(
self
):
def
theme
(
self
):
...
...
qfluentwidgets/common/style_sheet.py
浏览文件 @
1734a8ae
...
@@ -87,14 +87,8 @@ def setStyleSheet(widget, file, theme=Theme.AUTO, register=True):
...
@@ -87,14 +87,8 @@ def setStyleSheet(widget, file, theme=Theme.AUTO, register=True):
widget
.
setStyleSheet
(
getStyleSheet
(
file
,
theme
))
widget
.
setStyleSheet
(
getStyleSheet
(
file
,
theme
))
def
setTheme
(
theme
:
Theme
):
def
updateStyleSheet
():
""" set the theme of application """
""" update the style sheet of all fluent widgets """
if
theme
==
Theme
.
AUTO
:
theme
=
darkdetect
.
theme
()
qconfig
.
theme
=
Theme
(
theme
)
if
theme
else
Theme
.
LIGHT
else
:
qconfig
.
theme
=
theme
removes
=
[]
removes
=
[]
for
widget
,
file
in
styleSheetManager
.
items
():
for
widget
,
file
in
styleSheetManager
.
items
():
try
:
try
:
...
@@ -103,4 +97,23 @@ def setTheme(theme: Theme):
...
@@ -103,4 +97,23 @@ def setTheme(theme: Theme):
removes
.
append
(
widget
)
removes
.
append
(
widget
)
for
widget
in
removes
:
for
widget
in
removes
:
styleSheetManager
.
deregister
(
widget
)
styleSheetManager
.
deregister
(
widget
)
\ No newline at end of file
def
setTheme
(
theme
:
Theme
,
save
=
False
):
""" set the theme of application
Parameters
----------
theme: Theme
theme mode
save: bool
whether to save the change to config file
"""
if
theme
==
Theme
.
AUTO
:
theme
=
darkdetect
.
theme
()
theme
=
Theme
(
theme
)
if
theme
else
Theme
.
LIGHT
qconfig
.
set
(
qconfig
.
themeMode
,
theme
,
save
)
updateStyleSheet
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录