audit-e2w 1.11.2 → 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/README.md +152 -148
- package/dsh_plugins/audit-e2w/lib/index.js +9 -1
- package/dsh_plugins/audit-e2w/lib/skill.js +3 -2
- package/excel_word/README.md +45 -37
- package/excel_word/qoder_engine.py +10 -11
- package/excel_word/wesync/__init__.py +1 -1
- 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 +1 -0
- package/excel_word/wesync/api.py +544 -92
- package/excel_word/wesync/backup_history.py +44 -9
- package/excel_word/wesync/cli.py +19 -1
- package/excel_word/wesync/commands/blank_cmd.py +59 -30
- package/excel_word/wesync/commands/bookmark_cmd.py +41 -10
- package/excel_word/wesync/commands/clear_cmd.py +5 -3
- package/excel_word/wesync/commands/export_cmd.py +270 -220
- package/excel_word/wesync/commands/incremental_cmd.py +157 -0
- package/excel_word/wesync/commands/marks_cmd.py +24 -16
- package/excel_word/wesync/commands/placeholders_cmd.py +12 -7
- package/excel_word/wesync/commands/writeback_cmd.py +72 -116
- package/excel_word/wesync/config.py +3 -2
- package/excel_word/wesync/console.py +9 -2
- package/excel_word/wesync/docx_bookmarks.py +12 -5
- package/excel_word/wesync/docx_columns.py +1 -1
- package/excel_word/wesync/docx_marks.py +183 -75
- package/excel_word/wesync/docx_placeholders.py +65 -26
- package/excel_word/wesync/excel_blocks.py +144 -185
- package/excel_word/wesync/excel_export.py +15 -8
- package/excel_word/wesync/excel_marks.py +265 -193
- package/excel_word/wesync/fsops.py +11 -6
- package/excel_word/wesync/gui/__init__.py +21 -2
- package/excel_word/wesync/gui/app.py +243 -29
- package/excel_word/wesync/gui/manual.py +5 -3
- package/excel_word/wesync/gui/pages/__init__.py +53 -4
- package/excel_word/wesync/gui/pages/_page.py +129 -7
- package/excel_word/wesync/gui/pages/ai_page.py +854 -0
- package/excel_word/wesync/gui/pages/batch_page.py +64 -31
- package/excel_word/wesync/gui/pages/blank_page.py +529 -464
- package/excel_word/wesync/gui/pages/bookmark_page.py +97 -37
- package/excel_word/wesync/gui/pages/export_page.py +140 -87
- package/excel_word/wesync/gui/pages/feedback_page.py +196 -0
- package/excel_word/wesync/gui/pages/format_page.py +551 -429
- package/excel_word/wesync/gui/pages/help_page.py +73 -7
- package/excel_word/wesync/gui/pages/history_page.py +167 -144
- package/excel_word/wesync/gui/pages/marks_page.py +210 -177
- package/excel_word/wesync/gui/pages/settings_page.py +450 -0
- package/excel_word/wesync/gui/pages/writeback_page.py +167 -146
- package/excel_word/wesync/gui/runner.py +29 -13
- package/excel_word/wesync/gui/store.py +23 -7
- package/excel_word/wesync/gui/theme.py +220 -49
- package/excel_word/wesync/gui/widgets/ai_config.py +362 -0
- package/excel_word/wesync/gui/widgets/cards.py +124 -5
- package/excel_word/wesync/gui/widgets/chips.py +565 -0
- package/excel_word/wesync/gui/widgets/filebar.py +1 -1
- package/excel_word/wesync/gui/widgets/logpane.py +24 -8
- package/excel_word/wesync/gui/widgets/nav.py +267 -12
- package/excel_word/wesync/gui/widgets/theme_choice.py +93 -0
- package/excel_word/wesync/report_format.py +9 -1
- package/excel_word/wesync/settings.py +35 -0
- package/excel_word/wesync/sort_rules.py +75 -26
- package/excel_word/wesync/valuefmt.py +40 -17
- package/package.json +53 -51
- 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 -156
- package/qoder_plugins/audit-toolbox/catalog.mjs +13 -13
|
@@ -1,39 +1,294 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""左侧导航:图标、分组折叠、整栏折叠与当前项高亮。"""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from functools import lru_cache
|
|
5
6
|
from typing import Callable
|
|
6
7
|
|
|
7
|
-
from PySide6.
|
|
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), "?")
|
|
8
106
|
|
|
9
107
|
|
|
10
108
|
class NavBar(QWidget):
|
|
109
|
+
collapse_toggled = Signal(bool)
|
|
110
|
+
|
|
11
111
|
def __init__(self, parent, on_select: Callable[[str], None]):
|
|
12
112
|
super().__init__(parent)
|
|
13
113
|
self.setObjectName("Nav")
|
|
14
|
-
self.
|
|
114
|
+
self.setProperty("collapsed", False)
|
|
115
|
+
self.setMinimumWidth(COLLAPSED_WIDTH)
|
|
15
116
|
self._on_select = on_select
|
|
16
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
|
|
17
124
|
|
|
18
125
|
layout = QVBoxLayout(self)
|
|
19
|
-
layout.setContentsMargins(10,
|
|
20
|
-
layout.setSpacing(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
|
|
24
137
|
self._body = QVBoxLayout()
|
|
25
|
-
self._body.setSpacing(
|
|
138
|
+
self._body.setSpacing(3)
|
|
26
139
|
layout.addLayout(self._body)
|
|
27
140
|
layout.addStretch(1)
|
|
28
141
|
|
|
29
|
-
|
|
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
|
+
|
|
30
195
|
button = QPushButton(text)
|
|
31
196
|
button.setObjectName("Nav")
|
|
32
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))
|
|
33
201
|
button.clicked.connect(lambda _checked=False, k=key: self._on_select(k))
|
|
34
|
-
|
|
202
|
+
if group:
|
|
203
|
+
self._groups[group]["layout"].addWidget(button)
|
|
204
|
+
else:
|
|
205
|
+
self._body.addWidget(button)
|
|
35
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))
|
|
36
256
|
|
|
37
257
|
def select(self, key: str) -> None:
|
|
258
|
+
self._selected_key = key
|
|
38
259
|
for item_key, button in self._buttons.items():
|
|
39
|
-
|
|
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
|
|
@@ -731,6 +731,11 @@ _HEADING_NUMBER_RE = re.compile(
|
|
|
731
731
|
)
|
|
732
732
|
|
|
733
733
|
|
|
734
|
+
# 目录条目结尾:制表符、引导点,或末尾页码 / 页码区间(如「1-3」「1–3」「11~12」)。
|
|
735
|
+
# 缺了页码区间这一支,目录里的「一、审计报告 1-3」会被当成正文候选送进模型。
|
|
736
|
+
_TOC_TAIL_RE = re.compile(r"(?:\.{2,}|…{2,}|\t)|\s\d+(?:\s*[-–—-~]\s*\d+)?\s*$")
|
|
737
|
+
|
|
738
|
+
|
|
734
739
|
def _context_text(paragraph: Paragraph | None) -> str:
|
|
735
740
|
return re.sub(r"\s+", " ", paragraph.text).strip()[:100] if paragraph is not None else ""
|
|
736
741
|
|
|
@@ -772,7 +777,7 @@ def _format_candidate_package(doc, fingerprint: str) -> dict:
|
|
|
772
777
|
while content_start < len(paragraphs):
|
|
773
778
|
text = re.sub(r"\s+", " ", paragraphs[content_start].text).strip()
|
|
774
779
|
style_name = paragraphs[content_start].style.name if paragraphs[content_start].style is not None else ""
|
|
775
|
-
if "toc" not in style_name.lower() and "目录" not in style_name and not
|
|
780
|
+
if "toc" not in style_name.lower() and "目录" not in style_name and not _TOC_TAIL_RE.search(text):
|
|
776
781
|
break
|
|
777
782
|
content_start += 1
|
|
778
783
|
|
|
@@ -786,6 +791,9 @@ def _format_candidate_package(doc, fingerprint: str) -> dict:
|
|
|
786
791
|
continue
|
|
787
792
|
if DATE_RE.match(text) or re.search(r"[。;;!!??]$", text):
|
|
788
793
|
continue
|
|
794
|
+
# 带页码/页码区间的条目是目录行,不是标题:交给模型只会被误判,也浪费 token。
|
|
795
|
+
if _TOC_TAIL_RE.search(text):
|
|
796
|
+
continue
|
|
789
797
|
fmt = _effective_paragraph_format(paragraph)
|
|
790
798
|
visual = fmt.bold is True or fmt.align == "center" or (fmt.size is not None and fmt.size >= 14)
|
|
791
799
|
if not _HEADING_NUMBER_RE.match(text) and not (visual and len(text) <= 60):
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""全局操作默认值与 Word 零值显示策略。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
DEFAULTS = {
|
|
6
|
+
"auto_backup": True,
|
|
7
|
+
"excel_links": True,
|
|
8
|
+
"totals_formula": True,
|
|
9
|
+
# 默认三项全同步:表格、标注、占位符。多数报告三类内容都有,
|
|
10
|
+
# 只同步表格会让人以为「标注丢了」,所以默认全开。
|
|
11
|
+
"sync_tables": True,
|
|
12
|
+
"sync_marks": True,
|
|
13
|
+
"sync_placeholders": True,
|
|
14
|
+
"keep_highlight": True,
|
|
15
|
+
"reversible_delete": True,
|
|
16
|
+
"table_zero": "blank",
|
|
17
|
+
"mark_zero": "fixed",
|
|
18
|
+
"placeholder_zero": "fixed",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
ZERO_MODES = {"excel", "fixed", "dash", "blank"}
|
|
22
|
+
ZERO_LABELS = {"excel": "按 Excel 格式", "fixed": "0.00", "dash": "小横杠 -", "blank": "空白"}
|
|
23
|
+
BOOL_KEYS = {key for key, value in DEFAULTS.items() if isinstance(value, bool)}
|
|
24
|
+
ZERO_KEYS = {"table_zero", "mark_zero", "placeholder_zero"}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def normalize(values: dict) -> dict:
|
|
28
|
+
result = dict(DEFAULTS)
|
|
29
|
+
for key in DEFAULTS:
|
|
30
|
+
value = values.get(key, DEFAULTS[key])
|
|
31
|
+
if key in BOOL_KEYS and isinstance(value, bool):
|
|
32
|
+
result[key] = value
|
|
33
|
+
elif key in ZERO_KEYS and value in ZERO_MODES:
|
|
34
|
+
result[key] = value
|
|
35
|
+
return result
|
|
@@ -10,6 +10,7 @@ from __future__ import annotations
|
|
|
10
10
|
import re
|
|
11
11
|
from copy import copy
|
|
12
12
|
|
|
13
|
+
from openpyxl.formula import Tokenizer
|
|
13
14
|
from openpyxl.styles import Alignment, Font
|
|
14
15
|
|
|
15
16
|
from .config import FILL_ANCHOR, FONT_NAME, FONT_SIZE, META_SCAN_COLUMNS, NUMBER_RE, SHEET_NAME
|
|
@@ -22,7 +23,8 @@ DESC = "降序"
|
|
|
22
23
|
ASC = "升序"
|
|
23
24
|
OTHER_ITEM = "其他"
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
_A1_RANGE_RE = re.compile(r"(\$?[A-Za-z]{1,3})(\$?\d+)(?::(\$?[A-Za-z]{1,3})(\$?\d+))?")
|
|
27
|
+
_SHEET_RANGE_RE = re.compile(r"('(?:[^']|'')*'|[^!]+)!(.+)")
|
|
26
28
|
|
|
27
29
|
|
|
28
30
|
def sort_setting_text(column: str, descending: bool = True) -> str:
|
|
@@ -100,7 +102,7 @@ def _amount(ws, row: int, col: int, cached) -> float | None:
|
|
|
100
102
|
cell = ws.cell(row, col)
|
|
101
103
|
raw = cell.value
|
|
102
104
|
if isinstance(raw, str) and raw.startswith("="):
|
|
103
|
-
raw = cached.get((row, col))
|
|
105
|
+
raw = cached.get((ws.title, row, col))
|
|
104
106
|
if raw is None:
|
|
105
107
|
raw = evaluate_formula(ws, row, col, cached)
|
|
106
108
|
if isinstance(raw, (int, float)) and not isinstance(raw, bool):
|
|
@@ -119,26 +121,69 @@ def _is_other(ws, row: int, ncols: int, col0: int = 2) -> bool:
|
|
|
119
121
|
return ncols > 1 and _row_text(ws, row, col0 + 1) == OTHER_ITEM
|
|
120
122
|
|
|
121
123
|
|
|
122
|
-
def _remap_formula(text: str, rowmap: dict[int, int]) -> str:
|
|
123
|
-
"""
|
|
124
|
-
|
|
125
|
-
def
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
124
|
+
def _remap_formula(text: str, rowmap: dict[int, int], sheet_name: str | None = None) -> str:
|
|
125
|
+
"""仅重映射当前表的相对行引用;绝对行、跨表及复杂引用保守保留。"""
|
|
126
|
+
|
|
127
|
+
def unsupported() -> str:
|
|
128
|
+
warn(f"[排序] 公式含无法可靠处理的引用,已保留原公式:{text}")
|
|
129
|
+
return text
|
|
130
|
+
|
|
131
|
+
try:
|
|
132
|
+
tokens = Tokenizer(text).items
|
|
133
|
+
except Exception:
|
|
134
|
+
return unsupported()
|
|
135
|
+
significant = [token for token in tokens if token.type != "WSPACE"]
|
|
136
|
+
if not significant or significant[-1].type in {"OPERATOR-INFIX", "OPERATOR-PREFIX"}:
|
|
137
|
+
return unsupported()
|
|
138
|
+
depth = 0
|
|
139
|
+
for token in significant:
|
|
140
|
+
if token.type in {"FUNC", "PAREN"} and token.subtype == "OPEN":
|
|
141
|
+
depth += 1
|
|
142
|
+
elif token.type in {"FUNC", "PAREN"} and token.subtype == "CLOSE":
|
|
143
|
+
depth -= 1
|
|
144
|
+
if depth < 0:
|
|
145
|
+
return unsupported()
|
|
146
|
+
if depth:
|
|
147
|
+
return unsupported()
|
|
148
|
+
|
|
149
|
+
rewritten = []
|
|
150
|
+
changed = False
|
|
151
|
+
for token in tokens:
|
|
152
|
+
value = token.value
|
|
153
|
+
if token.type == "OPERAND" and token.subtype == "RANGE":
|
|
154
|
+
if any(mark in value for mark in "[]{}#"): # 结构化/外部/动态引用
|
|
155
|
+
return unsupported()
|
|
156
|
+
ref = value
|
|
157
|
+
qualifier_prefix = ""
|
|
158
|
+
if "!" in value:
|
|
159
|
+
qualified = _SHEET_RANGE_RE.fullmatch(value)
|
|
160
|
+
if qualified is None:
|
|
161
|
+
return unsupported()
|
|
162
|
+
qualifier, ref = qualified.groups()
|
|
163
|
+
qualifier_prefix = value[:len(qualifier) + 1]
|
|
164
|
+
if qualifier.startswith("'"):
|
|
165
|
+
qualifier = qualifier[1:-1].replace("''", "'")
|
|
166
|
+
if ":" in qualifier: # 三维工作表引用
|
|
167
|
+
return unsupported()
|
|
168
|
+
if sheet_name is None or qualifier.casefold() != sheet_name.casefold():
|
|
169
|
+
rewritten.append(value)
|
|
170
|
+
continue
|
|
171
|
+
match = _A1_RANGE_RE.fullmatch(ref)
|
|
172
|
+
if match is None: # 名称、整列/整行等无法可靠按行重映射
|
|
173
|
+
return unsupported()
|
|
174
|
+
col1, row1, col2, row2 = match.groups()
|
|
175
|
+
if row1.startswith("$") or (row2 and row2.startswith("$")):
|
|
176
|
+
rewritten.append(value)
|
|
177
|
+
continue
|
|
178
|
+
if row2 is None:
|
|
179
|
+
value = f"{qualifier_prefix}{col1}{rowmap.get(int(row1), int(row1))}"
|
|
180
|
+
else:
|
|
181
|
+
r1, r2 = int(row1), int(row2)
|
|
134
182
|
rows = [rowmap.get(r, r) for r in range(min(r1, r2), max(r1, r2) + 1)]
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return _RANGE_OR_REF_RE.sub(repl, part)
|
|
140
|
-
|
|
141
|
-
return "".join(fix_part(p) for p in re.split(r'("[^"]*")', text))
|
|
183
|
+
value = f"{qualifier_prefix}{col1}{min(rows)}:{col2}{max(rows)}"
|
|
184
|
+
changed = changed or value != token.value
|
|
185
|
+
rewritten.append(value)
|
|
186
|
+
return ("=" if text.startswith("=") else "") + "".join(rewritten) if changed else text
|
|
142
187
|
|
|
143
188
|
|
|
144
189
|
def apply_block_sort(ws, block: dict, cached: dict, dry_run: bool = False) -> dict | None:
|
|
@@ -216,12 +261,16 @@ def apply_block_sort(ws, block: dict, cached: dict, dry_run: bool = False) -> di
|
|
|
216
261
|
for c in range(2, col0 + ncols):
|
|
217
262
|
cell = ws.cell(r, c)
|
|
218
263
|
if isinstance(cell.value, str) and cell.value.startswith("="):
|
|
219
|
-
cell.value = _remap_formula(cell.value, rowmap)
|
|
220
|
-
cached_snapshot = {
|
|
221
|
-
|
|
264
|
+
cell.value = _remap_formula(cell.value, rowmap, ws.title)
|
|
265
|
+
cached_snapshot = {
|
|
266
|
+
(sheet, r, c): value
|
|
267
|
+
for (sheet, r, c), value in cached.items()
|
|
268
|
+
if sheet == ws.title and r in rowmap
|
|
269
|
+
}
|
|
270
|
+
for key in cached_snapshot:
|
|
222
271
|
del cached[key]
|
|
223
|
-
for (r, c), value in cached_snapshot.items():
|
|
224
|
-
cached[(rowmap[r], c)] = value
|
|
272
|
+
for (sheet, r, c), value in cached_snapshot.items():
|
|
273
|
+
cached[(sheet, rowmap[r], c)] = value
|
|
225
274
|
log(f"[排序] {code}:已按「{column}」{DESC if descending else ASC}重排 {moved} 行{note},合计行保持末行")
|
|
226
275
|
return {"moved": moved, "others": len(others), "unparsed": unparsed}
|
|
227
276
|
|