audit-e2w 0.0.0-stage → 1.11.2
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 +147 -2
- package/cordis.patch.yml +3 -0
- package/dsh_plugins/audit-e2w/lib/engine.mjs +174 -0
- package/dsh_plugins/audit-e2w/lib/index.js +114 -0
- package/dsh_plugins/audit-e2w/lib/skill.js +41 -0
- package/excel_word/README.md +380 -0
- package/excel_word/qoder_engine.py +438 -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/align.py +154 -0
- package/excel_word/wesync/api.py +840 -0
- package/excel_word/wesync/backup_history.py +65 -0
- package/excel_word/wesync/changelog.py +58 -0
- package/excel_word/wesync/cli.py +173 -0
- package/excel_word/wesync/commands/__init__.py +8 -0
- package/excel_word/wesync/commands/blank_cmd.py +250 -0
- package/excel_word/wesync/commands/bookmark_cmd.py +115 -0
- package/excel_word/wesync/commands/clear_cmd.py +48 -0
- package/excel_word/wesync/commands/export_cmd.py +220 -0
- package/excel_word/wesync/commands/marks_cmd.py +152 -0
- package/excel_word/wesync/commands/placeholders_cmd.py +87 -0
- package/excel_word/wesync/commands/writeback_cmd.py +513 -0
- package/excel_word/wesync/config.py +96 -0
- package/excel_word/wesync/console.py +78 -0
- package/excel_word/wesync/docx_blank.py +156 -0
- package/excel_word/wesync/docx_bookmarks.py +287 -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 +291 -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 +161 -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 +543 -0
- package/excel_word/wesync/excel_export.py +136 -0
- package/excel_word/wesync/excel_marks.py +193 -0
- package/excel_word/wesync/excel_totals.py +53 -0
- package/excel_word/wesync/fsops.py +214 -0
- package/excel_word/wesync/gui/__init__.py +34 -0
- package/excel_word/wesync/gui/__main__.py +6 -0
- package/excel_word/wesync/gui/app.py +399 -0
- package/excel_word/wesync/gui/manual.py +68 -0
- package/excel_word/wesync/gui/pages/__init__.py +31 -0
- package/excel_word/wesync/gui/pages/_page.py +89 -0
- package/excel_word/wesync/gui/pages/batch_page.py +423 -0
- package/excel_word/wesync/gui/pages/blank_page.py +465 -0
- package/excel_word/wesync/gui/pages/bookmark_page.py +37 -0
- package/excel_word/wesync/gui/pages/export_page.py +88 -0
- package/excel_word/wesync/gui/pages/format_page.py +429 -0
- package/excel_word/wesync/gui/pages/help_page.py +92 -0
- package/excel_word/wesync/gui/pages/history_page.py +145 -0
- package/excel_word/wesync/gui/pages/marks_page.py +178 -0
- package/excel_word/wesync/gui/pages/writeback_page.py +452 -0
- package/excel_word/wesync/gui/resources.py +22 -0
- package/excel_word/wesync/gui/runner.py +74 -0
- package/excel_word/wesync/gui/store.py +34 -0
- package/excel_word/wesync/gui/theme.py +100 -0
- package/excel_word/wesync/gui/widgets/__init__.py +8 -0
- package/excel_word/wesync/gui/widgets/cards.py +20 -0
- package/excel_word/wesync/gui/widgets/filebar.py +58 -0
- package/excel_word/wesync/gui/widgets/logpane.py +110 -0
- package/excel_word/wesync/gui/widgets/nav.py +39 -0
- package/excel_word/wesync/report_format.py +1577 -0
- package/excel_word/wesync/sort_rules.py +244 -0
- package/excel_word/wesync/valuefmt.py +462 -0
- package/package.json +49 -4
- package/qoder_plugins/audit-toolbox/README.md +156 -0
- package/qoder_plugins/audit-toolbox/catalog.mjs +265 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
"""主窗口:左侧导航 + 顶部文件条 + 中间页面 + 右侧可隐藏日志 + 状态栏。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import subprocess
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from PySide6.QtCore import Qt, QTimer
|
|
11
|
+
from PySide6.QtGui import QIcon, QKeySequence, QShortcut
|
|
12
|
+
from PySide6.QtWidgets import (
|
|
13
|
+
QApplication,
|
|
14
|
+
QFileDialog,
|
|
15
|
+
QLabel,
|
|
16
|
+
QMainWindow,
|
|
17
|
+
QMessageBox,
|
|
18
|
+
QProgressBar,
|
|
19
|
+
QPushButton,
|
|
20
|
+
QSplitter,
|
|
21
|
+
QStackedWidget,
|
|
22
|
+
QVBoxLayout,
|
|
23
|
+
QWidget,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from .. import api
|
|
27
|
+
from ..errors import SyncError
|
|
28
|
+
from ..fsops import find_default_docx
|
|
29
|
+
from . import store
|
|
30
|
+
from .pages import iter_pages
|
|
31
|
+
from .resources import icon_path
|
|
32
|
+
from .runner import TaskRunner
|
|
33
|
+
from .widgets.filebar import FileBar
|
|
34
|
+
from .widgets.logpane import LogPane
|
|
35
|
+
from .widgets.nav import NavBar
|
|
36
|
+
|
|
37
|
+
DEFAULT_SIZE = (1100, 640)
|
|
38
|
+
MIN_SIZE = (1080, 560)
|
|
39
|
+
DEFAULT_LOG_WIDTH = 320
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class UiContext:
|
|
43
|
+
"""页面与主窗口之间的桥梁:文件状态、日志、弹窗、任务执行。"""
|
|
44
|
+
|
|
45
|
+
def __init__(self, app: "WesyncApp") -> None:
|
|
46
|
+
self._app = app
|
|
47
|
+
|
|
48
|
+
# ---------- 文件 ----------
|
|
49
|
+
@property
|
|
50
|
+
def docx(self) -> Path | None:
|
|
51
|
+
return self._app.docx_path
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def excel(self) -> Path | None:
|
|
55
|
+
return self._app.excel_path
|
|
56
|
+
|
|
57
|
+
def workbook_path(self) -> Path:
|
|
58
|
+
if self._app.docx_path is None:
|
|
59
|
+
return Path("")
|
|
60
|
+
return api.workbook_path(self._app.docx_path, self._app.excel_path)
|
|
61
|
+
|
|
62
|
+
def require_docx(self) -> bool:
|
|
63
|
+
if self._app.docx_path is None:
|
|
64
|
+
self.error("未选择文件", "请先在顶部选择要处理的 Word 文件。")
|
|
65
|
+
return False
|
|
66
|
+
if not Path(self._app.docx_path).exists():
|
|
67
|
+
self.error("文件不存在", f"找不到 Word 文件:\n{self._app.docx_path}")
|
|
68
|
+
return False
|
|
69
|
+
return True
|
|
70
|
+
|
|
71
|
+
def set_docx(self, path: Path) -> None:
|
|
72
|
+
self._app.set_docx(Path(path))
|
|
73
|
+
|
|
74
|
+
def set_excel(self, path: Path | None) -> None:
|
|
75
|
+
self._app.set_excel(None if path is None else Path(path))
|
|
76
|
+
|
|
77
|
+
# ---------- 日志与状态 ----------
|
|
78
|
+
def log(self, text: str, level: str = "info") -> None:
|
|
79
|
+
self._app.append_log(text, level)
|
|
80
|
+
|
|
81
|
+
def set_status(self, text: str) -> None:
|
|
82
|
+
self._app.set_status(text)
|
|
83
|
+
|
|
84
|
+
# ---------- 弹窗 ----------
|
|
85
|
+
def confirm(self, title: str, message: str) -> bool:
|
|
86
|
+
box = QMessageBox(self._app)
|
|
87
|
+
box.setIcon(QMessageBox.Question)
|
|
88
|
+
box.setWindowTitle(title)
|
|
89
|
+
box.setText(message)
|
|
90
|
+
box.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
|
|
91
|
+
box.button(QMessageBox.Ok).setText("确定")
|
|
92
|
+
box.button(QMessageBox.Cancel).setText("取消")
|
|
93
|
+
return box.exec() == QMessageBox.Ok
|
|
94
|
+
|
|
95
|
+
def info(self, title: str, message: str) -> None:
|
|
96
|
+
QMessageBox.information(self._app, title, message)
|
|
97
|
+
|
|
98
|
+
def error(self, title: str, message: str, log: bool = True) -> None:
|
|
99
|
+
if log:
|
|
100
|
+
self._app.append_log(f"错误:{message}", "error")
|
|
101
|
+
QMessageBox.critical(self._app, title, message)
|
|
102
|
+
|
|
103
|
+
def open_folder(self) -> None:
|
|
104
|
+
self._app.open_folder()
|
|
105
|
+
|
|
106
|
+
# ---------- 任务 ----------
|
|
107
|
+
@property
|
|
108
|
+
def busy(self) -> bool:
|
|
109
|
+
return self._app.runner.busy
|
|
110
|
+
|
|
111
|
+
def run_steps(self, steps) -> bool:
|
|
112
|
+
if self._app.runner.busy:
|
|
113
|
+
self.log("已有任务在执行,请等待完成后再操作。", "warn")
|
|
114
|
+
return False
|
|
115
|
+
started = self._app.runner.submit(steps)
|
|
116
|
+
if started:
|
|
117
|
+
self._app.set_busy(True)
|
|
118
|
+
return started
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class WesyncApp(QMainWindow):
|
|
122
|
+
"""界面主窗口。"""
|
|
123
|
+
|
|
124
|
+
def __init__(self, base_dir: Path | None = None) -> None:
|
|
125
|
+
super().__init__()
|
|
126
|
+
self.base_dir = Path(base_dir) if base_dir else Path(__file__).resolve().parents[2]
|
|
127
|
+
self.settings = store.load()
|
|
128
|
+
self.docx_path: Path | None = None
|
|
129
|
+
self.excel_path: Path | None = None
|
|
130
|
+
self.excel_is_custom = False
|
|
131
|
+
self.runner = TaskRunner()
|
|
132
|
+
self.ctx = UiContext(self)
|
|
133
|
+
self._pages: dict[str, QWidget] = {}
|
|
134
|
+
|
|
135
|
+
self.setWindowTitle("审计工具箱")
|
|
136
|
+
self.setWindowIcon(QIcon(str(icon_path())))
|
|
137
|
+
size = self.settings.get("qt_size") or list(DEFAULT_SIZE)
|
|
138
|
+
self.resize(int(size[0]), int(size[1]))
|
|
139
|
+
pos = self.settings.get("qt_pos")
|
|
140
|
+
if pos:
|
|
141
|
+
self.move(int(pos[0]), int(pos[1]))
|
|
142
|
+
self.setMinimumSize(*MIN_SIZE)
|
|
143
|
+
|
|
144
|
+
self._build_layout()
|
|
145
|
+
self._load_initial_paths()
|
|
146
|
+
self._select_page(next(iter(self._pages)))
|
|
147
|
+
self._help_shortcut = QShortcut(QKeySequence("F1"), self)
|
|
148
|
+
self._help_shortcut.activated.connect(lambda: self._select_page("HelpPage"))
|
|
149
|
+
QTimer(self, timeout=self._poll_queue, interval=120).start()
|
|
150
|
+
|
|
151
|
+
# ------------------------------------------------------------------ 布局
|
|
152
|
+
|
|
153
|
+
def _build_layout(self) -> None:
|
|
154
|
+
central = QWidget()
|
|
155
|
+
self.setCentralWidget(central)
|
|
156
|
+
layout = QVBoxLayout(central)
|
|
157
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
158
|
+
layout.setSpacing(0)
|
|
159
|
+
|
|
160
|
+
self.filebar = FileBar(
|
|
161
|
+
central,
|
|
162
|
+
on_pick_docx=self.pick_docx,
|
|
163
|
+
on_pick_excel=self.pick_excel,
|
|
164
|
+
on_reset_excel=self.reset_excel,
|
|
165
|
+
on_open_folder=self.open_folder,
|
|
166
|
+
)
|
|
167
|
+
layout.addWidget(self.filebar)
|
|
168
|
+
|
|
169
|
+
self.splitter = QSplitter(Qt.Horizontal)
|
|
170
|
+
self.nav = NavBar(self.splitter, self._select_page)
|
|
171
|
+
self.stack = QStackedWidget()
|
|
172
|
+
self.logpane = LogPane(self.splitter, on_hide=lambda: self.set_log_visible(False))
|
|
173
|
+
self.splitter.addWidget(self.nav)
|
|
174
|
+
self.splitter.addWidget(self.stack)
|
|
175
|
+
self.splitter.addWidget(self.logpane)
|
|
176
|
+
self.splitter.setStretchFactor(0, 0)
|
|
177
|
+
self.splitter.setStretchFactor(1, 1)
|
|
178
|
+
self.splitter.setStretchFactor(2, 0)
|
|
179
|
+
self.splitter.setCollapsible(0, False)
|
|
180
|
+
self.splitter.setCollapsible(2, False)
|
|
181
|
+
log_width = int(self.settings.get("log_width") or DEFAULT_LOG_WIDTH)
|
|
182
|
+
# 首次布局会按 sizeHint 重分宽度,等布局生效后再按设定值分配
|
|
183
|
+
QTimer.singleShot(0, lambda: self._apply_splitter_sizes(log_width))
|
|
184
|
+
layout.addWidget(self.splitter, 1)
|
|
185
|
+
|
|
186
|
+
for page_class in iter_pages():
|
|
187
|
+
page = page_class(self.ctx)
|
|
188
|
+
key = page_class.__name__
|
|
189
|
+
self._pages[key] = page
|
|
190
|
+
self.stack.addWidget(page)
|
|
191
|
+
self.nav.add_item(key, getattr(page, "title", key))
|
|
192
|
+
|
|
193
|
+
self._status_label = QLabel("就绪")
|
|
194
|
+
self._status_label.setObjectName("Status")
|
|
195
|
+
self.statusBar().addWidget(self._status_label, 1)
|
|
196
|
+
self._toggle_log_btn = QPushButton("隐藏日志")
|
|
197
|
+
self._toggle_log_btn.clicked.connect(lambda _checked=False: self.set_log_visible(not self.logpane.isVisible()))
|
|
198
|
+
self.statusBar().addPermanentWidget(self._toggle_log_btn)
|
|
199
|
+
self._progress = QProgressBar()
|
|
200
|
+
self._progress.setFixedWidth(150)
|
|
201
|
+
self._progress.setRange(0, 100)
|
|
202
|
+
self._progress.setValue(0)
|
|
203
|
+
self._progress.setTextVisible(False)
|
|
204
|
+
self.statusBar().addPermanentWidget(self._progress)
|
|
205
|
+
self.set_log_visible(bool(self.settings.get("log_visible", True)))
|
|
206
|
+
|
|
207
|
+
def _apply_splitter_sizes(self, log_width: int) -> None:
|
|
208
|
+
total = sum(self.splitter.sizes()) or self.width()
|
|
209
|
+
self.splitter.setSizes([168, max(total - 168 - log_width, 300), log_width])
|
|
210
|
+
|
|
211
|
+
def set_log_visible(self, visible: bool) -> None:
|
|
212
|
+
self.logpane.setVisible(visible)
|
|
213
|
+
self._toggle_log_btn.setText("隐藏日志" if visible else "显示日志")
|
|
214
|
+
if visible:
|
|
215
|
+
self._apply_splitter_sizes(int(self.settings.get("log_width") or DEFAULT_LOG_WIDTH))
|
|
216
|
+
|
|
217
|
+
# ------------------------------------------------------------ 文件与路径
|
|
218
|
+
|
|
219
|
+
def _load_initial_paths(self) -> None:
|
|
220
|
+
docx: Path | None = None
|
|
221
|
+
remembered = self.settings.get("last_docx")
|
|
222
|
+
if remembered and Path(remembered).exists():
|
|
223
|
+
docx = Path(remembered)
|
|
224
|
+
else:
|
|
225
|
+
try:
|
|
226
|
+
docx = find_default_docx(self.base_dir)
|
|
227
|
+
except SyncError:
|
|
228
|
+
docx = None
|
|
229
|
+
remembered_excel = self.settings.get("last_excel")
|
|
230
|
+
if remembered_excel and Path(remembered_excel).exists():
|
|
231
|
+
self.excel_path = Path(remembered_excel)
|
|
232
|
+
self.excel_is_custom = True
|
|
233
|
+
self.set_docx(docx)
|
|
234
|
+
|
|
235
|
+
def set_docx(self, path: Path | None) -> None:
|
|
236
|
+
self.docx_path = path
|
|
237
|
+
if path is not None and not self.excel_is_custom:
|
|
238
|
+
self.excel_path = api.workbook_path(path, None)
|
|
239
|
+
self.filebar.set_paths(self.docx_path, self.excel_path)
|
|
240
|
+
if path is None:
|
|
241
|
+
self.set_status("尚未选择 Word 文件")
|
|
242
|
+
else:
|
|
243
|
+
exists = self.excel_path.exists() if self.excel_path else False
|
|
244
|
+
suffix = "" if exists else "(工作簿尚未生成)"
|
|
245
|
+
self.set_status(f"当前文件:{path.name}{suffix}")
|
|
246
|
+
page = self.stack.currentWidget()
|
|
247
|
+
if hasattr(page, "on_show"):
|
|
248
|
+
page.on_show()
|
|
249
|
+
|
|
250
|
+
def set_excel(self, path: Path | None) -> None:
|
|
251
|
+
self.excel_path = path
|
|
252
|
+
self.excel_is_custom = path is not None
|
|
253
|
+
self.filebar.set_paths(self.docx_path, self.excel_path)
|
|
254
|
+
self.set_status("已指定工作簿:" + (path.name if path else "(未指定)"))
|
|
255
|
+
|
|
256
|
+
def pick_docx(self) -> None:
|
|
257
|
+
initial = str(self.docx_path.parent if self.docx_path else self.base_dir)
|
|
258
|
+
path, _ = QFileDialog.getOpenFileName(
|
|
259
|
+
self, "选择 Word 文件", initial, "Word 文档 (*.docx);;所有文件 (*.*)"
|
|
260
|
+
)
|
|
261
|
+
if path:
|
|
262
|
+
self.set_docx(Path(path))
|
|
263
|
+
self.append_log(f"已选择 Word 文件:{path}", "muted")
|
|
264
|
+
|
|
265
|
+
def pick_excel(self) -> None:
|
|
266
|
+
initial = self.excel_path or self.base_dir
|
|
267
|
+
path, _ = QFileDialog.getSaveFileName(
|
|
268
|
+
self,
|
|
269
|
+
"选择或指定工作簿",
|
|
270
|
+
str(initial.parent / (initial.name if self.excel_path else "表格数据.xlsx")),
|
|
271
|
+
"Excel 工作簿 (*.xlsx);;所有文件 (*.*)",
|
|
272
|
+
)
|
|
273
|
+
if path:
|
|
274
|
+
if not path.lower().endswith(".xlsx"):
|
|
275
|
+
path += ".xlsx"
|
|
276
|
+
self.set_excel(Path(path))
|
|
277
|
+
self.append_log(f"已指定工作簿:{path}", "muted")
|
|
278
|
+
|
|
279
|
+
def reset_excel(self) -> None:
|
|
280
|
+
self.excel_is_custom = False
|
|
281
|
+
self.set_excel_default()
|
|
282
|
+
|
|
283
|
+
def set_excel_default(self) -> None:
|
|
284
|
+
if self.docx_path is None:
|
|
285
|
+
self.excel_path = None
|
|
286
|
+
else:
|
|
287
|
+
self.excel_path = api.workbook_path(self.docx_path, None)
|
|
288
|
+
self.filebar.set_paths(self.docx_path, self.excel_path)
|
|
289
|
+
self.set_status("工作簿已恢复为默认命名:" + (self.excel_path.name if self.excel_path else "(无)"))
|
|
290
|
+
|
|
291
|
+
def open_folder(self) -> None:
|
|
292
|
+
target = self.docx_path.parent if self.docx_path else self.base_dir
|
|
293
|
+
try:
|
|
294
|
+
if sys.platform.startswith("win"):
|
|
295
|
+
os.startfile(str(target)) # type: ignore[attr-defined]
|
|
296
|
+
elif sys.platform == "darwin":
|
|
297
|
+
subprocess.Popen(["open", str(target)])
|
|
298
|
+
else:
|
|
299
|
+
subprocess.Popen(["xdg-open", str(target)])
|
|
300
|
+
except Exception as exc:
|
|
301
|
+
self.ctx.error("无法打开目录", f"{target}\n{exc}")
|
|
302
|
+
|
|
303
|
+
# -------------------------------------------------------------- 页面切换
|
|
304
|
+
|
|
305
|
+
def _select_page(self, key: str) -> None:
|
|
306
|
+
if key not in self._pages:
|
|
307
|
+
return
|
|
308
|
+
page = self._pages[key]
|
|
309
|
+
self.stack.setCurrentWidget(page)
|
|
310
|
+
self.nav.select(key)
|
|
311
|
+
if hasattr(page, "on_show"):
|
|
312
|
+
page.on_show()
|
|
313
|
+
self.set_status(f"当前页面:{getattr(page, 'title', key)}")
|
|
314
|
+
|
|
315
|
+
# -------------------------------------------------------- 日志与状态栏
|
|
316
|
+
|
|
317
|
+
@staticmethod
|
|
318
|
+
def _level_for(text: str) -> str:
|
|
319
|
+
stripped = text.strip()
|
|
320
|
+
if stripped.startswith("警告:"):
|
|
321
|
+
return "warn"
|
|
322
|
+
if stripped.startswith("错误:") or stripped.startswith("Traceback"):
|
|
323
|
+
return "error"
|
|
324
|
+
if any(mark in stripped for mark in ("已保存", "已写入", "已更新", "已创建", "完成")):
|
|
325
|
+
return "ok"
|
|
326
|
+
return "info"
|
|
327
|
+
|
|
328
|
+
def append_log(self, text: str, level: str | None = None) -> None:
|
|
329
|
+
self.logpane.append(text, level if level else self._level_for(text))
|
|
330
|
+
|
|
331
|
+
def set_status(self, text: str) -> None:
|
|
332
|
+
self._status_label.setText(text)
|
|
333
|
+
|
|
334
|
+
# ---------------------------------------------------------- 后台任务处理
|
|
335
|
+
|
|
336
|
+
def set_busy(self, busy: bool) -> None:
|
|
337
|
+
buttons = self.stack.findChildren(QPushButton) + self.filebar.findChildren(QPushButton)
|
|
338
|
+
if busy:
|
|
339
|
+
# 记住执行前就禁用的按钮,结束后不能一律启用
|
|
340
|
+
self._disabled_before_busy = {btn for btn in buttons if not btn.isEnabled()}
|
|
341
|
+
for widget in buttons:
|
|
342
|
+
widget.setEnabled(False)
|
|
343
|
+
self.set_status("执行中…请稍候")
|
|
344
|
+
self._progress.setRange(0, 0)
|
|
345
|
+
else:
|
|
346
|
+
disabled = getattr(self, "_disabled_before_busy", set())
|
|
347
|
+
for widget in buttons:
|
|
348
|
+
widget.setEnabled(widget not in disabled)
|
|
349
|
+
self._disabled_before_busy = set()
|
|
350
|
+
# 任务期间页面可能清空了清单,按当前数据重算按钮可用性
|
|
351
|
+
for page in self._pages.values():
|
|
352
|
+
refresh = getattr(page, "refresh_button_state", None)
|
|
353
|
+
if refresh is not None:
|
|
354
|
+
refresh()
|
|
355
|
+
self._progress.setRange(0, 100)
|
|
356
|
+
self._progress.setValue(0)
|
|
357
|
+
|
|
358
|
+
def _poll_queue(self) -> None:
|
|
359
|
+
for event, payload in self.runner.drain():
|
|
360
|
+
if event == "log":
|
|
361
|
+
self.append_log(str(payload))
|
|
362
|
+
elif event == "step":
|
|
363
|
+
self.append_log(f"▶ {payload} …", "step")
|
|
364
|
+
self.set_status(f"执行中:{payload}")
|
|
365
|
+
elif event == "done":
|
|
366
|
+
data = payload if isinstance(payload, dict) else {}
|
|
367
|
+
titles = "、".join(title for title, _ in data.get("steps", []))
|
|
368
|
+
elapsed = float(data.get("elapsed", 0.0))
|
|
369
|
+
self.append_log(f"✔ 完成:{titles}(耗时 {elapsed:.1f} 秒)", "ok")
|
|
370
|
+
self.set_status(f"最近一次:{titles} · 耗时 {elapsed:.1f} 秒")
|
|
371
|
+
self.set_busy(False)
|
|
372
|
+
QTimer.singleShot(
|
|
373
|
+
200, lambda: self.ctx.info("执行完成", f"{titles}\n耗时:{elapsed:.1f} 秒\n\n详细过程见日志区。")
|
|
374
|
+
)
|
|
375
|
+
elif event == "error":
|
|
376
|
+
data = payload if isinstance(payload, dict) else {}
|
|
377
|
+
title = str(data.get("title", "任务"))
|
|
378
|
+
message = str(data.get("message", "未知错误"))
|
|
379
|
+
elapsed = float(data.get("elapsed", 0.0))
|
|
380
|
+
self.append_log(f"✘ 「{title}」执行失败(耗时 {elapsed:.1f} 秒):{message}", "error")
|
|
381
|
+
self.set_status(f"失败:{title}")
|
|
382
|
+
self.set_busy(False)
|
|
383
|
+
QTimer.singleShot(200, lambda: self.ctx.error("执行失败", f"{title}\n\n{message}", log=False))
|
|
384
|
+
|
|
385
|
+
# ------------------------------------------------------------------ 退出
|
|
386
|
+
|
|
387
|
+
def closeEvent(self, event) -> None:
|
|
388
|
+
sizes = self.splitter.sizes()
|
|
389
|
+
store.save(
|
|
390
|
+
{
|
|
391
|
+
"qt_size": [self.width(), self.height()],
|
|
392
|
+
"qt_pos": [self.x(), self.y()],
|
|
393
|
+
"log_visible": self.logpane.isVisible(),
|
|
394
|
+
"log_width": sizes[2] if sizes[2] >= 80 else int(self.settings.get("log_width") or DEFAULT_LOG_WIDTH),
|
|
395
|
+
"last_docx": str(self.docx_path) if self.docx_path else "",
|
|
396
|
+
"last_excel": str(self.excel_path) if (self.excel_path and self.excel_is_custom) else "",
|
|
397
|
+
}
|
|
398
|
+
)
|
|
399
|
+
super().closeEvent(event)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""把随包说明文档转成可导航、可搜索的 HTML。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import html
|
|
6
|
+
import re
|
|
7
|
+
|
|
8
|
+
from .resources import manual_path
|
|
9
|
+
|
|
10
|
+
HEADING_RE = re.compile(r"^(?:[一二三四五六七八九十]+、)\s*(.+)$")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def load_manual_text() -> str:
|
|
14
|
+
return manual_path().read_text(encoding="utf-8-sig")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def parse_manual(text: str) -> list[tuple[str, list[str]]]:
|
|
18
|
+
sections: list[tuple[str, list[str]]] = []
|
|
19
|
+
title = "软件说明"
|
|
20
|
+
lines: list[str] = []
|
|
21
|
+
for raw in text.splitlines():
|
|
22
|
+
line = raw.rstrip()
|
|
23
|
+
stripped = line.strip()
|
|
24
|
+
if HEADING_RE.match(stripped):
|
|
25
|
+
if any(item.strip() for item in lines):
|
|
26
|
+
sections.append((title, lines))
|
|
27
|
+
title = stripped
|
|
28
|
+
lines = []
|
|
29
|
+
elif stripped and set(stripped) <= {"=", "-"}:
|
|
30
|
+
continue
|
|
31
|
+
else:
|
|
32
|
+
lines.append(line)
|
|
33
|
+
if any(item.strip() for item in lines):
|
|
34
|
+
sections.append((title, lines))
|
|
35
|
+
return sections or [("软件说明", text.splitlines())]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _lines_html(lines: list[str]) -> str:
|
|
39
|
+
result: list[str] = []
|
|
40
|
+
for raw in lines:
|
|
41
|
+
line = raw.rstrip()
|
|
42
|
+
stripped = line.strip()
|
|
43
|
+
if not stripped:
|
|
44
|
+
result.append("<div class='gap'> </div>")
|
|
45
|
+
elif stripped.startswith("·"):
|
|
46
|
+
result.append(f"<div class='bullet'>{html.escape(stripped)}</div>")
|
|
47
|
+
elif re.match(r"^\d+\)", stripped):
|
|
48
|
+
result.append(f"<div class='step'>{html.escape(stripped)}</div>")
|
|
49
|
+
else:
|
|
50
|
+
result.append(f"<div class='line'>{html.escape(stripped)}</div>")
|
|
51
|
+
return "".join(result)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def manual_html(sections: list[tuple[str, list[str]]]) -> str:
|
|
55
|
+
parts = [
|
|
56
|
+
"<!doctype html><html><head><meta charset='utf-8'><style>",
|
|
57
|
+
"body{font-family:'Microsoft YaHei UI','Microsoft YaHei',sans-serif;color:#1F2937;font-size:14px;line-height:1.75;margin:18px 24px;}",
|
|
58
|
+
"h1{font-size:24px;color:#1F4E79;margin:0 0 6px;}h2{font-size:18px;color:#1F4E79;margin:26px 0 10px;border-bottom:1px solid #E3E6EA;padding-bottom:6px;}",
|
|
59
|
+
".intro,.line,.step,.bullet{margin:4px 0;}.intro{color:#6B7280;}.gap{height:6px;}",
|
|
60
|
+
".bullet{padding-left:16px;text-indent:-12px;}.step{padding-left:20px;text-indent:-16px;}",
|
|
61
|
+
"section{scroll-margin-top:12px;}</style></head><body>",
|
|
62
|
+
"<h1>审计工具箱使用说明</h1><p class='intro'>本说明书与软件一同分发,无需联网。左侧选择章节,右上角可搜索关键词。</p>",
|
|
63
|
+
]
|
|
64
|
+
for index, (title, lines) in enumerate(sections):
|
|
65
|
+
anchor = f"chapter-{index}"
|
|
66
|
+
parts.append(f"<section id='{anchor}'><h2>{html.escape(title)}</h2>{_lines_html(lines)}</section>")
|
|
67
|
+
parts.append("</body></html>")
|
|
68
|
+
return "".join(parts)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""页面注册表:新增页面只需继承 BasePage 并调用 register_page()。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from ._page import BasePage
|
|
6
|
+
from .batch_page import BatchPage
|
|
7
|
+
from .blank_page import BlankPage
|
|
8
|
+
from .bookmark_page import BookmarkPage
|
|
9
|
+
from .export_page import ExportPage
|
|
10
|
+
from .format_page import FormatPage
|
|
11
|
+
from .help_page import HelpPage
|
|
12
|
+
from .history_page import HistoryPage
|
|
13
|
+
from .marks_page import MarksPage
|
|
14
|
+
from .writeback_page import WritebackPage
|
|
15
|
+
|
|
16
|
+
# 全局工具箱界面:左侧导航直接列出功能。
|
|
17
|
+
# 后续新增功能(如多文件合并)在此追加,或调用 register_page()。
|
|
18
|
+
_PAGES: list[type[BasePage]] = [ExportPage, WritebackPage, MarksPage, BookmarkPage, BlankPage, BatchPage, FormatPage, HistoryPage, HelpPage]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def register_page(page_class: type[BasePage]) -> type[BasePage]:
|
|
22
|
+
"""注册新功能页(自动加入导航)。"""
|
|
23
|
+
_PAGES.append(page_class)
|
|
24
|
+
return page_class
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def iter_pages() -> list[type[BasePage]]:
|
|
28
|
+
return [*_PAGES]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
__all__ = ["BasePage", "register_page", "iter_pages", "ExportPage", "FormatPage", "WritebackPage", "MarksPage", "BookmarkPage", "BlankPage", "BatchPage", "HistoryPage", "HelpPage"]
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""页面基类与共用构件:标题、说明、卡片、按钮行。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from PySide6.QtWidgets import (
|
|
6
|
+
QHBoxLayout,
|
|
7
|
+
QLabel,
|
|
8
|
+
QPushButton,
|
|
9
|
+
QScrollArea,
|
|
10
|
+
QVBoxLayout,
|
|
11
|
+
QWidget,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from ..widgets.cards import make_card
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class BasePage(QWidget):
|
|
18
|
+
"""所有功能页的基类:上方标题与说明,下方是可滚动的页面内容。"""
|
|
19
|
+
|
|
20
|
+
title = "页面"
|
|
21
|
+
subtitle = ""
|
|
22
|
+
|
|
23
|
+
def __init__(self, ctx, parent=None):
|
|
24
|
+
super().__init__(parent)
|
|
25
|
+
self.ctx = ctx
|
|
26
|
+
layout = QVBoxLayout(self)
|
|
27
|
+
layout.setContentsMargins(18, 12, 18, 12)
|
|
28
|
+
layout.setSpacing(4)
|
|
29
|
+
title = QLabel(self.title)
|
|
30
|
+
title.setObjectName("PageTitle")
|
|
31
|
+
layout.addWidget(title)
|
|
32
|
+
if self.subtitle:
|
|
33
|
+
desc = QLabel(self.subtitle)
|
|
34
|
+
desc.setObjectName("Desc")
|
|
35
|
+
desc.setWordWrap(True)
|
|
36
|
+
desc.setMinimumWidth(0)
|
|
37
|
+
layout.addWidget(desc)
|
|
38
|
+
|
|
39
|
+
scroller = QScrollArea()
|
|
40
|
+
scroller.setWidgetResizable(True)
|
|
41
|
+
body = QWidget()
|
|
42
|
+
body_layout = QVBoxLayout(body)
|
|
43
|
+
body_layout.setContentsMargins(0, 8, 0, 0)
|
|
44
|
+
body_layout.setSpacing(12)
|
|
45
|
+
body_layout.addStretch(1)
|
|
46
|
+
scroller.setWidget(body)
|
|
47
|
+
layout.addWidget(scroller, 1)
|
|
48
|
+
self.body = body
|
|
49
|
+
self.build(body)
|
|
50
|
+
|
|
51
|
+
def build(self, body: QWidget) -> None: # pragma: no cover - 子类实现
|
|
52
|
+
raise NotImplementedError
|
|
53
|
+
|
|
54
|
+
def on_show(self) -> None:
|
|
55
|
+
"""切换到本页时调用,默认什么都不做。"""
|
|
56
|
+
|
|
57
|
+
# ---------- 共用构件 ----------
|
|
58
|
+
|
|
59
|
+
@staticmethod
|
|
60
|
+
def card(body: QWidget) -> QWidget:
|
|
61
|
+
card = make_card()
|
|
62
|
+
# 插到末尾 stretch 之前,卡片保持从上往下排
|
|
63
|
+
body.layout().insertWidget(body.layout().count() - 1, card)
|
|
64
|
+
return card
|
|
65
|
+
|
|
66
|
+
@staticmethod
|
|
67
|
+
def tip_label(card: QWidget, text: str) -> QLabel:
|
|
68
|
+
label = QLabel(text)
|
|
69
|
+
label.setObjectName("CardDesc")
|
|
70
|
+
label.setWordWrap(True)
|
|
71
|
+
label.setMinimumWidth(0)
|
|
72
|
+
card.layout().addWidget(label)
|
|
73
|
+
return label
|
|
74
|
+
|
|
75
|
+
def button_row(self, card: QWidget, on_dry, on_run, dry_text="仅预演", run_text="开始执行") -> QWidget:
|
|
76
|
+
row = QWidget()
|
|
77
|
+
layout = QHBoxLayout(row)
|
|
78
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
79
|
+
layout.setSpacing(12)
|
|
80
|
+
dry = QPushButton(dry_text)
|
|
81
|
+
dry.clicked.connect(lambda _checked=False: on_dry())
|
|
82
|
+
layout.addWidget(dry)
|
|
83
|
+
run = QPushButton(run_text)
|
|
84
|
+
run.setObjectName("Primary")
|
|
85
|
+
run.clicked.connect(lambda _checked=False: on_run())
|
|
86
|
+
layout.addWidget(run)
|
|
87
|
+
layout.addStretch(1)
|
|
88
|
+
card.layout().addWidget(row)
|
|
89
|
+
return row
|