audit-e2w 0.0.0-stage → 1.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +152 -3
- package/cordis.patch.yml +3 -0
- package/dsh_plugins/audit-e2w/lib/engine.mjs +174 -0
- package/dsh_plugins/audit-e2w/lib/index.js +122 -0
- package/dsh_plugins/audit-e2w/lib/skill.js +42 -0
- package/excel_word/README.md +388 -0
- package/excel_word/qoder_engine.py +437 -0
- package/excel_word/requirements.txt +4 -0
- package/excel_word/wesync/__init__.py +19 -0
- package/excel_word/wesync/__main__.py +6 -0
- package/excel_word/wesync/ai/__init__.py +52 -0
- package/excel_word/wesync/ai/actions.py +369 -0
- package/excel_word/wesync/ai/client.py +340 -0
- package/excel_word/wesync/ai/config.py +291 -0
- package/excel_word/wesync/ai/docs.py +177 -0
- package/excel_word/wesync/ai/prompts.py +288 -0
- package/excel_word/wesync/ai/tasks/__init__.py +26 -0
- package/excel_word/wesync/ai/tasks/actions_task.py +97 -0
- package/excel_word/wesync/ai/tasks/combined.py +123 -0
- package/excel_word/wesync/ai/tasks/diff_note.py +61 -0
- package/excel_word/wesync/ai/tasks/headings.py +119 -0
- package/excel_word/wesync/ai/tasks/help_task.py +69 -0
- package/excel_word/wesync/ai/tasks/roles.py +128 -0
- package/excel_word/wesync/align.py +155 -0
- package/excel_word/wesync/api.py +1292 -0
- package/excel_word/wesync/backup_history.py +100 -0
- package/excel_word/wesync/changelog.py +58 -0
- package/excel_word/wesync/cli.py +191 -0
- package/excel_word/wesync/commands/__init__.py +8 -0
- package/excel_word/wesync/commands/blank_cmd.py +279 -0
- package/excel_word/wesync/commands/bookmark_cmd.py +146 -0
- package/excel_word/wesync/commands/clear_cmd.py +50 -0
- package/excel_word/wesync/commands/export_cmd.py +270 -0
- package/excel_word/wesync/commands/incremental_cmd.py +157 -0
- package/excel_word/wesync/commands/marks_cmd.py +160 -0
- package/excel_word/wesync/commands/placeholders_cmd.py +92 -0
- package/excel_word/wesync/commands/writeback_cmd.py +469 -0
- package/excel_word/wesync/config.py +97 -0
- package/excel_word/wesync/console.py +85 -0
- package/excel_word/wesync/docx_blank.py +156 -0
- package/excel_word/wesync/docx_bookmarks.py +294 -0
- package/excel_word/wesync/docx_columns.py +257 -0
- package/excel_word/wesync/docx_edit.py +77 -0
- package/excel_word/wesync/docx_grid.py +212 -0
- package/excel_word/wesync/docx_marks.py +399 -0
- package/excel_word/wesync/docx_meta.py +157 -0
- package/excel_word/wesync/docx_newtable.py +220 -0
- package/excel_word/wesync/docx_placeholders.py +200 -0
- package/excel_word/wesync/docx_rows.py +67 -0
- package/excel_word/wesync/errors.py +5 -0
- package/excel_word/wesync/excel_blocks.py +502 -0
- package/excel_word/wesync/excel_export.py +143 -0
- package/excel_word/wesync/excel_marks.py +265 -0
- package/excel_word/wesync/excel_totals.py +53 -0
- package/excel_word/wesync/fsops.py +219 -0
- package/excel_word/wesync/gui/__init__.py +53 -0
- package/excel_word/wesync/gui/__main__.py +6 -0
- package/excel_word/wesync/gui/app.py +613 -0
- package/excel_word/wesync/gui/manual.py +70 -0
- package/excel_word/wesync/gui/pages/__init__.py +80 -0
- package/excel_word/wesync/gui/pages/_page.py +211 -0
- package/excel_word/wesync/gui/pages/ai_page.py +854 -0
- package/excel_word/wesync/gui/pages/batch_page.py +456 -0
- package/excel_word/wesync/gui/pages/blank_page.py +530 -0
- package/excel_word/wesync/gui/pages/bookmark_page.py +97 -0
- package/excel_word/wesync/gui/pages/export_page.py +141 -0
- package/excel_word/wesync/gui/pages/feedback_page.py +196 -0
- package/excel_word/wesync/gui/pages/format_page.py +551 -0
- package/excel_word/wesync/gui/pages/help_page.py +158 -0
- package/excel_word/wesync/gui/pages/history_page.py +168 -0
- package/excel_word/wesync/gui/pages/marks_page.py +211 -0
- package/excel_word/wesync/gui/pages/settings_page.py +450 -0
- package/excel_word/wesync/gui/pages/writeback_page.py +473 -0
- package/excel_word/wesync/gui/resources.py +22 -0
- package/excel_word/wesync/gui/runner.py +90 -0
- package/excel_word/wesync/gui/store.py +50 -0
- package/excel_word/wesync/gui/theme.py +271 -0
- package/excel_word/wesync/gui/widgets/__init__.py +8 -0
- package/excel_word/wesync/gui/widgets/ai_config.py +362 -0
- package/excel_word/wesync/gui/widgets/cards.py +139 -0
- package/excel_word/wesync/gui/widgets/chips.py +565 -0
- package/excel_word/wesync/gui/widgets/filebar.py +58 -0
- package/excel_word/wesync/gui/widgets/logpane.py +126 -0
- package/excel_word/wesync/gui/widgets/nav.py +294 -0
- package/excel_word/wesync/gui/widgets/theme_choice.py +93 -0
- package/excel_word/wesync/report_format.py +1585 -0
- package/excel_word/wesync/settings.py +35 -0
- package/excel_word/wesync/sort_rules.py +293 -0
- package/excel_word/wesync/valuefmt.py +485 -0
- package/package.json +53 -6
- package/packaging//344/275/277/347/224/250/350/257/264/346/230/216.txt +247 -0
- package/qoder_plugins/audit-toolbox/README.md +159 -0
- package/qoder_plugins/audit-toolbox/catalog.mjs +265 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""顶部文件条:选择 Word 文件、显示/选择工作簿、打开所在文件夹(长地址自动换行完整显示)。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Callable
|
|
7
|
+
|
|
8
|
+
from PySide6.QtWidgets import QGridLayout, QLabel, QPushButton, QWidget
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FileBar(QWidget):
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
parent,
|
|
15
|
+
on_pick_docx: Callable[[], None],
|
|
16
|
+
on_pick_excel: Callable[[], None],
|
|
17
|
+
on_reset_excel: Callable[[], None],
|
|
18
|
+
on_open_folder: Callable[[], None],
|
|
19
|
+
):
|
|
20
|
+
super().__init__(parent)
|
|
21
|
+
self.setObjectName("FileBar")
|
|
22
|
+
grid = QGridLayout(self)
|
|
23
|
+
grid.setContentsMargins(16, 10, 16, 10)
|
|
24
|
+
grid.setHorizontalSpacing(8)
|
|
25
|
+
grid.setVerticalSpacing(6)
|
|
26
|
+
grid.setColumnStretch(1, 1)
|
|
27
|
+
|
|
28
|
+
grid.addWidget(QLabel("Word 文件"), 0, 0)
|
|
29
|
+
self.docx_box = self._make_path_box()
|
|
30
|
+
grid.addWidget(self.docx_box, 0, 1)
|
|
31
|
+
btn = QPushButton("选择…")
|
|
32
|
+
btn.clicked.connect(lambda _checked=False: on_pick_docx())
|
|
33
|
+
grid.addWidget(btn, 0, 2)
|
|
34
|
+
btn = QPushButton("打开所在文件夹")
|
|
35
|
+
btn.clicked.connect(lambda _checked=False: on_open_folder())
|
|
36
|
+
grid.addWidget(btn, 0, 3)
|
|
37
|
+
|
|
38
|
+
grid.addWidget(QLabel("Excel 工作簿"), 1, 0)
|
|
39
|
+
self.excel_box = self._make_path_box()
|
|
40
|
+
grid.addWidget(self.excel_box, 1, 1)
|
|
41
|
+
btn = QPushButton("选择…")
|
|
42
|
+
btn.clicked.connect(lambda _checked=False: on_pick_excel())
|
|
43
|
+
grid.addWidget(btn, 1, 2)
|
|
44
|
+
btn = QPushButton("用默认名")
|
|
45
|
+
btn.clicked.connect(lambda _checked=False: on_reset_excel())
|
|
46
|
+
grid.addWidget(btn, 1, 3)
|
|
47
|
+
|
|
48
|
+
@staticmethod
|
|
49
|
+
def _make_path_box() -> QLabel:
|
|
50
|
+
box = QLabel("(未选择)")
|
|
51
|
+
box.setObjectName("PathBox")
|
|
52
|
+
box.setWordWrap(True)
|
|
53
|
+
box.setMinimumWidth(0)
|
|
54
|
+
return box
|
|
55
|
+
|
|
56
|
+
def set_paths(self, docx: Path | None, excel: Path | None) -> None:
|
|
57
|
+
self.docx_box.setText(str(docx) if docx else "(未选择)")
|
|
58
|
+
self.excel_box.setText(str(excel) if excel else "(未选择)")
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""右侧日志区:分色显示、清空/复制/保存、自动滚动开关、隐藏按钮。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import html
|
|
6
|
+
from typing import Callable
|
|
7
|
+
|
|
8
|
+
from .. import theme
|
|
9
|
+
from PySide6.QtWidgets import (
|
|
10
|
+
QCheckBox,
|
|
11
|
+
QFileDialog,
|
|
12
|
+
QHBoxLayout,
|
|
13
|
+
QLabel,
|
|
14
|
+
QMessageBox,
|
|
15
|
+
QPlainTextEdit,
|
|
16
|
+
QPushButton,
|
|
17
|
+
QVBoxLayout,
|
|
18
|
+
QWidget,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
LEVEL_TAGS = {
|
|
22
|
+
"info": ("text", False),
|
|
23
|
+
"muted": ("muted", False),
|
|
24
|
+
"ok": ("success", False),
|
|
25
|
+
"warn": ("warning", False),
|
|
26
|
+
"error": ("error", False),
|
|
27
|
+
"step": ("primary", True),
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class LogPane(QWidget):
|
|
32
|
+
def __init__(self, parent, on_hide: Callable[[], None] | None = None):
|
|
33
|
+
super().__init__(parent)
|
|
34
|
+
layout = QVBoxLayout(self)
|
|
35
|
+
layout.setContentsMargins(8, 8, 8, 8)
|
|
36
|
+
layout.setSpacing(8)
|
|
37
|
+
|
|
38
|
+
header = QHBoxLayout()
|
|
39
|
+
header.setSpacing(6)
|
|
40
|
+
title = QLabel("运行日志")
|
|
41
|
+
title.setObjectName("SectionTitle")
|
|
42
|
+
header.addWidget(title)
|
|
43
|
+
header.addStretch(1)
|
|
44
|
+
if on_hide is not None:
|
|
45
|
+
btn = QPushButton("隐藏")
|
|
46
|
+
btn.setObjectName("LogTool")
|
|
47
|
+
btn.clicked.connect(lambda _checked=False: on_hide())
|
|
48
|
+
header.addWidget(btn)
|
|
49
|
+
layout.addLayout(header)
|
|
50
|
+
|
|
51
|
+
tools = QHBoxLayout()
|
|
52
|
+
tools.setSpacing(6)
|
|
53
|
+
self.auto_scroll = QCheckBox("自动滚动")
|
|
54
|
+
self.auto_scroll.setChecked(True)
|
|
55
|
+
tools.addWidget(self.auto_scroll)
|
|
56
|
+
tools.addStretch(1)
|
|
57
|
+
for text, slot in (("复制全部", self.copy_all), ("保存…", self.save_to_file), ("清空", self.clear)):
|
|
58
|
+
btn = QPushButton(text)
|
|
59
|
+
btn.setObjectName("LogTool")
|
|
60
|
+
btn.clicked.connect(lambda _checked=False, fn=slot: fn())
|
|
61
|
+
tools.addWidget(btn)
|
|
62
|
+
layout.addLayout(tools)
|
|
63
|
+
|
|
64
|
+
self.text = QPlainTextEdit()
|
|
65
|
+
self.text.setObjectName("LogText")
|
|
66
|
+
self.text.setReadOnly(True)
|
|
67
|
+
self.text.setLineWrapMode(QPlainTextEdit.WidgetWidth)
|
|
68
|
+
layout.addWidget(self.text, 1)
|
|
69
|
+
self._entries: list[tuple[str, str]] = []
|
|
70
|
+
|
|
71
|
+
def _append_entry(self, message: str, level: str) -> None:
|
|
72
|
+
color_key, bold = LEVEL_TAGS.get(level, LEVEL_TAGS["info"])
|
|
73
|
+
color = theme.colors()[color_key]
|
|
74
|
+
body = html.escape(message).replace("\n", "<br>")
|
|
75
|
+
if bold:
|
|
76
|
+
body = f"<b>{body}</b>"
|
|
77
|
+
self.text.appendHtml(f'<span style="color:{color};">{body}</span>')
|
|
78
|
+
if self.auto_scroll.isChecked():
|
|
79
|
+
bar = self.text.verticalScrollBar()
|
|
80
|
+
bar.setValue(bar.maximum())
|
|
81
|
+
|
|
82
|
+
def append(self, message: str, level: str = "info") -> None:
|
|
83
|
+
self._entries.append((message, level))
|
|
84
|
+
self._append_entry(message, level)
|
|
85
|
+
|
|
86
|
+
def refresh_theme(self) -> None:
|
|
87
|
+
scroll = self.text.verticalScrollBar().value()
|
|
88
|
+
self.text.clear()
|
|
89
|
+
for message, level in self._entries:
|
|
90
|
+
self._append_entry(message, level)
|
|
91
|
+
if not self.auto_scroll.isChecked():
|
|
92
|
+
self.text.verticalScrollBar().setValue(scroll)
|
|
93
|
+
|
|
94
|
+
def clear(self) -> None:
|
|
95
|
+
self._entries.clear()
|
|
96
|
+
self.text.clear()
|
|
97
|
+
|
|
98
|
+
def content(self) -> str:
|
|
99
|
+
return self.text.toPlainText()
|
|
100
|
+
|
|
101
|
+
def copy_all(self) -> None:
|
|
102
|
+
text = self.content()
|
|
103
|
+
if not text.strip():
|
|
104
|
+
return
|
|
105
|
+
from PySide6.QtWidgets import QApplication
|
|
106
|
+
|
|
107
|
+
QApplication.clipboard().setText(text)
|
|
108
|
+
QMessageBox.information(self, "复制成功", "日志已复制到剪贴板。")
|
|
109
|
+
|
|
110
|
+
def save_to_file(self) -> None:
|
|
111
|
+
text = self.content()
|
|
112
|
+
if not text.strip():
|
|
113
|
+
QMessageBox.information(self, "没有日志", "当前没有可保存的日志内容。")
|
|
114
|
+
return
|
|
115
|
+
path, _ = QFileDialog.getSaveFileName(
|
|
116
|
+
self, "保存运行日志", "运行日志.txt", "文本文件 (*.txt);;所有文件 (*.*)"
|
|
117
|
+
)
|
|
118
|
+
if not path:
|
|
119
|
+
return
|
|
120
|
+
try:
|
|
121
|
+
with open(path, "w", encoding="utf-8") as handle:
|
|
122
|
+
handle.write(text + "\n")
|
|
123
|
+
except OSError as exc:
|
|
124
|
+
QMessageBox.critical(self, "保存失败", f"写入文件失败:{exc}")
|
|
125
|
+
return
|
|
126
|
+
QMessageBox.information(self, "保存成功", f"日志已保存到:\n{path}")
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"""左侧导航:图标、分组折叠、整栏折叠与当前项高亮。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from functools import lru_cache
|
|
6
|
+
from typing import Callable
|
|
7
|
+
|
|
8
|
+
from PySide6.QtCore import QEasingCurve, QPoint, QPropertyAnimation, QRect, QRectF, QSize, Qt, Signal, QTimer
|
|
9
|
+
from PySide6.QtGui import QColor, QIcon, QPainter, QPen, QPixmap
|
|
10
|
+
from PySide6.QtWidgets import QPushButton, QVBoxLayout, QWidget
|
|
11
|
+
|
|
12
|
+
from .. import theme
|
|
13
|
+
from ..resources import icon_path
|
|
14
|
+
|
|
15
|
+
EXPANDED_WIDTH = 224
|
|
16
|
+
COLLAPSED_WIDTH = 68
|
|
17
|
+
|
|
18
|
+
_ICON_KINDS = {
|
|
19
|
+
"ExportPage": "table",
|
|
20
|
+
"WritebackPage": "document",
|
|
21
|
+
"MarksPage": "chart",
|
|
22
|
+
"BatchPage": "list",
|
|
23
|
+
"BlankPage": "grid",
|
|
24
|
+
"FormatPage": "text",
|
|
25
|
+
"BookmarkPage": "bookmark",
|
|
26
|
+
"HistoryPage": "history",
|
|
27
|
+
"AiPage": "spark",
|
|
28
|
+
"SettingsPage": "settings",
|
|
29
|
+
"FeedbackPage": "message",
|
|
30
|
+
"HelpPage": "help",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@lru_cache(maxsize=None)
|
|
35
|
+
def _nav_icon(key: str, active: bool = False, mode: str = "light") -> QIcon:
|
|
36
|
+
kind = _ICON_KINDS.get(key, "document")
|
|
37
|
+
c = theme.colors(mode)
|
|
38
|
+
color = QColor(c["primary"] if active else c["muted"])
|
|
39
|
+
pixmap = QPixmap(36, 36)
|
|
40
|
+
pixmap.fill(Qt.transparent)
|
|
41
|
+
painter = QPainter(pixmap)
|
|
42
|
+
painter.setRenderHint(QPainter.Antialiasing)
|
|
43
|
+
pen = QPen(color, 2.2)
|
|
44
|
+
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
|
45
|
+
pen.setJoinStyle(Qt.PenJoinStyle.RoundJoin)
|
|
46
|
+
painter.setPen(pen)
|
|
47
|
+
painter.setBrush(Qt.NoBrush)
|
|
48
|
+
_draw_icon(painter, kind)
|
|
49
|
+
painter.end()
|
|
50
|
+
return QIcon(pixmap)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _draw_icon(painter: QPainter, kind: str) -> None:
|
|
54
|
+
if kind in {"table", "grid"}:
|
|
55
|
+
painter.drawRoundedRect(QRectF(5, 6, 26, 24), 2, 2)
|
|
56
|
+
painter.drawLine(18, 6, 18, 30)
|
|
57
|
+
painter.drawLine(5, 15, 31, 15)
|
|
58
|
+
if kind == "grid":
|
|
59
|
+
painter.drawLine(5, 22, 31, 22)
|
|
60
|
+
elif kind == "document":
|
|
61
|
+
painter.drawRoundedRect(QRectF(7, 4, 22, 28), 2, 2)
|
|
62
|
+
painter.drawLine(12, 12, 24, 12)
|
|
63
|
+
painter.drawLine(12, 18, 24, 18)
|
|
64
|
+
painter.drawLine(12, 24, 21, 24)
|
|
65
|
+
elif kind == "chart":
|
|
66
|
+
painter.drawLine(7, 29, 30, 29)
|
|
67
|
+
painter.drawLine(7, 29, 7, 7)
|
|
68
|
+
painter.drawPolyline([QPoint(11, 23), QPoint(17, 17), QPoint(22, 20), QPoint(29, 10)])
|
|
69
|
+
elif kind == "list":
|
|
70
|
+
for y in (11, 18, 25):
|
|
71
|
+
painter.drawEllipse(QPoint(9, y), 1.5, 1.5)
|
|
72
|
+
painter.drawLine(15, y, 29, y)
|
|
73
|
+
elif kind == "text":
|
|
74
|
+
painter.drawLine(6, 11, 30, 11)
|
|
75
|
+
painter.drawLine(6, 18, 25, 18)
|
|
76
|
+
painter.drawLine(6, 25, 29, 25)
|
|
77
|
+
elif kind == "bookmark":
|
|
78
|
+
painter.drawPolyline([QPoint(9, 7), QPoint(27, 7), QPoint(27, 30), QPoint(18, 24), QPoint(9, 30), QPoint(9, 7)])
|
|
79
|
+
elif kind == "history":
|
|
80
|
+
painter.drawArc(QRectF(7, 7, 22, 22), 35, 275)
|
|
81
|
+
painter.drawPolyline([QPoint(8, 8), QPoint(8, 14), QPoint(14, 14)])
|
|
82
|
+
painter.drawLine(18, 14, 18, 20)
|
|
83
|
+
painter.drawLine(18, 20, 23, 23)
|
|
84
|
+
elif kind == "settings":
|
|
85
|
+
painter.drawEllipse(QRectF(12, 12, 12, 12))
|
|
86
|
+
painter.drawArc(QRectF(8, 8, 20, 20), 0, 360)
|
|
87
|
+
for x, y in ((18, 3), (18, 33), (3, 18), (33, 18), (8, 8), (28, 28), (28, 8), (8, 28)):
|
|
88
|
+
painter.drawLine(18, 18, x, y)
|
|
89
|
+
elif kind == "message":
|
|
90
|
+
painter.drawRoundedRect(QRectF(5, 7, 26, 20), 4, 4)
|
|
91
|
+
painter.drawPolyline([QPoint(12, 27), QPoint(12, 32), QPoint(19, 27)])
|
|
92
|
+
painter.drawLine(11, 14, 25, 14)
|
|
93
|
+
painter.drawLine(11, 20, 22, 20)
|
|
94
|
+
elif kind == "spark":
|
|
95
|
+
painter.drawPolyline([QPoint(18, 5), QPoint(21, 15), QPoint(31, 18), QPoint(21, 21), QPoint(18, 31), QPoint(15, 21), QPoint(5, 18), QPoint(15, 15), QPoint(18, 5)])
|
|
96
|
+
elif kind == "chat":
|
|
97
|
+
painter.drawRoundedRect(QRect(5, 7, 26, 19), 5, 5)
|
|
98
|
+
painter.drawPolyline([QPoint(12, 26), QPoint(11, 32), QPoint(19, 26)])
|
|
99
|
+
elif kind == "help":
|
|
100
|
+
painter.drawEllipse(QRectF(5, 5, 26, 26))
|
|
101
|
+
font = painter.font()
|
|
102
|
+
font.setPixelSize(19)
|
|
103
|
+
font.setBold(True)
|
|
104
|
+
painter.setFont(font)
|
|
105
|
+
painter.drawText(QRectF(5, 4, 26, 26), int(Qt.AlignmentFlag.AlignCenter), "?")
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class NavBar(QWidget):
|
|
109
|
+
collapse_toggled = Signal(bool)
|
|
110
|
+
|
|
111
|
+
def __init__(self, parent, on_select: Callable[[str], None]):
|
|
112
|
+
super().__init__(parent)
|
|
113
|
+
self.setObjectName("Nav")
|
|
114
|
+
self.setProperty("collapsed", False)
|
|
115
|
+
self.setMinimumWidth(COLLAPSED_WIDTH)
|
|
116
|
+
self._on_select = on_select
|
|
117
|
+
self._buttons: dict[str, QPushButton] = {}
|
|
118
|
+
self._item_labels: dict[str, str] = {}
|
|
119
|
+
self._item_groups: dict[str, str] = {}
|
|
120
|
+
self._groups: dict[str, dict] = {}
|
|
121
|
+
self._collapsed = False
|
|
122
|
+
self._selected_key = ""
|
|
123
|
+
self._indicator_ready = False
|
|
124
|
+
|
|
125
|
+
layout = QVBoxLayout(self)
|
|
126
|
+
layout.setContentsMargins(10, 10, 10, 10)
|
|
127
|
+
layout.setSpacing(4)
|
|
128
|
+
self._brand_button = QPushButton()
|
|
129
|
+
self._brand_button.setObjectName("NavBrand")
|
|
130
|
+
self._brand_button.setIcon(QIcon(str(icon_path())))
|
|
131
|
+
self._brand_button.setIconSize(QSize(24, 24))
|
|
132
|
+
self._brand_button.setFixedHeight(32)
|
|
133
|
+
self._brand_button.setCursor(Qt.PointingHandCursor)
|
|
134
|
+
self._brand_button.clicked.connect(lambda: self.collapse_toggled.emit(not self._collapsed))
|
|
135
|
+
layout.addWidget(self._brand_button)
|
|
136
|
+
|
|
137
|
+
self._body = QVBoxLayout()
|
|
138
|
+
self._body.setSpacing(3)
|
|
139
|
+
layout.addLayout(self._body)
|
|
140
|
+
layout.addStretch(1)
|
|
141
|
+
|
|
142
|
+
self._indicator = QWidget(self)
|
|
143
|
+
self._indicator.setObjectName("NavIndicator")
|
|
144
|
+
self._indicator.setAttribute(Qt.WA_TransparentForMouseEvents)
|
|
145
|
+
self._indicator.hide()
|
|
146
|
+
self._indicator_animation = QPropertyAnimation(self._indicator, b"geometry", self)
|
|
147
|
+
self._indicator_animation.setDuration(180)
|
|
148
|
+
self._indicator_animation.setEasingCurve(QEasingCurve.Type.OutCubic)
|
|
149
|
+
self.set_collapsed(False)
|
|
150
|
+
|
|
151
|
+
@property
|
|
152
|
+
def collapsed(self) -> bool:
|
|
153
|
+
return self._collapsed
|
|
154
|
+
|
|
155
|
+
def add_group(self, title: str, key: str) -> None:
|
|
156
|
+
"""添加一个默认展开的导航分组。"""
|
|
157
|
+
if not key:
|
|
158
|
+
raise ValueError("导航分组 key 不能为空")
|
|
159
|
+
if key in self._groups:
|
|
160
|
+
raise ValueError(f"导航分组已存在:{key}")
|
|
161
|
+
|
|
162
|
+
button = QPushButton()
|
|
163
|
+
button.setObjectName("NavGroup")
|
|
164
|
+
button.setCheckable(True)
|
|
165
|
+
button.setChecked(True)
|
|
166
|
+
button.setCursor(Qt.PointingHandCursor)
|
|
167
|
+
button.clicked.connect(
|
|
168
|
+
lambda _checked=False, k=key: self._set_group_expanded(k, not self._groups[k]["expanded"])
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
contents = QWidget()
|
|
172
|
+
contents.setObjectName("NavGroupItems")
|
|
173
|
+
item_layout = QVBoxLayout(contents)
|
|
174
|
+
item_layout.setContentsMargins(0, 0, 0, 2)
|
|
175
|
+
item_layout.setSpacing(1)
|
|
176
|
+
|
|
177
|
+
self._body.addWidget(button)
|
|
178
|
+
self._body.addWidget(contents)
|
|
179
|
+
self._groups[key] = {
|
|
180
|
+
"title": title,
|
|
181
|
+
"button": button,
|
|
182
|
+
"contents": contents,
|
|
183
|
+
"layout": item_layout,
|
|
184
|
+
"expanded": True,
|
|
185
|
+
}
|
|
186
|
+
self._set_group_expanded(key, True)
|
|
187
|
+
|
|
188
|
+
def add_item(self, key: str, text: str, group: str = "") -> None:
|
|
189
|
+
"""添加导航项;不传 group 时保持原有的平铺行为。"""
|
|
190
|
+
if key in self._buttons:
|
|
191
|
+
raise ValueError(f"导航项已存在:{key}")
|
|
192
|
+
if group and group not in self._groups:
|
|
193
|
+
raise ValueError(f"导航分组不存在:{group}")
|
|
194
|
+
|
|
195
|
+
button = QPushButton(text)
|
|
196
|
+
button.setObjectName("Nav")
|
|
197
|
+
button.setCheckable(True)
|
|
198
|
+
button.setCursor(Qt.PointingHandCursor)
|
|
199
|
+
button.setIcon(_nav_icon(key, mode=theme.effective_mode()))
|
|
200
|
+
button.setIconSize(QSize(18, 18))
|
|
201
|
+
button.clicked.connect(lambda _checked=False, k=key: self._on_select(k))
|
|
202
|
+
if group:
|
|
203
|
+
self._groups[group]["layout"].addWidget(button)
|
|
204
|
+
else:
|
|
205
|
+
self._body.addWidget(button)
|
|
206
|
+
self._buttons[key] = button
|
|
207
|
+
self._item_labels[key] = text
|
|
208
|
+
self._item_groups[key] = group
|
|
209
|
+
|
|
210
|
+
def set_collapsed(self, collapsed: bool) -> None:
|
|
211
|
+
self._collapsed = bool(collapsed)
|
|
212
|
+
self.setProperty("collapsed", self._collapsed)
|
|
213
|
+
self.style().unpolish(self)
|
|
214
|
+
self.style().polish(self)
|
|
215
|
+
self._brand_button.setText("" if self._collapsed else "审计工具箱 ‹")
|
|
216
|
+
self._brand_button.setToolTip("展开侧栏" if self._collapsed else "折叠侧栏")
|
|
217
|
+
if self._collapsed:
|
|
218
|
+
self._brand_button.setFixedSize(48, 32)
|
|
219
|
+
else:
|
|
220
|
+
self._brand_button.setMinimumWidth(0)
|
|
221
|
+
self._brand_button.setMaximumWidth(16777215)
|
|
222
|
+
self._brand_button.setFixedHeight(32)
|
|
223
|
+
for key, button in self._buttons.items():
|
|
224
|
+
button.setText("" if self._collapsed else self._item_labels[key])
|
|
225
|
+
button.setToolTip(self._item_labels[key] if self._collapsed else "")
|
|
226
|
+
if self._collapsed:
|
|
227
|
+
button.setFixedSize(46, 32)
|
|
228
|
+
else:
|
|
229
|
+
button.setMinimumSize(0, 32)
|
|
230
|
+
button.setMaximumSize(16777215, 32)
|
|
231
|
+
for group in self._groups.values():
|
|
232
|
+
group["button"].setVisible(not self._collapsed)
|
|
233
|
+
self.layout().activate()
|
|
234
|
+
self._move_indicator(animate=False)
|
|
235
|
+
QTimer.singleShot(0, lambda: self._move_indicator(animate=False))
|
|
236
|
+
|
|
237
|
+
def _set_group_expanded(self, key: str, expanded: bool) -> None:
|
|
238
|
+
group = self._groups[key]
|
|
239
|
+
group["expanded"] = bool(expanded)
|
|
240
|
+
group["contents"].setVisible(group["expanded"])
|
|
241
|
+
group["button"].setChecked(group["expanded"])
|
|
242
|
+
group["button"].setText(f"{'▾' if group['expanded'] else '▸'} {group['title']}")
|
|
243
|
+
self.layout().activate()
|
|
244
|
+
self._move_indicator(animate=False)
|
|
245
|
+
QTimer.singleShot(0, lambda: self._move_indicator(animate=False))
|
|
246
|
+
|
|
247
|
+
def group_states(self) -> dict[str, bool]:
|
|
248
|
+
"""返回各分组的展开状态,True 表示展开。"""
|
|
249
|
+
return {key: bool(group["expanded"]) for key, group in self._groups.items()}
|
|
250
|
+
|
|
251
|
+
def set_group_states(self, states: dict[str, bool]) -> None:
|
|
252
|
+
"""恢复主窗口持久化的分组展开状态。"""
|
|
253
|
+
for key, expanded in states.items():
|
|
254
|
+
if key in self._groups:
|
|
255
|
+
self._set_group_expanded(key, bool(expanded))
|
|
256
|
+
|
|
257
|
+
def select(self, key: str) -> None:
|
|
258
|
+
self._selected_key = key
|
|
259
|
+
for item_key, button in self._buttons.items():
|
|
260
|
+
selected = item_key == key
|
|
261
|
+
button.setChecked(selected)
|
|
262
|
+
button.setIcon(_nav_icon(item_key, selected, theme.effective_mode()))
|
|
263
|
+
group_key = self._item_groups.get(key, "")
|
|
264
|
+
if group_key and not self._groups[group_key]["expanded"]:
|
|
265
|
+
self._set_group_expanded(group_key, True)
|
|
266
|
+
QTimer.singleShot(0, lambda: self._move_indicator(animate=True))
|
|
267
|
+
|
|
268
|
+
def refresh_theme(self) -> None:
|
|
269
|
+
mode = theme.effective_mode()
|
|
270
|
+
for key, button in self._buttons.items():
|
|
271
|
+
button.setIcon(_nav_icon(key, key == self._selected_key, mode))
|
|
272
|
+
|
|
273
|
+
def _move_indicator(self, *, animate: bool) -> None:
|
|
274
|
+
button = self._buttons.get(self._selected_key)
|
|
275
|
+
if button is None or not button.isVisible():
|
|
276
|
+
self._indicator.hide()
|
|
277
|
+
return
|
|
278
|
+
position = button.mapTo(self, QPoint(0, 0))
|
|
279
|
+
target = QRect(12 if not self._collapsed else 0, position.y() + 9, 3, max(8, button.height() - 18))
|
|
280
|
+
self._indicator.raise_()
|
|
281
|
+
if animate and self._indicator_ready and self._indicator.isVisible():
|
|
282
|
+
self._indicator_animation.stop()
|
|
283
|
+
self._indicator_animation.setStartValue(self._indicator.geometry())
|
|
284
|
+
self._indicator_animation.setEndValue(target)
|
|
285
|
+
self._indicator_animation.start()
|
|
286
|
+
else:
|
|
287
|
+
self._indicator_animation.stop()
|
|
288
|
+
self._indicator.setGeometry(target)
|
|
289
|
+
self._indicator.show()
|
|
290
|
+
self._indicator_ready = True
|
|
291
|
+
|
|
292
|
+
def showEvent(self, event) -> None:
|
|
293
|
+
super().showEvent(event)
|
|
294
|
+
QTimer.singleShot(0, lambda: self._move_indicator(animate=False))
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""首次启动的主题选择对话框。
|
|
2
|
+
|
|
3
|
+
只在用户**从未选过**主题时弹出一次(.wesync_ui.json 里没有 appearance 键),
|
|
4
|
+
选完即写入偏好,之后不再打扰。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from PySide6.QtCore import Qt
|
|
10
|
+
from PySide6.QtWidgets import (
|
|
11
|
+
QDialog,
|
|
12
|
+
QHBoxLayout,
|
|
13
|
+
QLabel,
|
|
14
|
+
QPushButton,
|
|
15
|
+
QVBoxLayout,
|
|
16
|
+
QWidget,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from .. import theme
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ThemeChoiceDialog(QDialog):
|
|
23
|
+
"""深色 / 浅色 / 跟随系统 三选一。"""
|
|
24
|
+
|
|
25
|
+
OPTIONS = (
|
|
26
|
+
("dark", "深色", "夜间与暗光环境更舒适"),
|
|
27
|
+
("light", "浅色", "白天与明亮环境更清晰"),
|
|
28
|
+
("system", "跟随系统", "随 Windows 深浅色自动切换"),
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def __init__(self, parent=None, *, current: str = "dark") -> None:
|
|
32
|
+
super().__init__(parent)
|
|
33
|
+
self.setWindowTitle("选择界面外观")
|
|
34
|
+
self.setModal(True)
|
|
35
|
+
self.setMinimumWidth(430)
|
|
36
|
+
self._chosen = theme.normalize_mode(current)
|
|
37
|
+
|
|
38
|
+
layout = QVBoxLayout(self)
|
|
39
|
+
layout.setContentsMargins(24, 20, 24, 18)
|
|
40
|
+
layout.setSpacing(14)
|
|
41
|
+
|
|
42
|
+
title = QLabel("首次使用,先选一个界面外观")
|
|
43
|
+
title.setObjectName("DialogTitle")
|
|
44
|
+
layout.addWidget(title)
|
|
45
|
+
|
|
46
|
+
note = QLabel("之后可随时在「全局设置 → 界面外观」里修改。")
|
|
47
|
+
note.setObjectName("CardDesc")
|
|
48
|
+
note.setWordWrap(True)
|
|
49
|
+
layout.addWidget(note)
|
|
50
|
+
|
|
51
|
+
self._buttons: dict[str, QPushButton] = {}
|
|
52
|
+
row = QHBoxLayout()
|
|
53
|
+
row.setSpacing(10)
|
|
54
|
+
for mode, label, hint in self.OPTIONS:
|
|
55
|
+
button = QPushButton(f"{label}\n{hint}")
|
|
56
|
+
button.setObjectName("ThemeOption")
|
|
57
|
+
button.setCheckable(True)
|
|
58
|
+
button.setCursor(Qt.PointingHandCursor)
|
|
59
|
+
button.setMinimumHeight(74)
|
|
60
|
+
button.clicked.connect(lambda _c=False, m=mode: self._choose(m))
|
|
61
|
+
row.addWidget(button)
|
|
62
|
+
self._buttons[mode] = button
|
|
63
|
+
layout.addLayout(row)
|
|
64
|
+
|
|
65
|
+
footer = QHBoxLayout()
|
|
66
|
+
footer.addStretch(1)
|
|
67
|
+
confirm = QPushButton("确定")
|
|
68
|
+
confirm.setObjectName("Primary")
|
|
69
|
+
confirm.setDefault(True)
|
|
70
|
+
confirm.clicked.connect(self.accept)
|
|
71
|
+
footer.addWidget(confirm)
|
|
72
|
+
layout.addLayout(footer)
|
|
73
|
+
|
|
74
|
+
self._choose(self._chosen)
|
|
75
|
+
|
|
76
|
+
def _choose(self, mode: str) -> None:
|
|
77
|
+
self._chosen = theme.normalize_mode(mode)
|
|
78
|
+
for key, button in self._buttons.items():
|
|
79
|
+
button.setChecked(key == self._chosen)
|
|
80
|
+
|
|
81
|
+
def chosen(self) -> str:
|
|
82
|
+
return self._chosen
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def needs_choice(settings: dict) -> bool:
|
|
86
|
+
"""是否需要弹首次选择:只看配置里有没有 appearance 键。
|
|
87
|
+
|
|
88
|
+
用户手动选过(哪怕选的就是 system)就不再问;老用户升级上来
|
|
89
|
+
若原本没有该键,会问一次,属于预期行为。
|
|
90
|
+
"""
|
|
91
|
+
if not isinstance(settings, dict):
|
|
92
|
+
return True
|
|
93
|
+
return "appearance" not in settings
|