Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 153 additions & 6 deletions app/common/notification/notification_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,39 @@
self.layout.addWidget(widget)
self.content_widgets.append(widget)

# 确保新添加的 BodyLabel 可见:根据主题强制设置前景色
try:
from app.tools.personalised import is_dark_theme
from qfluentwidgets import qconfig
from qfluentwidgets import BodyLabel as QFBodyLabel

fg = "#ffffff" if is_dark_theme(qconfig) else "#000000"

def apply_fg_to(w):
# 如果是直接的 BodyLabel,设置样式
if isinstance(w, QFBodyLabel):
existing = w.styleSheet() or ""
if "color:" not in existing:
# 保留已有样式,追加颜色
w.setStyleSheet(existing + f" color: {fg};")
else:
# 遍历子控件查找 BodyLabel
for child in w.findChildren(QFBodyLabel):
existing = child.styleSheet() or ""
if "color:" not in existing:
child.setStyleSheet(existing + f" color: {fg};")

for w in self.content_widgets:
try:
apply_fg_to(w)
except Exception as e:
from loguru import logger

logger.exception("Error applying fg to content widget: {}", e)
except Exception:

Check notice on line 68 in app/common/notification/notification_service.py

View check run for this annotation

codefactor.io / CodeFactor

app/common/notification/notification_service.py#L66-L68

Try, Except, Pass detected. (B110)
# 忽略主题检测错误,保持原样
pass


class NotificationWindowTemplate(PageTemplate):
"""通知窗口页面模板"""
Expand Down Expand Up @@ -69,6 +102,16 @@
# 设置UI
self.setup_ui()

# 订阅主题变化,确保切换主题时更新文字颜色
try:
from qfluentwidgets import qconfig

qconfig.themeChanged.connect(self._on_theme_changed)
except Exception as e:
from loguru import logger

logger.exception("Error connecting themeChanged signal (ignored): {}", e)

# 设置窗口圆角
self.setBorderRadius(15)

Expand Down Expand Up @@ -198,7 +241,10 @@
)
self.update_drag_line_style()
self.update_drag_line_container_style()
except:
except Exception as e:
from loguru import logger

logger.exception("Error updating background style (fallback used): {}", e)
# 如果无法获取主题信息,默认使用白色背景和深色拖动线
background_color = "#ffffff"
self.background_widget.setStyleSheet(
Expand Down Expand Up @@ -227,7 +273,12 @@
self.drag_line_container.setStyleSheet(
f"background-color: {background_color}; border-top-left-radius: 15px; border-top-right-radius: 15px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px;"
)
except:
except Exception as e:
from loguru import logger

logger.exception(
"Error updating drag line container style (fallback used): {}", e
)
# 如果无法获取主题信息,默认使用白色背景
self.drag_line_container.setStyleSheet(
"background-color: #ffffff; border-top-left-radius: 15px; border-top-right-radius: 15px; border-bottom-left-radius: 0px; border-bottom-right-radius: 0px;"
Expand Down Expand Up @@ -258,6 +309,20 @@
# 设置透明度(背景和字体透明度统一)
self.setWindowOpacity(transparency)

# 设置倒计时标签颜色,确保与背景对比
try:
from app.tools.personalised import is_dark_theme
from qfluentwidgets import qconfig

fg = "#ffffff" if is_dark_theme(qconfig) else "#000000"
existing = self.countdown_label.styleSheet() or ""
if "color:" not in existing:
self.countdown_label.setStyleSheet(existing + f" color: {fg};")
except Exception as e:
from loguru import logger

logger.exception("Error setting countdown label color: {}", e)

# 根据设置定位窗口
self.position_window(settings)

Expand Down Expand Up @@ -287,6 +352,69 @@
self.countdown_timer.stop()
self.countdown_label.setText("连续点击3次关闭窗口")

def _on_theme_changed(self):
"""主题切换时更新浮窗内文字和背景颜色"""
try:
from app.tools.personalised import is_dark_theme
from qfluentwidgets import qconfig

fg = "#ffffff" if is_dark_theme(qconfig) else "#000000"

# 更新所有 BodyLabel 子控件颜色
for lbl in self.findChildren(BodyLabel):
try:
existing = lbl.styleSheet() or ""
parts = [
p.strip()
for p in existing.split(";")
if p.strip() and not p.strip().startswith("color:")
]
parts.append(f"color: {fg} !important")
lbl.setStyleSheet("; ".join(parts) + ";")
except Exception as e:
from loguru import logger

logger.exception(
"Error applying color to label child (continuing): {}", e
)
continue

# 更新倒计时标签颜色
try:
existing = self.countdown_label.styleSheet() or ""
parts = [
p.strip()
for p in existing.split(";")
if p.strip() and not p.strip().startswith("color:")
]
parts.append(f"color: {fg} !important")
self.countdown_label.setStyleSheet("; ".join(parts) + ";")
except Exception as e:
from loguru import logger

logger.exception(
"Error applying countdown label color (ignored): {}", e
)
pass

# 更新背景与拖动线样式
try:
self.update_background_style()
self.update_drag_line_style()
self.update_drag_line_container_style()
except Exception as e:
from loguru import logger

logger.exception(
"Error updating background/drag line styles (ignored): {}", e
)
pass
except Exception as e:
from loguru import logger

logger.exception("Error in _on_theme_changed (ignored): {}", e)
pass

def _get_screen_from_settings(self, settings):
"""根据设置获取屏幕"""
screen = QApplication.primaryScreen()
Expand Down Expand Up @@ -540,6 +668,13 @@

# 立即更新倒计时显示(显示"正在抽取中")
self.update_countdown_display()
# 确保颜色与当前主题同步
try:
self._on_theme_changed()
except Exception as e:
from loguru import logger

logger.exception("Error syncing theme on show (ignored): {}", e)

def on_animation_finished(self):
"""动画完成后的处理"""
Expand All @@ -561,9 +696,10 @@
try:
if not (self.windowFlags() & Qt.WindowDoesNotAcceptFocus):
self.activateWindow()
except Exception:
# 保险兜底:如果出现问题则不激活窗口
pass
except Exception as e:
from loguru import logger

logger.exception("Error activating window (ignored): {}", e)

# 更新倒计时显示
self.update_countdown_display()
Expand Down Expand Up @@ -616,6 +752,14 @@
for label in student_labels:
self.content_layout.addWidget(label)

# 确保颜色与当前主题同步
try:
self._on_theme_changed()
except Exception as e:
from loguru import logger

logger.exception("Error syncing theme on update_content (ignored): {}", e)

# 调整窗口大小以适应内容
self.adjustSize()

Expand Down Expand Up @@ -673,7 +817,10 @@
return get_content_name_async(
"notification_settings", "notification_result"
)
except:
except Exception as e:
from loguru import logger

logger.exception("Error getting notification title (fallback used): {}", e)
# 如果无法获取多语言文本,则使用默认文本
return "通知结果"

Expand Down
13 changes: 9 additions & 4 deletions app/page_building/page_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from PySide6.QtGui import *
from PySide6.QtCore import *
from PySide6.QtNetwork import *
import loguru
from qfluentwidgets import *

from app.tools.variable import *
Expand Down Expand Up @@ -108,10 +109,12 @@ def create_content(self):
self.content_created = True

elapsed = time.perf_counter() - start
logger.debug(f"创建内容组件 {content_name} 耗时: {elapsed:.3f}s")
loguru.logger.debug(f"创建内容组件 {content_name} 耗时: {elapsed:.3f}s")
except Exception as e:
elapsed = time.perf_counter() - start
logger.error(f"创建内容组件失败 ({elapsed:.3f}s): {e}")
from loguru import logger

logger.exception(f"创建内容组件失败 ({elapsed:.3f}s): {e}")

def create_empty_content(self, message="该页面正在开发中,敬请期待!"):
"""创建空页面内容"""
Expand Down Expand Up @@ -437,8 +440,10 @@ def load_all_pages(self, interval_ms: int = 50, max_per_tick: int = 5):
]
),
)
except Exception:
pass
except Exception as e:
from loguru import logger

