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,158 @@
|
|
|
1
|
+
"""内置使用说明书:章节导航与全文搜索。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
from PySide6.QtCore import QTimer, Qt
|
|
8
|
+
from PySide6.QtWidgets import (
|
|
9
|
+
QHBoxLayout,
|
|
10
|
+
QLabel,
|
|
11
|
+
QLineEdit,
|
|
12
|
+
QListWidget,
|
|
13
|
+
QListWidgetItem,
|
|
14
|
+
QPushButton,
|
|
15
|
+
QSizePolicy,
|
|
16
|
+
QSplitter,
|
|
17
|
+
QTextBrowser,
|
|
18
|
+
QVBoxLayout,
|
|
19
|
+
QWidget,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
from ... import __version__
|
|
23
|
+
from ..manual import load_manual_text, manual_html, parse_manual
|
|
24
|
+
from ._page import BasePage
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# 章节标题里括号中的补充说明(如「(「标注与占位」页,两个 tab)」)在窄列表里
|
|
28
|
+
# 只会挤成省略号,列表里只留主干,完整标题放进 tooltip 与右侧正文。
|
|
29
|
+
_PAREN_TAIL_RE = re.compile(r"[((][^))]*[))]\s*$")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _short_title(title: str) -> str:
|
|
33
|
+
"""去掉章节标题末尾的括号补充说明,保留主干用于左侧目录。"""
|
|
34
|
+
text = (title or "").strip()
|
|
35
|
+
stripped = _PAREN_TAIL_RE.sub("", text).strip()
|
|
36
|
+
return stripped or text
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class HelpPage(BasePage):
|
|
40
|
+
title = "使用说明"
|
|
41
|
+
subtitle = f"内置完整指南 v{__version__};按章节浏览或搜索关键词。"
|
|
42
|
+
CONTENT_MAX_WIDTH = None
|
|
43
|
+
FILL_HEIGHT = True
|
|
44
|
+
|
|
45
|
+
def build(self, body: QWidget) -> None:
|
|
46
|
+
container = QWidget()
|
|
47
|
+
layout = QVBoxLayout(container)
|
|
48
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
49
|
+
layout.setSpacing(8)
|
|
50
|
+
|
|
51
|
+
search_row = QWidget()
|
|
52
|
+
search_layout = QHBoxLayout(search_row)
|
|
53
|
+
search_layout.setContentsMargins(0, 0, 0, 0)
|
|
54
|
+
search_layout.setSpacing(8)
|
|
55
|
+
self.search_edit = QLineEdit()
|
|
56
|
+
self.search_edit.setObjectName("ManualSearch")
|
|
57
|
+
self.search_edit.setPlaceholderText("搜索说明书内容,回车查找下一处;点「问 AI」可让 AI 依据说明书回答")
|
|
58
|
+
self.search_edit.returnPressed.connect(self._find_next)
|
|
59
|
+
search_layout.addWidget(self.search_edit, 1)
|
|
60
|
+
self.find_button = QPushButton("查找下一处")
|
|
61
|
+
self.find_button.clicked.connect(self._find_next)
|
|
62
|
+
search_layout.addWidget(self.find_button)
|
|
63
|
+
self.search_status = QLabel()
|
|
64
|
+
self.search_status.setObjectName("CardDesc")
|
|
65
|
+
search_layout.addWidget(self.search_status)
|
|
66
|
+
self.ask_button = QPushButton("问 AI")
|
|
67
|
+
self.ask_button.setToolTip("把搜索框里的话当成问题,让 AI 依据说明书回答")
|
|
68
|
+
self.ask_button.clicked.connect(lambda _checked=False: self._ask_ai())
|
|
69
|
+
search_layout.addWidget(self.ask_button)
|
|
70
|
+
layout.addWidget(search_row)
|
|
71
|
+
|
|
72
|
+
splitter = QSplitter(Qt.Horizontal)
|
|
73
|
+
self.chapter_list = QListWidget()
|
|
74
|
+
self.chapter_list.setObjectName("ManualChapters")
|
|
75
|
+
self.chapter_list.setMinimumWidth(200)
|
|
76
|
+
self.chapter_list.setMaximumWidth(300)
|
|
77
|
+
# 章节标题较长(如「八、标注与占位(「标注与占位」页,两个 tab)」),
|
|
78
|
+
# 不换行会被截断成「…」还带横向滚动条;这里允许换行并隐藏横条。
|
|
79
|
+
self.chapter_list.setWordWrap(True)
|
|
80
|
+
self.chapter_list.setTextElideMode(Qt.ElideNone)
|
|
81
|
+
self.chapter_list.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
|
|
82
|
+
self.chapter_list.currentRowChanged.connect(self._show_chapter)
|
|
83
|
+
self.browser = QTextBrowser()
|
|
84
|
+
self.browser.setObjectName("ManualView")
|
|
85
|
+
splitter.addWidget(self.chapter_list)
|
|
86
|
+
splitter.addWidget(self.browser)
|
|
87
|
+
splitter.setStretchFactor(0, 0)
|
|
88
|
+
splitter.setStretchFactor(1, 1)
|
|
89
|
+
splitter.setSizes([240, 880])
|
|
90
|
+
# 关键:让分栏区吃掉全部剩余高度,否则下方留大片空白
|
|
91
|
+
splitter.setChildrenCollapsible(False)
|
|
92
|
+
layout.addWidget(splitter, 1)
|
|
93
|
+
|
|
94
|
+
body.layout().insertWidget(body.layout().count(), container, 1)
|
|
95
|
+
container.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
|
|
96
|
+
|
|
97
|
+
try:
|
|
98
|
+
self.sections = parse_manual(load_manual_text())
|
|
99
|
+
self.browser.setHtml(manual_html(self.sections))
|
|
100
|
+
except OSError as exc:
|
|
101
|
+
self.sections = []
|
|
102
|
+
self.browser.setPlainText(f"说明书资源加载失败:{exc}")
|
|
103
|
+
for index, (title, _lines) in enumerate(self.sections):
|
|
104
|
+
item = QListWidgetItem(_short_title(title))
|
|
105
|
+
item.setData(Qt.UserRole, f"chapter-{index}")
|
|
106
|
+
item.setToolTip(title)
|
|
107
|
+
self.chapter_list.addItem(item)
|
|
108
|
+
if self.sections:
|
|
109
|
+
self.chapter_list.setCurrentRow(0)
|
|
110
|
+
|
|
111
|
+
def refresh_theme(self) -> None:
|
|
112
|
+
if not self.sections:
|
|
113
|
+
return
|
|
114
|
+
scroll = self.browser.verticalScrollBar().value()
|
|
115
|
+
query = self.search_edit.text().strip()
|
|
116
|
+
self.browser.setHtml(manual_html(self.sections))
|
|
117
|
+
if query:
|
|
118
|
+
self.browser.find(query)
|
|
119
|
+
QTimer.singleShot(0, lambda: self.browser.verticalScrollBar().setValue(scroll))
|
|
120
|
+
|
|
121
|
+
def _show_chapter(self, row: int) -> None:
|
|
122
|
+
if row < 0 or row >= len(self.sections):
|
|
123
|
+
return
|
|
124
|
+
anchor = f"chapter-{row}"
|
|
125
|
+
QTimer.singleShot(0, lambda: self.browser.scrollToAnchor(anchor))
|
|
126
|
+
|
|
127
|
+
def _find_next(self) -> None:
|
|
128
|
+
query = self.search_edit.text().strip()
|
|
129
|
+
if not query:
|
|
130
|
+
self.search_status.setText("请输入要查找的关键词")
|
|
131
|
+
return
|
|
132
|
+
found = self.browser.find(query)
|
|
133
|
+
self.search_status.setText("已定位到下一处" if found else "未找到,请换个关键词")
|
|
134
|
+
|
|
135
|
+
def _ask_ai(self) -> None:
|
|
136
|
+
"""把搜索框内容当问题,转到 AI 助手的「对话助手」标签页。
|
|
137
|
+
|
|
138
|
+
不在本页内联问答:说明书页要保持"离线可读",AI 只作为可选跳转。
|
|
139
|
+
"""
|
|
140
|
+
question = self.search_edit.text().strip()
|
|
141
|
+
page = self.ctx.page("AiPage")
|
|
142
|
+
if page is None:
|
|
143
|
+
self.ctx.error("无法打开", "找不到「AI 助手」页。")
|
|
144
|
+
return
|
|
145
|
+
self.ctx.go_to_page("AiPage")
|
|
146
|
+
page.tabs.setCurrentIndex(1) # 对话助手(配置已移到全局设置,现在是第 2 个标签)
|
|
147
|
+
if question:
|
|
148
|
+
page.ask_edit.setPlainText(question)
|
|
149
|
+
page.ask_edit.setFocus()
|
|
150
|
+
self.ctx.info(
|
|
151
|
+
"已转到 AI 助手的「对话助手」",
|
|
152
|
+
f"问题「{question}」已填入输入框。\n\n点「问这个软件怎么用」即可依据说明书回答。",
|
|
153
|
+
)
|
|
154
|
+
else:
|
|
155
|
+
self.ctx.info(
|
|
156
|
+
"已转到 AI 助手的「对话助手」",
|
|
157
|
+
"在输入框写下你的问题,然后点「问这个软件怎么用」。",
|
|
158
|
+
)
|
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
QPushButton,
|
|
10
|
+
QTableWidget,
|
|
11
|
+
QTableWidgetItem,
|
|
12
|
+
QWidget,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
from ... import api
|
|
16
|
+
from ...console import set_log_sink
|
|
17
|
+
from ...errors import SyncError
|
|
18
|
+
from ..widgets.cards import make_checkbutton
|
|
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;选中版本可恢复。恢复前请关闭对应 Word / Excel。",
|
|
31
|
+
)
|
|
32
|
+
row = QHBoxLayout()
|
|
33
|
+
refresh = QPushButton("刷新备份清单")
|
|
34
|
+
refresh.clicked.connect(lambda _checked=False: self._refresh())
|
|
35
|
+
row.addWidget(refresh)
|
|
36
|
+
row.addStretch(1)
|
|
37
|
+
card.layout().addLayout(row)
|
|
38
|
+
self.safety_backup = make_checkbutton(card, "回滚前自动备份当前文件", True)
|
|
39
|
+
card.layout().addWidget(self.safety_backup)
|
|
40
|
+
self.bind_defaults(card.layout(), {"auto_backup": self.safety_backup})
|
|
41
|
+
self.status = self.tip_label(card, "尚未加载。选择 Word 文件后点「刷新备份清单」。")
|
|
42
|
+
|
|
43
|
+
self.word_label = self.tip_label(card, "Word 报告备份")
|
|
44
|
+
self.word_table = self._make_table()
|
|
45
|
+
card.layout().addWidget(self.word_table)
|
|
46
|
+
self.word_restore = QPushButton("恢复选中的 Word 版本")
|
|
47
|
+
self.word_restore.setObjectName("Primary")
|
|
48
|
+
self.word_restore.clicked.connect(lambda _checked=False: self._restore("word"))
|
|
49
|
+
card.layout().addWidget(self.word_restore)
|
|
50
|
+
|
|
51
|
+
self.excel_label = self.tip_label(card, "Excel 工作簿备份")
|
|
52
|
+
self.excel_table = self._make_table()
|
|
53
|
+
card.layout().addWidget(self.excel_table)
|
|
54
|
+
self.excel_restore = QPushButton("恢复选中的 Excel 版本")
|
|
55
|
+
self.excel_restore.setObjectName("Primary")
|
|
56
|
+
self.excel_restore.clicked.connect(lambda _checked=False: self._restore("excel"))
|
|
57
|
+
card.layout().addWidget(self.excel_restore)
|
|
58
|
+
|
|
59
|
+
self._info: dict = {}
|
|
60
|
+
self._file_key: tuple[str | None, str | None] | None = None
|
|
61
|
+
self._set_restore_enabled()
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def _make_table() -> QTableWidget:
|
|
65
|
+
table = QTableWidget(0, 3)
|
|
66
|
+
table.setHorizontalHeaderLabels(["备份时间", "文件名", "大小"])
|
|
67
|
+
table.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
|
|
68
|
+
table.setSelectionBehavior(QTableWidget.SelectRows)
|
|
69
|
+
table.setSelectionMode(QTableWidget.SingleSelection)
|
|
70
|
+
table.setEditTriggers(QTableWidget.NoEditTriggers)
|
|
71
|
+
table.setMinimumHeight(140)
|
|
72
|
+
return table
|
|
73
|
+
|
|
74
|
+
def on_show(self) -> None:
|
|
75
|
+
super().on_show()
|
|
76
|
+
key = (
|
|
77
|
+
str(self.ctx.docx) if self.ctx.docx is not None else None,
|
|
78
|
+
str(self.ctx.excel) if self.ctx.excel is not None else None,
|
|
79
|
+
)
|
|
80
|
+
if key != self._file_key:
|
|
81
|
+
self._file_key = key
|
|
82
|
+
self._refresh(quiet=True)
|
|
83
|
+
|
|
84
|
+
def _set_restore_enabled(self) -> None:
|
|
85
|
+
self.word_restore.setEnabled(bool(self._info.get("word")))
|
|
86
|
+
self.excel_restore.setEnabled(bool(self._info.get("excel")))
|
|
87
|
+
|
|
88
|
+
def _refresh(self, quiet: bool = False) -> None:
|
|
89
|
+
self._file_key = (
|
|
90
|
+
str(self.ctx.docx) if self.ctx.docx is not None else None,
|
|
91
|
+
str(self.ctx.excel) if self.ctx.excel is not None else None,
|
|
92
|
+
)
|
|
93
|
+
self._info = {}
|
|
94
|
+
self.word_table.setRowCount(0)
|
|
95
|
+
self.excel_table.setRowCount(0)
|
|
96
|
+
if self.ctx.docx is None:
|
|
97
|
+
self.status.setText("尚未加载。请先在上方选择 Word 文件。")
|
|
98
|
+
self._set_restore_enabled()
|
|
99
|
+
return
|
|
100
|
+
set_log_sink(lambda message: self.ctx.log(message))
|
|
101
|
+
try:
|
|
102
|
+
self._info = api.scan_backups(self.ctx.docx, self.ctx.excel)
|
|
103
|
+
except Exception as exc:
|
|
104
|
+
self.status.setText(f"加载失败:{exc}")
|
|
105
|
+
self._set_restore_enabled()
|
|
106
|
+
return
|
|
107
|
+
finally:
|
|
108
|
+
set_log_sink(None)
|
|
109
|
+
self._fill(self.word_table, self._info.get("word", []))
|
|
110
|
+
self._fill(self.excel_table, self._info.get("excel", []))
|
|
111
|
+
nw, ne = len(self._info.get("word", [])), len(self._info.get("excel", []))
|
|
112
|
+
self.word_label.setText(f"Word 报告备份({nw} 个)")
|
|
113
|
+
self.word_label.setToolTip(self._info.get("word_path", ""))
|
|
114
|
+
self.excel_label.setText(f"Excel 工作簿备份({ne} 个)")
|
|
115
|
+
self.excel_label.setToolTip(self._info.get("excel_path", ""))
|
|
116
|
+
self.status.setText(f"Word 历史版本 {nw} 个、Excel 历史版本 {ne} 个。选中一行后点「恢复」。")
|
|
117
|
+
self._set_restore_enabled()
|
|
118
|
+
if not quiet:
|
|
119
|
+
self.ctx.log("备份清单已刷新。", "muted")
|
|
120
|
+
|
|
121
|
+
@staticmethod
|
|
122
|
+
def _fill(table: QTableWidget, items: list[dict]) -> None:
|
|
123
|
+
table.setRowCount(0)
|
|
124
|
+
for item in items:
|
|
125
|
+
row = table.rowCount()
|
|
126
|
+
table.insertRow(row)
|
|
127
|
+
size_kb = f"{item['size'] / 1024:.1f} KB"
|
|
128
|
+
for c, value in enumerate([item["time"], item["file"], size_kb]):
|
|
129
|
+
cell = QTableWidgetItem(str(value))
|
|
130
|
+
if c == 0:
|
|
131
|
+
cell.setData(Qt.UserRole, item["path"])
|
|
132
|
+
table.setItem(row, c, cell)
|
|
133
|
+
|
|
134
|
+
def _restore(self, which: str) -> None:
|
|
135
|
+
expected = self.ctx.docx if which == "word" else self.ctx.excel
|
|
136
|
+
if expected is None or str(expected) != self._info.get(f"{which}_path"):
|
|
137
|
+
self.ctx.error("文件已切换", "当前文件与备份清单不一致,请刷新清单后重试。")
|
|
138
|
+
self._refresh(quiet=True)
|
|
139
|
+
return
|
|
140
|
+
table = self.word_table if which == "word" else self.excel_table
|
|
141
|
+
target = self._info.get("word_path" if which == "word" else "excel_path", "")
|
|
142
|
+
rows = table.selectionModel().selectedRows()
|
|
143
|
+
if not rows:
|
|
144
|
+
self.ctx.info("未选择版本", "请先在列表里选中要恢复的历史版本。")
|
|
145
|
+
return
|
|
146
|
+
row = rows[0].row()
|
|
147
|
+
backup = table.item(row, 0).data(Qt.UserRole)
|
|
148
|
+
time_text = table.item(row, 0).text()
|
|
149
|
+
label = "Word 报告" if which == "word" else "Excel 工作簿"
|
|
150
|
+
if not self.ctx.confirm(
|
|
151
|
+
"确认回滚",
|
|
152
|
+
f"将把{label}恢复到 {time_text} 的版本:\n\n目标:{target}\n备份:{backup}\n\n"
|
|
153
|
+
+ ("恢复前会先把当前现状再备份一次(可再次回滚)。" if self.safety_backup.isChecked()
|
|
154
|
+
else "本次已取消回滚前备份。")
|
|
155
|
+
+ "请先关闭该文件。确认恢复?",
|
|
156
|
+
):
|
|
157
|
+
return
|
|
158
|
+
set_log_sink(lambda message: self.ctx.log(message))
|
|
159
|
+
try:
|
|
160
|
+
api.run_restore_backup(
|
|
161
|
+
backup, target, safety_backup=self.safety_backup.isChecked()
|
|
162
|
+
)
|
|
163
|
+
except SyncError as exc:
|
|
164
|
+
self.ctx.error("回滚失败", str(exc))
|
|
165
|
+
return
|
|
166
|
+
finally:
|
|
167
|
+
set_log_sink(None)
|
|
168
|
+
self._refresh(quiet=True)
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"""标注与占位页:链接标注(高亮标记)与正文 {字段名} 占位符的导出/同步。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from PySide6.QtWidgets import QTabWidget, QVBoxLayout, QWidget
|
|
6
|
+
|
|
7
|
+
from ... import api
|
|
8
|
+
from ..widgets.cards import make_action_bar, make_checkbutton
|
|
9
|
+
from ..widgets.chips import ChipRow
|
|
10
|
+
from ._page import BasePage
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MarksPage(BasePage):
|
|
14
|
+
title = "标注与占位"
|
|
15
|
+
subtitle = "高亮标注与正文 {字段名} 占位符:导出到 Excel,填好后一键写回。"
|
|
16
|
+
|
|
17
|
+
def build(self, body: QWidget) -> None:
|
|
18
|
+
card = self.card(body)
|
|
19
|
+
tabs = QTabWidget()
|
|
20
|
+
card.layout().addWidget(tabs)
|
|
21
|
+
tabs.addTab(self._build_marks_tab(), "链接标注")
|
|
22
|
+
tabs.addTab(self._build_placeholder_tab(), "正文占位符")
|
|
23
|
+
|
|
24
|
+
# ---------- 链接标注 tab ----------
|
|
25
|
+
|
|
26
|
+
def _build_marks_tab(self) -> QWidget:
|
|
27
|
+
tab = QWidget()
|
|
28
|
+
layout = QVBoxLayout(tab)
|
|
29
|
+
layout.setContentsMargins(12, 12, 12, 12)
|
|
30
|
+
layout.setSpacing(10)
|
|
31
|
+
self.options = ChipRow([
|
|
32
|
+
("keep_highlight", "保留标注高亮", True, "便于人工复核"),
|
|
33
|
+
("backup", "同步前备份", True, "关闭则直接覆盖", True),
|
|
34
|
+
])
|
|
35
|
+
tab.layout().addWidget(self.options)
|
|
36
|
+
self.keep_highlight = self.options["keep_highlight"]
|
|
37
|
+
self.marks_backup = self.options["backup"]
|
|
38
|
+
mark_controls = {}
|
|
39
|
+
self.bind_defaults(layout, {
|
|
40
|
+
"keep_highlight": self.keep_highlight,
|
|
41
|
+
"auto_backup": self.marks_backup,
|
|
42
|
+
}, [("标注", "mark_zero")], mark_controls)
|
|
43
|
+
self.mark_zero = mark_controls["mark_zero"]
|
|
44
|
+
layout.addWidget(self._marks_buttons())
|
|
45
|
+
layout.addStretch(1)
|
|
46
|
+
return tab
|
|
47
|
+
|
|
48
|
+
def _marks_buttons(self) -> QWidget:
|
|
49
|
+
return make_action_bar(
|
|
50
|
+
self,
|
|
51
|
+
"开始同步",
|
|
52
|
+
lambda: self._sync_marks(False),
|
|
53
|
+
secondary=[
|
|
54
|
+
("导出/刷新标注", self._export_marks),
|
|
55
|
+
("仅预演同步", lambda: self._sync_marks(True)),
|
|
56
|
+
],
|
|
57
|
+
primary_index=2,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
def _export_marks(self) -> None:
|
|
61
|
+
if not self.ctx.require_docx():
|
|
62
|
+
return
|
|
63
|
+
docx, custom_excel = self.ctx.docx, self.ctx.excel
|
|
64
|
+
backup = self.marks_backup.isChecked()
|
|
65
|
+
links = self.ctx.global_settings()["excel_links"]
|
|
66
|
+
totals = self.ctx.global_settings()["totals_formula"]
|
|
67
|
+
xlsx = api.workbook_path(docx, custom_excel)
|
|
68
|
+
if xlsx.exists():
|
|
69
|
+
steps = [("导出/刷新标注", lambda: api.run_marks(docx, custom_excel, backup=backup))]
|
|
70
|
+
else:
|
|
71
|
+
if not self.ctx.confirm(
|
|
72
|
+
"尚未生成工作簿",
|
|
73
|
+
f"未找到工作簿:\n{xlsx}\n\n是否现在先执行一次完整导出(表格 + 链接标注)?",
|
|
74
|
+
):
|
|
75
|
+
self.ctx.log("已取消导出。", "muted")
|
|
76
|
+
return
|
|
77
|
+
steps = [("导出表格到 Excel(含链接标注)", lambda: api.run_export(
|
|
78
|
+
docx, custom_excel, backup=backup,
|
|
79
|
+
with_excel_links=links, totals_formula=totals,
|
|
80
|
+
))]
|
|
81
|
+
self.ctx.run_steps(steps)
|
|
82
|
+
|
|
83
|
+
def _sync_marks(self, dry_run: bool) -> None:
|
|
84
|
+
if not self.ctx.require_docx():
|
|
85
|
+
return
|
|
86
|
+
docx, custom_excel = self.ctx.docx, self.ctx.excel
|
|
87
|
+
xlsx = api.workbook_path(docx, custom_excel)
|
|
88
|
+
keep_highlight = self.keep_highlight.isChecked()
|
|
89
|
+
backup = self.marks_backup.isChecked()
|
|
90
|
+
mark_zero = self.mark_zero.currentData()
|
|
91
|
+
if not xlsx.exists():
|
|
92
|
+
self.ctx.log(f"未找到工作簿:{xlsx}\n请先执行“导出/刷新标注”。", "error")
|
|
93
|
+
return
|
|
94
|
+
if not dry_run:
|
|
95
|
+
message = (
|
|
96
|
+
f"将把「链接标注」工作表里填写的内容写回 Word:\n\nWord:{docx}\nExcel:{xlsx}\n\n"
|
|
97
|
+
+ ("同步后保留高亮。\n" if keep_highlight else "同步后自动去掉该处高亮。\n")
|
|
98
|
+
+ "\n"
|
|
99
|
+
+ ("写盘前会自动备份,确认开始同步?" if backup else "本次已取消备份,确认开始同步?")
|
|
100
|
+
)
|
|
101
|
+
if not self.ctx.confirm("确认同步标注", message):
|
|
102
|
+
self.ctx.log("已取消标注同步。", "muted")
|
|
103
|
+
return
|
|
104
|
+
self.ctx.run_steps(
|
|
105
|
+
[
|
|
106
|
+
(
|
|
107
|
+
("同步标注(预演)" if dry_run else "同步标注") + ("·保留高亮" if keep_highlight else ""),
|
|
108
|
+
lambda: api.run_marks_sync(
|
|
109
|
+
docx, custom_excel,
|
|
110
|
+
dry_run=dry_run,
|
|
111
|
+
keep_highlight=keep_highlight,
|
|
112
|
+
backup=backup, mark_zero=mark_zero,
|
|
113
|
+
),
|
|
114
|
+
)
|
|
115
|
+
]
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# ---------- 正文占位符 tab ----------
|
|
119
|
+
|
|
120
|
+
def _build_placeholder_tab(self) -> QWidget:
|
|
121
|
+
tab = QWidget()
|
|
122
|
+
layout = QVBoxLayout(tab)
|
|
123
|
+
layout.setContentsMargins(12, 12, 12, 12)
|
|
124
|
+
layout.setSpacing(10)
|
|
125
|
+
self.placeholder_backup = make_checkbutton(tab, "同步前备份;关闭则直接覆盖", True)
|
|
126
|
+
layout.addWidget(self.placeholder_backup)
|
|
127
|
+
placeholder_controls = {}
|
|
128
|
+
self.bind_defaults(
|
|
129
|
+
layout,
|
|
130
|
+
{"auto_backup": self.placeholder_backup},
|
|
131
|
+
[("占位符", "placeholder_zero")],
|
|
132
|
+
placeholder_controls,
|
|
133
|
+
)
|
|
134
|
+
self.placeholder_zero = placeholder_controls["placeholder_zero"]
|
|
135
|
+
self.tip_label(
|
|
136
|
+
tab,
|
|
137
|
+
"导出 {字段名} 到「正文信息」,填写后同步;未填保留并警告。该表与模板生成共用。",
|
|
138
|
+
)
|
|
139
|
+
actions = make_action_bar(
|
|
140
|
+
tab,
|
|
141
|
+
"开始同步",
|
|
142
|
+
lambda: self._sync_placeholders(False),
|
|
143
|
+
secondary=[
|
|
144
|
+
("导出/刷新占位符", self._export_placeholders),
|
|
145
|
+
("仅预演同步", lambda: self._sync_placeholders(True)),
|
|
146
|
+
],
|
|
147
|
+
primary_index=2,
|
|
148
|
+
)
|
|
149
|
+
layout.addWidget(actions)
|
|
150
|
+
layout.addStretch(1)
|
|
151
|
+
return tab
|
|
152
|
+
|
|
153
|
+
def _export_placeholders(self) -> None:
|
|
154
|
+
if not self.ctx.require_docx():
|
|
155
|
+
return
|
|
156
|
+
docx, custom_excel = self.ctx.docx, self.ctx.excel
|
|
157
|
+
backup = self.placeholder_backup.isChecked()
|
|
158
|
+
links = self.ctx.global_settings()["excel_links"]
|
|
159
|
+
totals = self.ctx.global_settings()["totals_formula"]
|
|
160
|
+
xlsx = api.workbook_path(docx, custom_excel)
|
|
161
|
+
if xlsx.exists():
|
|
162
|
+
steps = [("导出/刷新占位符", lambda: api.run_placeholder_export(docx, custom_excel, backup=backup))]
|
|
163
|
+
else:
|
|
164
|
+
if not self.ctx.confirm(
|
|
165
|
+
"尚未生成工作簿",
|
|
166
|
+
f"未找到工作簿:\n{xlsx}\n\n是否现在先执行一次完整导出(表格 + 链接标注),再补齐占位符骨架?",
|
|
167
|
+
):
|
|
168
|
+
self.ctx.log("已取消导出。", "muted")
|
|
169
|
+
return
|
|
170
|
+
steps = [
|
|
171
|
+
("导出表格到 Excel(含链接标注)", lambda: api.run_export(
|
|
172
|
+
docx, custom_excel, backup=backup,
|
|
173
|
+
with_excel_links=links, totals_formula=totals,
|
|
174
|
+
)),
|
|
175
|
+
("导出/刷新占位符", lambda: api.run_placeholder_export(
|
|
176
|
+
docx, custom_excel, backup=backup,
|
|
177
|
+
)),
|
|
178
|
+
]
|
|
179
|
+
self.ctx.run_steps(steps)
|
|
180
|
+
|
|
181
|
+
def _sync_placeholders(self, dry_run: bool) -> None:
|
|
182
|
+
if not self.ctx.require_docx():
|
|
183
|
+
return
|
|
184
|
+
docx, custom_excel = self.ctx.docx, self.ctx.excel
|
|
185
|
+
xlsx = api.workbook_path(docx, custom_excel)
|
|
186
|
+
backup = self.placeholder_backup.isChecked()
|
|
187
|
+
placeholder_zero = self.placeholder_zero.currentData()
|
|
188
|
+
if not xlsx.exists():
|
|
189
|
+
self.ctx.log(f"未找到工作簿:{xlsx}\n请先执行“导出/刷新占位符”。", "error")
|
|
190
|
+
return
|
|
191
|
+
if not dry_run:
|
|
192
|
+
message = (
|
|
193
|
+
f"将按「正文信息」表填写的值替换 Word 里的 {{字段名}} 占位符:\n\n"
|
|
194
|
+
f"Word:{docx}\nExcel:{xlsx}\n\n"
|
|
195
|
+
"未填值的占位符保留原样并逐条警告。\n"
|
|
196
|
+
+ ("写盘前会自动备份,确认开始同步?" if backup else "本次已取消备份,确认开始同步?")
|
|
197
|
+
)
|
|
198
|
+
if not self.ctx.confirm("确认同步占位符", message):
|
|
199
|
+
self.ctx.log("已取消占位符同步。", "muted")
|
|
200
|
+
return
|
|
201
|
+
self.ctx.run_steps(
|
|
202
|
+
[
|
|
203
|
+
(
|
|
204
|
+
"同步占位符(预演)" if dry_run else "同步占位符",
|
|
205
|
+
lambda: api.run_placeholder_sync(
|
|
206
|
+
docx, custom_excel, dry_run=dry_run,
|
|
207
|
+
backup=backup, placeholder_zero=placeholder_zero,
|
|
208
|
+
),
|
|
209
|
+
)
|
|
210
|
+
]
|
|
211
|
+
)
|