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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -2
  3. package/cordis.patch.yml +3 -0
  4. package/dsh_plugins/audit-e2w/lib/engine.mjs +174 -0
  5. package/dsh_plugins/audit-e2w/lib/index.js +114 -0
  6. package/dsh_plugins/audit-e2w/lib/skill.js +41 -0
  7. package/excel_word/README.md +380 -0
  8. package/excel_word/qoder_engine.py +438 -0
  9. package/excel_word/requirements.txt +4 -0
  10. package/excel_word/wesync/__init__.py +19 -0
  11. package/excel_word/wesync/__main__.py +6 -0
  12. package/excel_word/wesync/align.py +154 -0
  13. package/excel_word/wesync/api.py +840 -0
  14. package/excel_word/wesync/backup_history.py +65 -0
  15. package/excel_word/wesync/changelog.py +58 -0
  16. package/excel_word/wesync/cli.py +173 -0
  17. package/excel_word/wesync/commands/__init__.py +8 -0
  18. package/excel_word/wesync/commands/blank_cmd.py +250 -0
  19. package/excel_word/wesync/commands/bookmark_cmd.py +115 -0
  20. package/excel_word/wesync/commands/clear_cmd.py +48 -0
  21. package/excel_word/wesync/commands/export_cmd.py +220 -0
  22. package/excel_word/wesync/commands/marks_cmd.py +152 -0
  23. package/excel_word/wesync/commands/placeholders_cmd.py +87 -0
  24. package/excel_word/wesync/commands/writeback_cmd.py +513 -0
  25. package/excel_word/wesync/config.py +96 -0
  26. package/excel_word/wesync/console.py +78 -0
  27. package/excel_word/wesync/docx_blank.py +156 -0
  28. package/excel_word/wesync/docx_bookmarks.py +287 -0
  29. package/excel_word/wesync/docx_columns.py +257 -0
  30. package/excel_word/wesync/docx_edit.py +77 -0
  31. package/excel_word/wesync/docx_grid.py +212 -0
  32. package/excel_word/wesync/docx_marks.py +291 -0
  33. package/excel_word/wesync/docx_meta.py +157 -0
  34. package/excel_word/wesync/docx_newtable.py +220 -0
  35. package/excel_word/wesync/docx_placeholders.py +161 -0
  36. package/excel_word/wesync/docx_rows.py +67 -0
  37. package/excel_word/wesync/errors.py +5 -0
  38. package/excel_word/wesync/excel_blocks.py +543 -0
  39. package/excel_word/wesync/excel_export.py +136 -0
  40. package/excel_word/wesync/excel_marks.py +193 -0
  41. package/excel_word/wesync/excel_totals.py +53 -0
  42. package/excel_word/wesync/fsops.py +214 -0
  43. package/excel_word/wesync/gui/__init__.py +34 -0
  44. package/excel_word/wesync/gui/__main__.py +6 -0
  45. package/excel_word/wesync/gui/app.py +399 -0
  46. package/excel_word/wesync/gui/manual.py +68 -0
  47. package/excel_word/wesync/gui/pages/__init__.py +31 -0
  48. package/excel_word/wesync/gui/pages/_page.py +89 -0
  49. package/excel_word/wesync/gui/pages/batch_page.py +423 -0
  50. package/excel_word/wesync/gui/pages/blank_page.py +465 -0
  51. package/excel_word/wesync/gui/pages/bookmark_page.py +37 -0
  52. package/excel_word/wesync/gui/pages/export_page.py +88 -0
  53. package/excel_word/wesync/gui/pages/format_page.py +429 -0
  54. package/excel_word/wesync/gui/pages/help_page.py +92 -0
  55. package/excel_word/wesync/gui/pages/history_page.py +145 -0
  56. package/excel_word/wesync/gui/pages/marks_page.py +178 -0
  57. package/excel_word/wesync/gui/pages/writeback_page.py +452 -0
  58. package/excel_word/wesync/gui/resources.py +22 -0
  59. package/excel_word/wesync/gui/runner.py +74 -0
  60. package/excel_word/wesync/gui/store.py +34 -0
  61. package/excel_word/wesync/gui/theme.py +100 -0
  62. package/excel_word/wesync/gui/widgets/__init__.py +8 -0
  63. package/excel_word/wesync/gui/widgets/cards.py +20 -0
  64. package/excel_word/wesync/gui/widgets/filebar.py +58 -0
  65. package/excel_word/wesync/gui/widgets/logpane.py +110 -0
  66. package/excel_word/wesync/gui/widgets/nav.py +39 -0
  67. package/excel_word/wesync/report_format.py +1577 -0
  68. package/excel_word/wesync/sort_rules.py +244 -0
  69. package/excel_word/wesync/valuefmt.py +462 -0
  70. package/package.json +49 -4
  71. package/qoder_plugins/audit-toolbox/README.md +156 -0
  72. package/qoder_plugins/audit-toolbox/catalog.mjs +265 -0