logger.exception("Error scheduling batch page loads (ignored): {}", e)

def on_current_index_changed(self, index: int):
"""堆叠窗口索引改变时的处理"""
Expand Down
8 changes: 7 additions & 1 deletion app/page_building/window_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ def _apply_current_theme(self) -> None:
self.default_page.setStyleSheet(
"background-color: transparent;"
)
except:
except Exception as e:
from loguru import logger

logger.exception(
"Error detecting dark mode with darkdetect (fallback to light): {}",
e,
)
# 如果检测失败,使用浅色主题
self.setStyleSheet("background-color: #ffffff;")
self.default_page.setStyleSheet("background-color: transparent;")
Expand Down
7 changes: 6 additions & 1 deletion app/tools/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,12 @@ def calculate_weight(students_data: list, class_name: str) -> list:
current_time = datetime.now()
days_diff = (current_time - last_time).days
time_factor = min(1.0, days_diff / 30.0) * 0.5
except:
except Exception as e:
from loguru import logger

logger.exception(
"Error calculating time factor for student weights: {}", e
)
time_factor = 0.0
else:
time_factor = 0.0
Expand Down
31 changes: 27 additions & 4 deletions app/tools/result_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,21 @@ def _apply_label_style(label, font_size, animation_color):
style_sheet = f"font-size: {font_size}pt; "

if animation_color == 1:
style_sheet += f"color: {ResultDisplayUtils._generate_vibrant_color()};"
style_sheet += f"color: {ResultDisplayUtils._generate_vibrant_color()} !important;"
elif animation_color == 2:
style_sheet += f"color: {fixed_color};"
style_sheet += f"color: {fixed_color} !important;"
else:
try:
from app.tools.personalised import is_dark_theme
from qfluentwidgets import qconfig

default_color = (
"#ffffff" if is_dark_theme(qconfig) else "#000000"
)
style_sheet += f"color: {default_color} !important;"
except Exception:
# 兜底使用黑色
style_sheet += "color: #000000 !important;"

widget.setStyleSheet(style_sheet)
else:
Expand All @@ -203,9 +215,20 @@ def _apply_label_style(label, font_size, animation_color):
"roll_call_settings", "animation_fixed_color"
)
if animation_color == 1:
style_sheet += f"color: {ResultDisplayUtils._generate_vibrant_color()};"
style_sheet += (
f"color: {ResultDisplayUtils._generate_vibrant_color()} !important;"
)
elif animation_color == 2:
style_sheet += f"color: {fixed_color};"
style_sheet += f"color: {fixed_color} !important;"
else:
try:
from app.tools.personalised import is_dark_theme
from qfluentwidgets import qconfig

default_color = "#ffffff" if is_dark_theme(qconfig) else "#000000"
style_sheet += f"color: {default_color} !important;"
except Exception:
style_sheet += "color: #000000 !important;"

label.setStyleSheet(style_sheet)

Expand Down
Loading