chore(ui): 优化实现方法
This commit is contained in:
@@ -933,6 +933,38 @@ class TimeEditSettingCard(SettingCard):
|
|||||||
self.TimeEdit.setTime(QTime.fromString(value, "HH:mm"))
|
self.TimeEdit.setTime(QTime.fromString(value, "HH:mm"))
|
||||||
|
|
||||||
|
|
||||||
|
class StatusSwitchSetting(SwitchButton):
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
qconfig: QConfig,
|
||||||
|
configItem_check: ConfigItem,
|
||||||
|
configItem_enable: ConfigItem,
|
||||||
|
parent=None,
|
||||||
|
):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.qconfig = qconfig
|
||||||
|
self.configItem_check = configItem_check
|
||||||
|
self.configItem_enable = configItem_enable
|
||||||
|
self.setOffText("")
|
||||||
|
self.setOnText("")
|
||||||
|
|
||||||
|
if configItem_check:
|
||||||
|
self.setValue(self.qconfig.get(configItem_check))
|
||||||
|
configItem_check.valueChanged.connect(self.setValue)
|
||||||
|
if configItem_enable:
|
||||||
|
self.setEnabled(self.qconfig.get(configItem_enable))
|
||||||
|
configItem_enable.valueChanged.connect(self.setEnabled)
|
||||||
|
|
||||||
|
self.checkedChanged.connect(self.setValue)
|
||||||
|
|
||||||
|
def setValue(self, isChecked: bool):
|
||||||
|
if self.configItem_check:
|
||||||
|
self.qconfig.set(self.configItem_check, isChecked)
|
||||||
|
|
||||||
|
self.setChecked(isChecked)
|
||||||
|
|
||||||
|
|
||||||
class HistoryCard(HeaderCardWidget):
|
class HistoryCard(HeaderCardWidget):
|
||||||
|
|
||||||
def __init__(self, qconfig: QConfig, configItem: ConfigItem, parent=None):
|
def __init__(self, qconfig: QConfig, configItem: ConfigItem, parent=None):
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ from qfluentwidgets import (
|
|||||||
PushSettingCard,
|
PushSettingCard,
|
||||||
TableWidget,
|
TableWidget,
|
||||||
PrimaryToolButton,
|
PrimaryToolButton,
|
||||||
SwitchButton,
|
|
||||||
)
|
)
|
||||||
from PySide6.QtCore import Signal
|
from PySide6.QtCore import Signal
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -72,6 +71,7 @@ from .Widget import (
|
|||||||
SwitchSettingCard,
|
SwitchSettingCard,
|
||||||
PushAndSwitchButtonSettingCard,
|
PushAndSwitchButtonSettingCard,
|
||||||
PushAndComboBoxSettingCard,
|
PushAndComboBoxSettingCard,
|
||||||
|
StatusSwitchSetting,
|
||||||
PivotArea,
|
PivotArea,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1173,13 +1173,6 @@ class MemberManager(QWidget):
|
|||||||
Config.PASSWORD_refreshed.connect(self.load_info)
|
Config.PASSWORD_refreshed.connect(self.load_info)
|
||||||
|
|
||||||
def load_info(self):
|
def load_info(self):
|
||||||
# 使用闭包工厂函数捕获当前config:
|
|
||||||
def create_handler(config_obj):
|
|
||||||
def handler(checked):
|
|
||||||
# 使用配置项的set方法自动触发信号
|
|
||||||
config_obj.set(config_obj.Info_Status, checked)
|
|
||||||
|
|
||||||
return handler
|
|
||||||
|
|
||||||
self.user_data = Config.member_dict[self.name]["UserData"]
|
self.user_data = Config.member_dict[self.name]["UserData"]
|
||||||
|
|
||||||
@@ -1188,7 +1181,6 @@ class MemberManager(QWidget):
|
|||||||
for name, info in self.user_data.items():
|
for name, info in self.user_data.items():
|
||||||
|
|
||||||
config = info["Config"]
|
config = info["Config"]
|
||||||
handler = create_handler(config)
|
|
||||||
|
|
||||||
text_list = []
|
text_list = []
|
||||||
if not config.get(config.Data_IfPassCheck):
|
if not config.get(config.Data_IfPassCheck):
|
||||||
@@ -1209,7 +1201,6 @@ class MemberManager(QWidget):
|
|||||||
else "本周剿灭未完成"
|
else "本周剿灭未完成"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 跳转按钮
|
|
||||||
button = PrimaryToolButton(
|
button = PrimaryToolButton(
|
||||||
FluentIcon.CHEVRON_RIGHT, self
|
FluentIcon.CHEVRON_RIGHT, self
|
||||||
)
|
)
|
||||||
@@ -1218,18 +1209,6 @@ class MemberManager(QWidget):
|
|||||||
partial(self.switch_to.emit, name)
|
partial(self.switch_to.emit, name)
|
||||||
)
|
)
|
||||||
|
|
||||||
# 状态开关
|
|
||||||
switch_button = SwitchButton()
|
|
||||||
switch_button.setOffText("")
|
|
||||||
switch_button.setOnText("")
|
|
||||||
# 初始化开关状态
|
|
||||||
switch_button.setChecked(config.get(config.Info_Status))
|
|
||||||
switch_button.setEnabled(
|
|
||||||
config.get(config.Info_RemainedDay) != 0
|
|
||||||
)
|
|
||||||
# 将开关的bool同步
|
|
||||||
switch_button.checkedChanged.connect(handler)
|
|
||||||
|
|
||||||
self.dashboard.setItem(
|
self.dashboard.setItem(
|
||||||
int(name[3:]) - 1,
|
int(name[3:]) - 1,
|
||||||
0,
|
0,
|
||||||
@@ -1253,7 +1232,14 @@ class MemberManager(QWidget):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
self.dashboard.setCellWidget(
|
self.dashboard.setCellWidget(
|
||||||
int(name[3:]) - 1, 3, switch_button
|
int(name[3:]) - 1,
|
||||||
|
3,
|
||||||
|
StatusSwitchSetting(
|
||||||
|
qconfig=config,
|
||||||
|
configItem_check=config.Info_Status,
|
||||||
|
configItem_enable=config.Info_RemainedDay,
|
||||||
|
parent=self,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
self.dashboard.setItem(
|
self.dashboard.setItem(
|
||||||
int(name[3:]) - 1,
|
int(name[3:]) - 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user