@@ -0,0 +1,429 @@
1
+ """桌面格式页:选择样板、预演格式方案、生成格式调整副本。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ from PySide6.QtCore import QTimer
8
+ from PySide6.QtWidgets import (
9
+ QComboBox,
10
+ QCheckBox,
11
+ QFileDialog,
12
+ QHBoxLayout,
13
+ QInputDialog,
14
+ QLabel,
15
+ QLineEdit,
16
+ QPlainTextEdit,
17
+ QPushButton,
18
+ QTabWidget,
19
+ QVBoxLayout,
20
+ QWidget,
21
+ )
22
+
23
+ from ... import api
24
+ from ...errors import SyncError
25
+ from ...report_format import DEFAULT_SCOPE, SCOPE_LABELS
26
+ from ._page import BasePage
27
+ from ..widgets.cards import make_checkbutton
28
+
29
+
30
+ class FormatPage(BasePage):
31
+ title = "一键调整格式"
32
+ subtitle = "按样板或已存方案统一字体、标题、正文和表格格式;只生成新副本,原报告不改动。"
33
+
34
+ def build(self, body: QWidget) -> None:
35
+ card = self.card(body)
36
+ self.tip_label(
37
+ card,
38
+ "先在顶部选择要调整的报告,再到第 2 个 Tab“调整项目”勾选需要修改的内容。"
39
+ "小报表字号保留,页面设置、分节、页眉页脚、表格结构和审计痕迹均不改动。",
40
+ )
41
+ self.tabs = QTabWidget()
42
+ card.layout().addWidget(self.tabs)
43
+ self.tabs.addTab(self._build_apply_tab(), "格式调整")
44
+ self.tabs.addTab(self._build_scope_tab(), "调整项目")
45
+
46
+ result_card = self.card(body)
47
+ self.status_label = self.tip_label(result_card, "尚未检查。选择样板或已存方案后,先点“检查格式方案”。")
48
+ self.details = QPlainTextEdit()
49
+ self.details.setReadOnly(True)
50
+ self.details.setLineWrapMode(QPlainTextEdit.WidgetWidth)
51
+ self.details.setMinimumHeight(240)
52
+ result_card.layout().addWidget(self.details)
53
+
54
+ self._waiting: str | None = None
55
+ self._result: dict | None = None
56
+ self._scan_key: tuple[str, str, str, tuple[bool, ...]] | None = None
57
+ self._pending_key: tuple[str, str, str, tuple[bool, ...]] | None = None
58
+ self._pending_output = ""
59
+ self._output_auto = True
60
+ self._last_target: Path | None = None
61
+ self._reload_profiles()
62
+ self._timer = QTimer(self)
63
+ self._timer.timeout.connect(self._check_done)
64
+ self._timer.start(250)
65
+
66
+ def _build_apply_tab(self) -> QWidget:
67
+ tab = QWidget()
68
+ layout = QVBoxLayout(tab)
69
+ layout.setContentsMargins(0, 4, 0, 0)
70
+ layout.setSpacing(8)
71
+ target_row = QHBoxLayout()
72
+ target_row.addWidget(QLabel("待调整报告:"))
73
+ self.target_label = QLabel("尚未选择")
74
+ self.target_label.setWordWrap(True)
75
+ self.target_label.setMinimumWidth(0)
76
+ target_row.addWidget(self.target_label, 1)
77
+ layout.addLayout(target_row)
78
+
79
+ profile_row = QHBoxLayout()
80
+ profile_row.addWidget(QLabel("格式来源:"))
81
+ self.profile_combo = QComboBox()
82
+ self.profile_combo.addItem("从样板报告提取", "")
83
+ self.profile_combo.currentIndexChanged.connect(self._invalidate)
84
+ self.profile_combo.currentIndexChanged.connect(self._update_profile_mode)
85
+ profile_row.addWidget(self.profile_combo, 1)
86
+ self.save_profile_button = QPushButton("保存当前样板为方案…")
87
+ self.save_profile_button.clicked.connect(self._save_profile)
88
+ profile_row.addWidget(self.save_profile_button)
89
+ self.delete_profile_button = QPushButton("删除方案")
90
+ self.delete_profile_button.clicked.connect(self._delete_profile)
91
+ profile_row.addWidget(self.delete_profile_button)
92
+ layout.addLayout(profile_row)
93
+
94
+ template_row = QHBoxLayout()
95
+ template_row.addWidget(QLabel("样板报告:"))
96
+ self.template_edit = QLineEdit()
97
+ self.template_edit.setPlaceholderText("选择格式标准的 Word 报告;使用已存方案时无需选择")
98
+ self.template_edit.textChanged.connect(self._invalidate)
99
+ template_row.addWidget(self.template_edit, 1)
100
+ self.template_button = QPushButton("浏览…")
101
+ self.template_button.clicked.connect(self._browse_template)
102
+ template_row.addWidget(self.template_button)
103
+ layout.addLayout(template_row)
104
+
105
+ output_row = QHBoxLayout()
106
+ output_row.addWidget(QLabel("输出副本:"))
107
+ self.output_edit = QLineEdit()
108
+ self.output_edit.setPlaceholderText("默认保存在原报告旁:原名_格式调整.docx")
109
+ self.output_edit.textChanged.connect(self._invalidate)
110
+ self.output_edit.textEdited.connect(lambda _text: setattr(self, "_output_auto", False))
111
+ output_row.addWidget(self.output_edit, 1)
112
+ output_button = QPushButton("浏览…")
113
+ output_button.clicked.connect(self._browse_output)
114
+ output_row.addWidget(output_button)
115
+ layout.addLayout(output_row)
116
+
117
+ row = self.button_row(tab, self._start_scan, self._start_apply, "检查格式方案", "生成格式副本")
118
+ self.apply_button = row.layout().itemAt(1).widget()
119
+ self.apply_button.setEnabled(False)
120
+ layout.addStretch(1)
121
+ return tab
122
+
123
+ def _build_scope_tab(self) -> QWidget:
124
+ tab = QWidget()
125
+ layout = QVBoxLayout(tab)
126
+ layout.setContentsMargins(0, 4, 0, 0)
127
+ layout.setSpacing(8)
128
+ self.tip_label(tab, "只调整勾选的项目;未勾选项目的字体、字号、段落设置、对齐和加粗均保持原样。修改选择后需重新检查。")
129
+ self.scope_buttons: dict[str, QCheckBox] = {}
130
+ descriptions = {
131
+ "cover": "封面与目录(封面标题、封面信息、目录标题和条目)",
132
+ "headings": "一至四级标题",
133
+ "statement": "报表名称、日期与表格标题",
134
+ "body": "正文段落",
135
+ "table_text": "表格字体与字号(小报表字号不放大)",
136
+ "table_emphasis": "表格对齐、表头与合计行加粗",
137
+ "table_borders": "表格框线(外框、内部横线和竖线)",
138
+ }
139
+ for key in DEFAULT_SCOPE:
140
+ button = make_checkbutton(tab, descriptions[key], checked=True)
141
+ button.toggled.connect(self._invalidate)
142
+ layout.addWidget(button)
143
+ self.scope_buttons[key] = button
144
+ self.tip_label(
145
+ tab,
146
+ "智能保护:按报告角色区分处理,不把所有段落套成同一种格式;空段落和大纲级别异常段落保持原样。"
147
+ "不改文字、数字、书签、超链接、图片、域代码、颜色、高亮、下划线、表格结构及页面设置。",
148
+ )
149
+ layout.addStretch(1)
150
+ return tab
151
+
152
+ def _scope(self) -> dict[str, bool]:
153
+ return {key: button.isChecked() for key, button in self.scope_buttons.items()}
154
+
155
+ def on_show(self) -> None:
156
+ self._refresh_target()
157
+ self._reload_profiles()
158
+
159
+ def _reload_profiles(self) -> None:
160
+ selected = self.profile_combo.currentData()
161
+ self.profile_combo.blockSignals(True)
162
+ self.profile_combo.clear()
163
+ self.profile_combo.addItem("从样板报告提取", "")
164
+ try:
165
+ for item in api.list_format_profiles():
166
+ self.profile_combo.addItem(item["name"], item["name"])
167
+ except SyncError as exc:
168
+ self.ctx.error("格式方案读取失败", str(exc))
169
+ index = self.profile_combo.findData(selected)
170
+ self.profile_combo.setCurrentIndex(max(index, 0))
171
+ self.profile_combo.blockSignals(False)
172
+ if (self.profile_combo.currentData() or None) != (selected or None):
173
+ self._invalidate()
174
+ self._update_profile_mode()
175
+
176
+ def _update_profile_mode(self) -> None:
177
+ saved = bool(self.profile_combo.currentData())
178
+ enabled = not self.ctx.busy
179
+ self.template_edit.setEnabled(not saved)
180
+ self.template_button.setEnabled(not saved and enabled)
181
+ self.save_profile_button.setEnabled(not saved and enabled)
182
+ self.delete_profile_button.setEnabled(saved and enabled)
183
+
184
+ def _save_profile(self) -> None:
185
+ template_text = self.template_edit.text().strip()
186
+ if not template_text:
187
+ self.ctx.error("未选择样板", "请先选择样板报告,再保存纯格式方案。")
188
+ return
189
+ template = Path(template_text)
190
+ name, ok = QInputDialog.getText(self, "保存格式方案", "方案名称:", QLineEdit.Normal, template.stem)
191
+ if not ok or not name.strip():
192
+ return
193
+ try:
194
+ if any(item["name"] == name.strip() for item in api.list_format_profiles()):
195
+ self.ctx.error("方案已存在", "请换一个方案名称;已有方案不会被覆盖。")
196
+ return
197
+ except SyncError as exc:
198
+ self.ctx.error("方案读取失败", str(exc))
199
+ return
200
+ self._result = None
201
+ self._waiting = "save"
202
+ self.status_label.setText("正在提取并保存纯格式方案…")
203
+
204
+ def run() -> int:
205
+ self._result = api.save_format_profile(template, name, source=self.ctx.docx)
206
+ return 0
207
+
208
+ self.ctx.run_steps([("保存纯格式方案", run)])
209
+
210
+ def _delete_profile(self) -> None:
211
+ name = self.profile_combo.currentData()
212
+ if not name:
213
+ return
214
+ if not self.ctx.confirm("删除格式方案", f"确定删除格式方案“{name}”?\n\n只删除格式参数,不删除任何报告。"):
215
+ return
216
+ try:
217
+ api.delete_format_profile(name)
218
+ except SyncError as exc:
219
+ self.ctx.error("删除失败", str(exc))
220
+ return
221
+ self._reload_profiles()
222
+ self._invalidate()
223
+ self.status_label.setText(f"已删除格式方案:{name}")
224
+
225
+ def _refresh_target(self) -> None:
226
+ target = self.ctx.docx
227
+ self.target_label.setText(str(target) if target else "尚未选择(请在顶部选择 Word 文件)")
228
+ if target != self._last_target:
229
+ self._last_target = target
230
+ self._scan_key = None
231
+ self._result = None
232
+ self.apply_button.setEnabled(False)
233
+ if target is not None and self._output_auto:
234
+ suffix = target.suffix if target.suffix.lower() in (".docx", ".docm") else ".docx"
235
+ self.output_edit.setText(str(target.with_name(f"{target.stem}_格式调整{suffix}")))
236
+
237
+ def _invalidate(self) -> None:
238
+ self._scan_key = None
239
+ self._result = None
240
+ self.apply_button.setEnabled(False)
241
+
242
+ def _browse_template(self) -> None:
243
+ initial = self.template_edit.text() or str(self.ctx.docx.parent if self.ctx.docx else "")
244
+ path, _ = QFileDialog.getOpenFileName(self, "选择样板报告", initial, "Word 文档 (*.docx *.docm)")
245
+ if path:
246
+ self.template_edit.setText(path)
247
+
248
+ def _browse_output(self) -> None:
249
+ target = self.ctx.docx
250
+ suffix = target.suffix if target and target.suffix.lower() in (".docx", ".docm") else ".docx"
251
+ initial = self.output_edit.text() or str(target.with_name(f"{target.stem}_格式调整{suffix}") if target else f"格式调整{suffix}")
252
+ path, _ = QFileDialog.getSaveFileName(self, "选择格式副本保存位置", initial, f"Word 文档 (*{suffix})")
253
+ if path:
254
+ if not path.lower().endswith(suffix):
255
+ path += suffix
256
+ self._output_auto = False
257
+ self.output_edit.setText(path)
258
+
259
+ def _paths(self) -> tuple[Path, Path | None, Path, str | None] | None:
260
+ self._refresh_target()
261
+ if not self.ctx.require_docx() or self.ctx.docx is None:
262
+ return None
263
+ profile_name = self.profile_combo.currentData() or None
264
+ template_text = self.template_edit.text().strip()
265
+ if profile_name is None and not template_text:
266
+ self.ctx.error("未选择格式来源", "请选择样板报告,或改用已保存的格式方案。")
267
+ return None
268
+ output_text = self.output_edit.text().strip()
269
+ if not output_text:
270
+ self.ctx.error("未选择输出位置", "请选择格式副本的保存位置。")
271
+ return None
272
+ return (
273
+ self.ctx.docx,
274
+ Path(template_text) if template_text and profile_name is None else None,
275
+ Path(output_text),
276
+ profile_name,
277
+ )
278
+
279
+ def _source_key(
280
+ self,
281
+ target: Path,
282
+ template: Path | None,
283
+ profile_name: str | None,
284
+ scope: dict[str, bool],
285
+ ) -> tuple[str, str, str, tuple[bool, ...]]:
286
+ return (
287
+ str(target),
288
+ "profile" if profile_name else "template",
289
+ profile_name or str(template),
290
+ tuple(scope[key] for key in DEFAULT_SCOPE),
291
+ )
292
+
293
+ def _start_scan(self) -> None:
294
+ paths = self._paths()
295
+ if paths is None:
296
+ return
297
+ target, template, output, profile_name = paths
298
+ scope = self._scope()
299
+ self._pending_key = self._source_key(target, template, profile_name, scope)
300
+ self._pending_output = str(output)
301
+ self._waiting = "scan"
302
+ self._result = None
303
+ self.status_label.setText("正在读取格式来源和待调整报告…")
304
+
305
+ def run() -> int:
306
+ self._result = api.scan_report_format(target, template, profile_name=profile_name, scope=scope)
307
+ return 0
308
+
309
+ self.ctx.run_steps([("检查报告格式方案", run)])
310
+
311
+ def _start_apply(self) -> None:
312
+ paths = self._paths()
313
+ if paths is None:
314
+ return
315
+ target, template, output, profile_name = paths
316
+ scope = self._scope()
317
+ key = self._source_key(target, template, profile_name, scope)
318
+ if self._scan_key != key or self._result is None:
319
+ self.ctx.error("尚未预演", "请先点“检查格式方案”,确认影响范围后再生成副本。")
320
+ return
321
+ self._pending_key = key
322
+ self._pending_output = str(output)
323
+ totals = self._result["totals"]
324
+ source_label = f"已存方案:{profile_name}" if profile_name else f"样板:{template.name}"
325
+ if not self.ctx.confirm(
326
+ "确认生成格式副本",
327
+ f"将按以下格式来源调整:\n\n{source_label}\n报告:{target.name}\n"
328
+ f"段落:{totals['selected_paragraphs']} 个\n表格:{totals['tables']} 张\n\n"
329
+ f"输出:{output}\n\n原报告不会改动。确认生成格式副本?",
330
+ ):
331
+ self.ctx.log("已取消格式调整。", "muted")
332
+ return
333
+ self._result = None
334
+ self._waiting = "apply"
335
+ self.status_label.setText("正在生成并核验格式副本…")
336
+
337
+ def run() -> int:
338
+ self._result = api.run_report_format(target, template, output=output, profile_name=profile_name, scope=scope)
339
+ return 0
340
+
341
+ self.ctx.run_steps([("生成报告格式副本", run)])
342
+
343
+ def _check_done(self) -> None:
344
+ if not self._waiting or self.ctx.busy:
345
+ return
346
+ mode, self._waiting = self._waiting, None
347
+ pending_key, pending_output = self._pending_key, self._pending_output
348
+ self._pending_key = None
349
+ self._pending_output = ""
350
+ if self._result is None:
351
+ self.status_label.setText("执行失败,请查看右侧日志。")
352
+ return
353
+ if mode == "save":
354
+ name = self._result["name"]
355
+ self._reload_profiles()
356
+ index = self.profile_combo.findData(name)
357
+ if index >= 0:
358
+ self.profile_combo.setCurrentIndex(index)
359
+ self._invalidate()
360
+ self.status_label.setText(f"已保存纯格式方案:{name}")
361
+ elif mode == "scan":
362
+ profile_name = self.profile_combo.currentData() or None
363
+ template_text = self.template_edit.text().strip()
364
+ template = Path(template_text) if template_text and profile_name is None else None
365
+ current_key = (
366
+ self._source_key(self.ctx.docx, template, profile_name, self._scope())
367
+ if self.ctx.docx is not None
368
+ else None
369
+ )
370
+ unchanged = pending_key == current_key
371
+ self._scan_key = pending_key if unchanged else None
372
+ self.apply_button.setEnabled(unchanged)
373
+ if unchanged:
374
+ self._render_scan(self._result, pending_output)
375
+ else:
376
+ self.status_label.setText("格式来源或调整项目已变化,请重新检查格式方案。")
377
+ else:
378
+ output = self._result.get("output", pending_output or self.output_edit.text())
379
+ self._scan_key = None
380
+ self.apply_button.setEnabled(False)
381
+ self.status_label.setText(f"格式副本已生成并核验:{output}")
382
+ self.details.appendPlainText(f"\n已生成:{output}\n原报告未改动。")
383
+ review = self._result.get("visual_review", [])
384
+ if review:
385
+ self.details.appendPlainText("\nWord 目视验收(结构核验不代表排版已通过):")
386
+ self.details.appendPlainText("\n".join(f"· {item}" for item in review))
387
+ self.ctx.info("格式副本已生成", f"格式副本已生成并结构核验:\n{output}\n\n原报告未改动。请在 Word 中按“目视验收清单”复核排版。")
388
+
389
+ def _render_scan(self, result: dict, output: str = "") -> None:
390
+ totals = result["totals"]
391
+ selected_labels = [SCOPE_LABELS[key] for key, enabled in result["scope"].items() if enabled]
392
+ lines = [
393
+ f"格式来源:{result['template']}",
394
+ f"待调整:{result['source']}",
395
+ f"计划输出:{output or result['suggested_output']}",
396
+ "",
397
+ "调整项目:",
398
+ ]
399
+ lines.extend(f"· {label}" for label in selected_labels)
400
+ lines.extend([
401
+ "",
402
+ f"将处理 {totals['selected_paragraphs']} 个非空段落、{totals['tables']} 张表({totals['table_rows']} 行)。",
403
+ f"未选项目跳过 {totals['skipped_paragraphs']} 个段落、{totals['skipped_tables']} 张表;"
404
+ f"异常大纲段落保持原样 {totals['protected_paragraphs']} 个;空段落保留 {totals['empty_paragraphs']} 个。",
405
+ "",
406
+ ])
407
+ selected_roles = [item for item in result["roles"] if item["selected"]]
408
+ if selected_roles:
409
+ lines.append("段落格式方案:")
410
+ for item in selected_roles:
411
+ lines.append(f"· {item['label']}:{item['selected_paragraphs']} 段;{item['format']}")
412
+ if result["scope"]["table_text"]:
413
+ lines.append(f"· 表格字体与字号:{result['table_format']}")
414
+ if result["scope"]["table_emphasis"]:
415
+ lines.append("· 表格强调:表头居中,数值右对齐,普通文字左对齐,表头和合计行加粗。")
416
+ if result["scope"]["table_borders"]:
417
+ lines.append(f"· 表格框线:{result['table_border_format']}")
418
+ if result["scope"]["table_text"]:
419
+ lines.append(f"· {result['small_table_policy']}")
420
+ if result["warnings"]:
421
+ lines.append("")
422
+ lines.append("提示:")
423
+ lines.extend(f"· {item}" for item in result["warnings"])
424
+ self.details.setPlainText("\n".join(lines))
425
+ self.status_label.setText("预演完成,未写入任何文件。确认无误后点“生成格式副本”。")
426
+
427
+ def refresh_button_state(self) -> None:
428
+ self.apply_button.setEnabled(self._scan_key is not None and self._result is not None and not self.ctx.busy)
429
+ self._update_profile_mode()
@@ -0,0 +1,92 @@
1
+ """内置使用说明书:章节导航与全文搜索。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from PySide6.QtCore import QTimer, Qt
6
+ from PySide6.QtWidgets import (
7
+ QHBoxLayout,
8
+ QLabel,
9
+ QLineEdit,
10
+ QListWidget,
11
+ QListWidgetItem,
12
+ QPushButton,
13
+ QSplitter,
14
+ QTextBrowser,
15
+ QVBoxLayout,
16
+ QWidget,
17
+ )
18
+
19
+ from ... import __version__
20
+ from ..manual import load_manual_text, manual_html, parse_manual
21
+ from ._page import BasePage
22
+
23
+
24
+ class HelpPage(BasePage):
25
+ title = "使用说明"
26
+ subtitle = "完整操作指南已内置,无需联网;选择左侧章节,或搜索关键词快速定位。"
27
+
28
+ def build(self, body: QWidget) -> None:
29
+ container = QWidget()
30
+ layout = QVBoxLayout(container)
31
+ layout.setContentsMargins(0, 0, 0, 0)
32
+ layout.setSpacing(8)
33
+
34
+ search_row = QWidget()
35
+ search_layout = QHBoxLayout(search_row)
36
+ search_layout.setContentsMargins(0, 0, 0, 0)
37
+ search_layout.setSpacing(8)
38
+ self.search_edit = QLineEdit()
39
+ self.search_edit.setObjectName("ManualSearch")
40
+ self.search_edit.setPlaceholderText("搜索说明书内容,回车查找下一处")
41
+ self.search_edit.returnPressed.connect(self._find_next)
42
+ search_layout.addWidget(self.search_edit, 1)
43
+ self.find_button = QPushButton("查找下一处")
44
+ self.find_button.clicked.connect(self._find_next)
45
+ search_layout.addWidget(self.find_button)
46
+ self.search_status = QLabel(f"当前版本 v{__version__}")
47
+ self.search_status.setObjectName("CardDesc")
48
+ search_layout.addWidget(self.search_status)
49
+ layout.addWidget(search_row)
50
+
51
+ splitter = QSplitter(Qt.Horizontal)
52
+ self.chapter_list = QListWidget()
53
+ self.chapter_list.setObjectName("ManualChapters")
54
+ self.chapter_list.setMaximumWidth(230)
55
+ self.chapter_list.currentRowChanged.connect(self._show_chapter)
56
+ self.browser = QTextBrowser()
57
+ self.browser.setObjectName("ManualView")
58
+ splitter.addWidget(self.chapter_list)
59
+ splitter.addWidget(self.browser)
60
+ splitter.setStretchFactor(0, 0)
61
+ splitter.setStretchFactor(1, 1)
62
+ splitter.setSizes([230, 620])
63
+ layout.addWidget(splitter, 1)
64
+
65
+ body.layout().insertWidget(body.layout().count() - 1, container)
66
+
67
+ try:
68
+ self.sections = parse_manual(load_manual_text())
69
+ self.browser.setHtml(manual_html(self.sections))
70
+ except OSError as exc:
71
+ self.sections = []
72
+ self.browser.setPlainText(f"说明书资源加载失败:{exc}")
73
+ for index, (title, _lines) in enumerate(self.sections):
74
+ item = QListWidgetItem(title)
75
+ item.setData(Qt.UserRole, f"chapter-{index}")
76
+ self.chapter_list.addItem(item)
77
+ if self.sections:
78
+ self.chapter_list.setCurrentRow(0)
79
+
80
+ def _show_chapter(self, row: int) -> None:
81
+ if row < 0 or row >= len(self.sections):
82
+ return
83
+ anchor = f"chapter-{row}"
84
+ QTimer.singleShot(0, lambda: self.browser.scrollToAnchor(anchor))
85
+
86
+ def _find_next(self) -> None:
87
+ query = self.search_edit.text().strip()
88
+ if not query:
89
+ self.search_status.setText("请输入要查找的关键词")
90
+ return
91
+ found = self.browser.find(query)
92
+ self.search_status.setText("已定位到下一处" if found else "未找到,请换个关键词")
@@ -0,0 +1,145 @@
1
+ """备份与回滚页:Word 与 Excel 的历史备份分开两栏列出,选中一键恢复(恢复前自动备份现状)。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from PySide6.QtCore import Qt
6
+ from PySide6.QtWidgets import (
7
+ QHBoxLayout,
8
+ QHeaderView,
9
+ QLabel,
10
+ QPushButton,
11
+ QTableWidget,
12
+ QTableWidgetItem,
13
+ QWidget,
14
+ )
15
+
16
+ from ... import api
17
+ from ...console import set_log_sink
18
+ from ...errors import SyncError
19
+ from ._page import BasePage
20
+
21
+
22
+ class HistoryPage(BasePage):
23
+ title = "备份与回滚"
24
+ subtitle = "浏览每次写盘前自动留下的历史版本,按时间点恢复;Word 与 Excel 分开列,可各自独立回滚。"
25
+
26
+ def build(self, body: QWidget) -> None:
27
+ card = self.card(body)
28
+ self.tip_label(
29
+ card,
30
+ "每次同步/回写写盘前,工具会把原文件备份到同目录 _backup(带时间戳)。这里列出这些历史版本,"
31
+ "选中某一行点「恢复」即可回滚到该时间点。恢复前会先把当前现状再备份一次,因此回滚本身也可逆。"
32
+ "恢复前请先关闭对应的 Word / Excel。",
33
+ )
34
+ row = QHBoxLayout()
35
+ refresh = QPushButton("刷新备份清单")
36
+ refresh.clicked.connect(lambda _checked=False: self._refresh())
37
+ row.addWidget(refresh)
38
+ row.addStretch(1)
39
+ card.layout().addLayout(row)
40
+ self.status = self.tip_label(card, "尚未加载。选择 Word 文件后点「刷新备份清单」。")
41
+
42
+ self.word_label = self.tip_label(card, "Word 报告备份")
43
+ self.word_table = self._make_table()
44
+ card.layout().addWidget(self.word_table)
45
+ self.word_restore = QPushButton("恢复选中的 Word 版本")
46
+ self.word_restore.setObjectName("Primary")
47
+ self.word_restore.clicked.connect(lambda _checked=False: self._restore("word"))
48
+ card.layout().addWidget(self.word_restore)
49
+
50
+ self.excel_label = self.tip_label(card, "Excel 工作簿备份")
51
+ self.excel_table = self._make_table()
52
+ card.layout().addWidget(self.excel_table)
53
+ self.excel_restore = QPushButton("恢复选中的 Excel 版本")
54
+ self.excel_restore.setObjectName("Primary")
55
+ self.excel_restore.clicked.connect(lambda _checked=False: self._restore("excel"))
56
+ card.layout().addWidget(self.excel_restore)
57
+
58
+ self._info: dict = {}
59
+ self._set_restore_enabled()
60
+
61
+ @staticmethod
62
+ def _make_table() -> QTableWidget:
63
+ table = QTableWidget(0, 3)
64
+ table.setHorizontalHeaderLabels(["备份时间", "文件名", "大小"])
65
+ table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
66
+ table.setSelectionBehavior(QTableWidget.SelectRows)
67
+ table.setSelectionMode(QTableWidget.SingleSelection)
68
+ table.setEditTriggers(QTableWidget.NoEditTriggers)
69
+ table.setMinimumHeight(140)
70
+ return table
71
+
72
+ def on_show(self) -> None:
73
+ if not self._info:
74
+ self._refresh(quiet=True)
75
+
76
+ def _set_restore_enabled(self) -> None:
77
+ self.word_restore.setEnabled(bool(self._info.get("word")))
78
+ self.excel_restore.setEnabled(bool(self._info.get("excel")))
79
+
80
+ def _refresh(self, quiet: bool = False) -> None:
81
+ self._info = {}
82
+ self.word_table.setRowCount(0)
83
+ self.excel_table.setRowCount(0)
84
+ if self.ctx.docx is None:
85
+ self.status.setText("尚未加载。请先在上方选择 Word 文件。")
86
+ self._set_restore_enabled()
87
+ return
88
+ set_log_sink(lambda message: self.ctx.log(message))
89
+ try:
90
+ self._info = api.scan_backups(self.ctx.docx, self.ctx.excel)
91
+ except SyncError as exc:
92
+ self.status.setText(f"加载失败:{exc}")
93
+ self._set_restore_enabled()
94
+ return
95
+ finally:
96
+ set_log_sink(None)
97
+ self._fill(self.word_table, self._info.get("word", []))
98
+ self._fill(self.excel_table, self._info.get("excel", []))
99
+ nw, ne = len(self._info.get("word", [])), len(self._info.get("excel", []))
100
+ self.word_label.setText(f"Word 报告备份({nw} 个):{self._info.get('word_path', '')}")
101
+ self.excel_label.setText(f"Excel 工作簿备份({ne} 个):{self._info.get('excel_path', '')}")
102
+ self.status.setText(f"Word 历史版本 {nw} 个、Excel 历史版本 {ne} 个。选中一行后点「恢复」。")
103
+ self._set_restore_enabled()
104
+ if not quiet:
105
+ self.ctx.log("备份清单已刷新。", "muted")
106
+
107
+ @staticmethod
108
+ def _fill(table: QTableWidget, items: list[dict]) -> None:
109
+ table.setRowCount(0)
110
+ for item in items:
111
+ row = table.rowCount()
112
+ table.insertRow(row)
113
+ size_kb = f"{item['size'] / 1024:.1f} KB"
114
+ for c, value in enumerate([item["time"], item["file"], size_kb]):
115
+ cell = QTableWidgetItem(str(value))
116
+ if c == 0:
117
+ cell.setData(Qt.UserRole, item["path"])
118
+ table.setItem(row, c, cell)
119
+
120
+ def _restore(self, which: str) -> None:
121
+ table = self.word_table if which == "word" else self.excel_table
122
+ target = self._info.get("word_path" if which == "word" else "excel_path", "")
123
+ rows = table.selectionModel().selectedRows()
124
+ if not rows:
125
+ self.ctx.info("未选择版本", "请先在列表里选中要恢复的历史版本。")
126
+ return
127
+ row = rows[0].row()
128
+ backup = table.item(row, 0).data(Qt.UserRole)
129
+ time_text = table.item(row, 0).text()
130
+ label = "Word 报告" if which == "word" else "Excel 工作簿"
131
+ if not self.ctx.confirm(
132
+ "确认回滚",
133
+ f"将把{label}恢复到 {time_text} 的版本:\n\n目标:{target}\n备份:{backup}\n\n"
134
+ "恢复前会先把当前现状再备份一次(可再次回滚)。请先关闭该文件。确认恢复?",
135
+ ):
136
+ return
137
+ set_log_sink(lambda message: self.ctx.log(message))
138
+ try:
139
+ api.run_restore_backup(backup, target)
140
+ except SyncError as exc:
141
+ self.ctx.error("回滚失败", str(exc))
142
+ return
143
+ finally:
144
+ set_log_sink(None)
145
+ self._refresh(quiet=True)