修复若干bug

This commit is contained in:
扫地僧 2026-04-03 22:48:27 +08:00
parent 10843a5bc5
commit 17655f2dba
16 changed files with 108 additions and 2 deletions

Binary file not shown.

BIN
assets/imgs/weather/雾.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

Binary file not shown.

View File

@ -228,3 +228,18 @@ def reorder_items(group_id, id_list):
conn.execute("UPDATE items SET position=? WHERE id=?", (pos, iid)) conn.execute("UPDATE items SET position=? WHERE id=?", (pos, iid))
conn.commit() conn.commit()
conn.close() conn.close()
def reset_groups_and_items(recreate_default_group: bool = True):
"""
清空所有分组与程序items
- 为避免外键级联受 SQLite 外键开关影响这里显式先删 items 再删 groups
- 可选地重新创建默认分组常用程序保证界面至少有一个组可操作
"""
conn = get_conn()
conn.execute("DELETE FROM items")
conn.execute("DELETE FROM groups")
if recreate_default_group:
conn.execute("INSERT INTO groups (name, position) VALUES ('常用程序', 0)")
conn.commit()
conn.close()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -858,6 +858,16 @@ class PanelWindow(QWidget):
) )
self.groups_layout.insertWidget(self.groups_layout.count() - 1, gw) self.groups_layout.insertWidget(self.groups_layout.count() - 1, gw)
def reset_groups_and_items(self):
"""清空所有分组与程序,并刷新界面。"""
database.reset_groups_and_items(recreate_default_group=True)
# 清空搜索关键字,确保刷新后可见全部内容
try:
self.search_box.setText("")
except Exception:
pass
self.refresh_groups()
def _add_group(self): def _add_group(self):
name, ok = dialog_style.get_text(self, "新建分组", "分组名称:") name, ok = dialog_style.get_text(self, "新建分组", "分组名称:")
if ok and name.strip(): if ok and name.strip():
@ -909,12 +919,13 @@ class PanelWindow(QWidget):
def _collapse_body(self): def _collapse_body(self):
"""收缩:隐藏内容区,窗口缩到只剩标题栏高度""" """收缩:隐藏内容区,窗口缩到只剩标题栏高度"""
self._body.hide() self._body.hide()
self.weather_bar.hide()
# 记录当前高度,展开时恢复 # 记录当前高度,展开时恢复
self._expanded_height = self.height() self._expanded_height = self.height()
title_h = ( title_h = (
self.container.layout().contentsMargins().top() self.container.layout().contentsMargins().top()
+ self.container.layout().contentsMargins().bottom() + self.container.layout().contentsMargins().bottom()
+ 46 + self._title_bar.sizeHint().height()
) )
self.setFixedHeight(title_h) self.setFixedHeight(title_h)
ic = "#cccccc" if theme.name() == "dark" else "#555555" ic = "#cccccc" if theme.name() == "dark" else "#555555"
@ -923,6 +934,7 @@ class PanelWindow(QWidget):
def _expand_body(self): def _expand_body(self):
"""展开:恢复内容区和窗口高度""" """展开:恢复内容区和窗口高度"""
self.weather_bar.show()
self._body.show() self._body.show()
h = getattr(self, "_expanded_height", 520) h = getattr(self, "_expanded_height", 520)
self.setMinimumHeight(MIN_H) self.setMinimumHeight(MIN_H)

View File

@ -6,10 +6,12 @@ from PyQt6.QtWidgets import (
QCheckBox, QGroupBox, QFormLayout, QSpinBox, QFrame QCheckBox, QGroupBox, QFormLayout, QSpinBox, QFrame
) )
from PyQt6.QtCore import Qt, QSize from PyQt6.QtCore import Qt, QSize
from PyQt6.QtWidgets import QMessageBox
from PyQt6.QtGui import QIcon, QPixmap from PyQt6.QtGui import QIcon, QPixmap
import qtawesome as qta import qtawesome as qta
from db import database from db import database
import ui.theme as theme import ui.theme as theme
import ui.dialog_style as dialog_style
class SettingsWindow(QDialog): class SettingsWindow(QDialog):
@ -50,7 +52,10 @@ class SettingsWindow(QDialog):
("fa5s.window-maximize", "窗口"), ("fa5s.window-maximize", "窗口"),
("fa5s.rocket", "启动"), ("fa5s.rocket", "启动"),
("fa5s.heart", "捐赠"), ("fa5s.heart", "捐赠"),
("fa5s.eraser", "初始化"),
] ]
self._nav_ready = False
self._block_nav = False
for icon_name, label in pages: for icon_name, label in pages:
try: try:
icon = qta.icon(icon_name, color="#888") icon = qta.icon(icon_name, color="#888")
@ -59,6 +64,8 @@ class SettingsWindow(QDialog):
# 防止图标名不存在导致设置页直接报错 # 防止图标名不存在导致设置页直接报错
icon = qta.icon("fa5s.rocket", color="#888") icon = qta.icon("fa5s.rocket", color="#888")
item = QListWidgetItem(icon, label) item = QListWidgetItem(icon, label)
if label == "初始化":
item.setData(Qt.ItemDataRole.UserRole, "init")
self.nav.addItem(item) self.nav.addItem(item)
self.nav.setCurrentRow(0) self.nav.setCurrentRow(0)
self.nav.currentRowChanged.connect(self._on_nav) self.nav.currentRowChanged.connect(self._on_nav)
@ -69,6 +76,11 @@ class SettingsWindow(QDialog):
self.stack.addWidget(self._page_window()) self.stack.addWidget(self._page_window())
self.stack.addWidget(self._page_startup()) self.stack.addWidget(self._page_startup())
self.stack.addWidget(self._page_donate()) self.stack.addWidget(self._page_donate())
self.stack.addWidget(self._page_initialization())
# 此时 stack 已就绪,允许导航回调正常工作
self._nav_ready = True
self._last_nav_index = self.nav.currentRow()
self.stack.setCurrentIndex(self._last_nav_index)
# 分割线 # 分割线
line = QFrame() line = QFrame()
@ -312,6 +324,29 @@ class SettingsWindow(QDialog):
self._donate_card = card self._donate_card = card
return page return page
def _page_initialization(self) -> QWidget:
page = QWidget()
layout = QVBoxLayout(page)
layout.setContentsMargins(24, 20, 24, 20)
layout.setSpacing(16)
layout.addWidget(self._section_title("初始化"))
desc = QLabel(
"点击左侧「初始化」页签后,将弹出确认提醒。\n"
"确认后会清空所有分组和程序(不可撤销)。"
)
desc.setWordWrap(True)
desc.setStyleSheet("color:#888; font-size:13px; line-height:1.6;")
layout.addWidget(desc)
self._init_status_lbl = QLabel("")
self._init_status_lbl.setStyleSheet("font-size:12px; color:#f90;")
layout.addWidget(self._init_status_lbl)
layout.addStretch()
return page
def _open_donate_image(self, img_path: str): def _open_donate_image(self, img_path: str):
"""点击二维码后的弹窗大图查看。""" """点击二维码后的弹窗大图查看。"""
t = theme.current() t = theme.current()
@ -386,7 +421,51 @@ class SettingsWindow(QDialog):
return line return line
def _on_nav(self, index: int): def _on_nav(self, index: int):
self.stack.setCurrentIndex(index) if self._block_nav:
return
if not getattr(self, "_nav_ready", False) or not hasattr(self, "stack"):
return
item = self.nav.item(index)
is_init_tab = bool(item and item.data(Qt.ItemDataRole.UserRole) == "init")
if not is_init_tab:
self.stack.setCurrentIndex(index)
self._last_nav_index = index
return
ret = dialog_style.question(
self,
"初始化",
"提醒请谨慎操作!!!!!\n\n"
"此操作会清空所有分组和程序,且无法撤销。是否继续?",
icon=QMessageBox.Icon.Warning,
)
if ret == QMessageBox.StandardButton.Yes:
try:
self._panel.reset_groups_and_items()
except Exception as e:
# 初始化失败也要尽量让用户知道原因
dialog_style.warning(self, "初始化失败", f"清空数据失败:{e}")
# 初始化失败则回退到上一个页签
self._block_nav = True
self.nav.setCurrentRow(self._last_nav_index)
self._block_nav = False
self.stack.setCurrentIndex(self._last_nav_index)
return
if hasattr(self, "_init_status_lbl"):
self._init_status_lbl.setText("已完成初始化(分组和程序已清空)。")
self.stack.setCurrentIndex(index)
self._last_nav_index = index
else:
# 用户取消:回退到上一个页签
self._block_nav = True
self.nav.setCurrentRow(self._last_nav_index)
self._block_nav = False
self.stack.setCurrentIndex(self._last_nav_index)
def _apply_theme(self): def _apply_theme(self):
t = theme.current() t = theme.current()