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
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
"""胶囊勾选项(chip):带图标、可自适应换行、窄窗只显图标。
|
|
2
|
+
|
|
3
|
+
设计要点:
|
|
4
|
+
- **胶囊形**:圆角等于高度一半,选中时填充主色淡底 + 主色描边;
|
|
5
|
+
- **带图标**:图标由本地绘制(与侧栏同一套线条风格),不依赖外部资源;
|
|
6
|
+
- **流式布局**:窗口变宽时一行放更多,变窄时自动换行,不出现横向滚动条;
|
|
7
|
+
- **窄窗降级**:每个 chip 有最小宽度需求,容器放不下文字时只显示图标,
|
|
8
|
+
鼠标悬停用 tooltip 显示名称——与侧栏折叠的行为一致。
|
|
9
|
+
|
|
10
|
+
用法:
|
|
11
|
+
row = ChipRow(parent, options=[(key, label, icon_kind), ...])
|
|
12
|
+
row.checked() -> {key: bool}
|
|
13
|
+
row.toggled -> 信号(任何 chip 状态变化时发出)
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from functools import lru_cache
|
|
19
|
+
|
|
20
|
+
from PySide6.QtCore import QRectF, QSize, Qt, Signal
|
|
21
|
+
from PySide6.QtGui import QColor, QIcon, QPainter, QPen, QPixmap
|
|
22
|
+
from PySide6.QtWidgets import (
|
|
23
|
+
QHBoxLayout,
|
|
24
|
+
QLabel,
|
|
25
|
+
QSizePolicy,
|
|
26
|
+
QVBoxLayout,
|
|
27
|
+
QWidget,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
from .. import theme
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# ---------------------------------------------------------------- 图标
|
|
34
|
+
|
|
35
|
+
# 每个勾选项用哪条线条图标(风格与侧栏一致)
|
|
36
|
+
_CHIP_ICONS = {
|
|
37
|
+
# 格式页「调整项目」
|
|
38
|
+
"cover": "cover",
|
|
39
|
+
"headings": "heading",
|
|
40
|
+
"statement": "statement",
|
|
41
|
+
"body": "body",
|
|
42
|
+
"table_text": "text",
|
|
43
|
+
"table_emphasis": "emphasis",
|
|
44
|
+
"table_borders": "border",
|
|
45
|
+
# 创建 Excel / 同步 Word / 标注 / 空白表 / 书签 等页面的选项
|
|
46
|
+
"links": "link",
|
|
47
|
+
"totals": "sum",
|
|
48
|
+
"backup": "shield",
|
|
49
|
+
"changelog": "list",
|
|
50
|
+
"force": "unlock",
|
|
51
|
+
"keep_highlight": "highlight",
|
|
52
|
+
"reversible": "undo",
|
|
53
|
+
"delete_backup": "shield",
|
|
54
|
+
"refresh_links": "link",
|
|
55
|
+
"delete_empty": "eraser",
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@lru_cache(maxsize=None)
|
|
60
|
+
def chip_icon(kind: str, active: bool = False, mode: str = "light") -> QIcon:
|
|
61
|
+
"""画一枚 32×32 的线条图标;active 时用主色,否则用弱化色。"""
|
|
62
|
+
c = theme.colors(mode)
|
|
63
|
+
color = QColor(c["primary"] if active else c["muted"])
|
|
64
|
+
pixmap = QPixmap(32, 32)
|
|
65
|
+
pixmap.fill(Qt.transparent)
|
|
66
|
+
painter = QPainter(pixmap)
|
|
67
|
+
painter.setRenderHint(QPainter.Antialiasing)
|
|
68
|
+
pen = QPen(color, 2.0)
|
|
69
|
+
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
|
|
70
|
+
pen.setJoinStyle(Qt.PenJoinStyle.RoundJoin)
|
|
71
|
+
painter.setPen(pen)
|
|
72
|
+
painter.setBrush(Qt.NoBrush)
|
|
73
|
+
_draw(painter, kind)
|
|
74
|
+
painter.end()
|
|
75
|
+
return QIcon(pixmap)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _draw(painter: QPainter, kind: str) -> None:
|
|
79
|
+
if kind == "cover": # 封面:方框 + 顶部条
|
|
80
|
+
painter.drawRoundedRect(QRectF(6, 5, 20, 22), 2, 2)
|
|
81
|
+
painter.drawLine(10, 11, 22, 11)
|
|
82
|
+
painter.drawLine(10, 16, 18, 16)
|
|
83
|
+
elif kind == "heading": # 标题:H 形(大小标题)
|
|
84
|
+
painter.drawLine(8, 8, 8, 24)
|
|
85
|
+
painter.drawLine(8, 16, 18, 16)
|
|
86
|
+
painter.drawLine(18, 8, 18, 24)
|
|
87
|
+
painter.drawLine(22, 20, 26, 20)
|
|
88
|
+
elif kind == "statement": # 报表名:行 + 日期点
|
|
89
|
+
painter.drawLine(6, 10, 26, 10)
|
|
90
|
+
painter.drawLine(6, 16, 20, 16)
|
|
91
|
+
painter.drawEllipse(QRectF(21, 19, 5, 5))
|
|
92
|
+
elif kind == "body": # 正文段落:多行
|
|
93
|
+
painter.drawLine(7, 9, 25, 9)
|
|
94
|
+
painter.drawLine(7, 15, 25, 15)
|
|
95
|
+
painter.drawLine(7, 21, 18, 21)
|
|
96
|
+
elif kind == "text": # 表格字体:格子里的 T
|
|
97
|
+
painter.drawRoundedRect(QRectF(6, 7, 20, 18), 2, 2)
|
|
98
|
+
painter.drawLine(11, 12, 21, 12)
|
|
99
|
+
painter.drawLine(16, 12, 16, 21)
|
|
100
|
+
elif kind == "emphasis": # 加粗:粗线 + 细线
|
|
101
|
+
pen = painter.pen()
|
|
102
|
+
thick = QPen(pen)
|
|
103
|
+
thick.setWidthF(3.6)
|
|
104
|
+
painter.setPen(thick)
|
|
105
|
+
painter.drawLine(8, 11, 24, 11)
|
|
106
|
+
painter.setPen(pen)
|
|
107
|
+
painter.drawLine(8, 18, 24, 18)
|
|
108
|
+
painter.drawLine(8, 24, 18, 24)
|
|
109
|
+
elif kind == "border": # 框线:外框 + 内十字
|
|
110
|
+
painter.drawRoundedRect(QRectF(6, 7, 20, 18), 2, 2)
|
|
111
|
+
painter.drawLine(16, 7, 16, 25)
|
|
112
|
+
painter.drawLine(6, 16, 26, 16)
|
|
113
|
+
elif kind == "link": # 链接:两节链条
|
|
114
|
+
painter.drawArc(QRectF(5, 11, 12, 10), 40 * 16, 200 * 16)
|
|
115
|
+
painter.drawArc(QRectF(15, 11, 12, 10), 220 * 16, 200 * 16)
|
|
116
|
+
painter.drawLine(12, 16, 20, 16)
|
|
117
|
+
elif kind == "sum": # 求和:Σ
|
|
118
|
+
painter.drawLine(9, 8, 23, 8)
|
|
119
|
+
painter.drawLine(9, 8, 17, 16)
|
|
120
|
+
painter.drawLine(17, 16, 9, 24)
|
|
121
|
+
painter.drawLine(9, 24, 23, 24)
|
|
122
|
+
elif kind == "shield": # 备份/保护:盾牌
|
|
123
|
+
painter.drawLine(16, 5, 16, 26)
|
|
124
|
+
painter.drawLine(16, 5, 8, 9)
|
|
125
|
+
painter.drawLine(8, 9, 9, 19)
|
|
126
|
+
painter.drawLine(9, 19, 16, 26)
|
|
127
|
+
painter.drawLine(16, 5, 24, 9)
|
|
128
|
+
painter.drawLine(24, 9, 23, 19)
|
|
129
|
+
painter.drawLine(23, 19, 16, 26)
|
|
130
|
+
elif kind == "list": # 清单:三行带点
|
|
131
|
+
for y in (9, 16, 23):
|
|
132
|
+
painter.drawPoint(8, y)
|
|
133
|
+
painter.drawLine(12, y, 25, y)
|
|
134
|
+
elif kind == "unlock": # 忽略占用:开锁
|
|
135
|
+
painter.drawRoundedRect(QRectF(8, 14, 16, 12), 2, 2)
|
|
136
|
+
painter.drawArc(QRectF(12, 6, 12, 12), 0, 180 * 16)
|
|
137
|
+
elif kind == "highlight": # 高亮:荧光笔
|
|
138
|
+
painter.drawLine(7, 25, 25, 25)
|
|
139
|
+
painter.drawLine(9, 21, 21, 9)
|
|
140
|
+
painter.drawLine(13, 7, 25, 19)
|
|
141
|
+
painter.drawLine(9, 21, 13, 7)
|
|
142
|
+
elif kind == "undo": # 可逆:回转箭头
|
|
143
|
+
painter.drawArc(QRectF(7, 8, 18, 16), 30 * 16, 280 * 16)
|
|
144
|
+
painter.drawLine(7, 8, 7, 14)
|
|
145
|
+
painter.drawLine(7, 8, 13, 8)
|
|
146
|
+
elif kind == "eraser": # 删除:橡皮
|
|
147
|
+
painter.drawRoundedRect(QRectF(7, 13, 18, 11), 2, 2)
|
|
148
|
+
painter.drawLine(7, 18, 25, 18)
|
|
149
|
+
painter.drawLine(11, 13, 15, 7)
|
|
150
|
+
else: # 兜底:小方块
|
|
151
|
+
painter.drawRoundedRect(QRectF(9, 9, 14, 14), 3, 3)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
# ---------------------------------------------------------------- 单个胶囊
|
|
155
|
+
|
|
156
|
+
class Chip(QWidget):
|
|
157
|
+
"""一枚胶囊勾选项:图标 + 文字,可点击切换,选中时高亮。"""
|
|
158
|
+
|
|
159
|
+
toggled = Signal(bool)
|
|
160
|
+
|
|
161
|
+
HEIGHT = 34
|
|
162
|
+
ICON_ONLY_WIDTH = 52
|
|
163
|
+
|
|
164
|
+
def __init__(self, key: str, label: str, checked: bool = True, parent=None):
|
|
165
|
+
super().__init__(parent)
|
|
166
|
+
self.key = key
|
|
167
|
+
self.label = label
|
|
168
|
+
self._checked = bool(checked)
|
|
169
|
+
self._icon_only = False
|
|
170
|
+
|
|
171
|
+
self.setCursor(Qt.PointingHandCursor)
|
|
172
|
+
self.setFixedHeight(self.HEIGHT)
|
|
173
|
+
self.setFocusPolicy(Qt.StrongFocus)
|
|
174
|
+
# 水平方向允许收缩,否则容器被撑死、窗口变窄时无法降级为图标模式
|
|
175
|
+
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
|
|
176
|
+
self.setMinimumWidth(self.ICON_ONLY_WIDTH)
|
|
177
|
+
self.setObjectName("Chip")
|
|
178
|
+
self.setProperty("checked", self._checked)
|
|
179
|
+
self.setAccessibleName(label)
|
|
180
|
+
self._sync_tooltip()
|
|
181
|
+
|
|
182
|
+
layout = QHBoxLayout(self)
|
|
183
|
+
layout.setContentsMargins(11, 0, 14, 0)
|
|
184
|
+
layout.setSpacing(7)
|
|
185
|
+
self._icon = QLabel(self)
|
|
186
|
+
self._icon.setObjectName("ChipIcon")
|
|
187
|
+
self._icon.setFixedSize(18, 18)
|
|
188
|
+
layout.addWidget(self._icon)
|
|
189
|
+
self._text = QLabel(label, self)
|
|
190
|
+
self._text.setObjectName("ChipText")
|
|
191
|
+
layout.addWidget(self._text)
|
|
192
|
+
self._layout = layout
|
|
193
|
+
self._refresh_icon()
|
|
194
|
+
self._refresh_style()
|
|
195
|
+
|
|
196
|
+
# -- 状态
|
|
197
|
+
|
|
198
|
+
def is_checked(self) -> bool:
|
|
199
|
+
return self._checked
|
|
200
|
+
|
|
201
|
+
def set_checked(self, checked: bool, *, emit: bool = True) -> None:
|
|
202
|
+
checked = bool(checked)
|
|
203
|
+
if checked == self._checked:
|
|
204
|
+
return
|
|
205
|
+
self._checked = checked
|
|
206
|
+
self.setProperty("checked", checked)
|
|
207
|
+
self._refresh_icon()
|
|
208
|
+
self._refresh_style()
|
|
209
|
+
if emit:
|
|
210
|
+
self.toggled.emit(checked)
|
|
211
|
+
|
|
212
|
+
def toggle(self) -> None:
|
|
213
|
+
self.set_checked(not self._checked)
|
|
214
|
+
|
|
215
|
+
# -- QCheckBox 兼容接口
|
|
216
|
+
# 各页面原本用 QCheckBox,并经由 bind_defaults 调用 setChecked/isChecked/setEnabled。
|
|
217
|
+
# 提供同名方法后,页面代码与既有测试都不必改写。
|
|
218
|
+
|
|
219
|
+
def isChecked(self) -> bool: # noqa: N802 - 对齐 Qt 命名
|
|
220
|
+
return self._checked
|
|
221
|
+
|
|
222
|
+
def setChecked(self, checked: bool) -> None: # noqa: N802 - 对齐 Qt 命名
|
|
223
|
+
self.set_checked(checked)
|
|
224
|
+
|
|
225
|
+
def setEnabled(self, enabled: bool) -> None: # noqa: N802 - 对齐 Qt 命名
|
|
226
|
+
super().setEnabled(enabled)
|
|
227
|
+
self.setCursor(Qt.PointingHandCursor if enabled else Qt.ArrowCursor)
|
|
228
|
+
self.update()
|
|
229
|
+
|
|
230
|
+
# -- 外观
|
|
231
|
+
|
|
232
|
+
def _refresh_icon(self) -> None:
|
|
233
|
+
kind = _CHIP_ICONS.get(self.key, "dot")
|
|
234
|
+
self._icon.setPixmap(
|
|
235
|
+
chip_icon(kind, self._checked, theme.effective_mode()).pixmap(18, 18)
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
def _refresh_style(self) -> None:
|
|
239
|
+
self.style().unpolish(self)
|
|
240
|
+
self.style().polish(self)
|
|
241
|
+
self.update()
|
|
242
|
+
|
|
243
|
+
def refresh_theme(self) -> None:
|
|
244
|
+
self._refresh_icon()
|
|
245
|
+
self._refresh_style()
|
|
246
|
+
|
|
247
|
+
def set_icon_only(self, icon_only: bool) -> None:
|
|
248
|
+
"""窄窗时只显示图标,文字隐藏,靠 tooltip 提示。"""
|
|
249
|
+
icon_only = bool(icon_only)
|
|
250
|
+
if icon_only == self._icon_only:
|
|
251
|
+
return
|
|
252
|
+
self._icon_only = icon_only
|
|
253
|
+
self._text.setVisible(not icon_only)
|
|
254
|
+
if icon_only:
|
|
255
|
+
self.setMinimumWidth(self.ICON_ONLY_WIDTH)
|
|
256
|
+
self.setMaximumWidth(self.ICON_ONLY_WIDTH)
|
|
257
|
+
self._layout.setContentsMargins(0, 0, 0, 0)
|
|
258
|
+
self._layout.setSpacing(0)
|
|
259
|
+
self._layout.setAlignment(Qt.AlignCenter)
|
|
260
|
+
else:
|
|
261
|
+
# 恢复可伸缩:只给最小宽度,不用 setFixedWidth,否则容器又被锁死
|
|
262
|
+
self.setMinimumWidth(self.ICON_ONLY_WIDTH)
|
|
263
|
+
self.setMaximumWidth(16777215)
|
|
264
|
+
self._layout.setContentsMargins(11, 0, 14, 0)
|
|
265
|
+
self._layout.setSpacing(7)
|
|
266
|
+
self._layout.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
|
267
|
+
self._sync_tooltip()
|
|
268
|
+
self.updateGeometry()
|
|
269
|
+
|
|
270
|
+
def apply_icon_only(self) -> None:
|
|
271
|
+
"""按当前模式重新应用显隐(布局重新 addWidget 后调用,防止文字被隐式显示)。"""
|
|
272
|
+
self._text.setVisible(not self._icon_only)
|
|
273
|
+
if self._icon_only:
|
|
274
|
+
self.setMinimumWidth(self.ICON_ONLY_WIDTH)
|
|
275
|
+
self.setMaximumWidth(self.ICON_ONLY_WIDTH)
|
|
276
|
+
self._layout.setContentsMargins(0, 0, 0, 0)
|
|
277
|
+
self._layout.setSpacing(0)
|
|
278
|
+
self._layout.setAlignment(Qt.AlignCenter)
|
|
279
|
+
else:
|
|
280
|
+
self.setMinimumWidth(self.ICON_ONLY_WIDTH)
|
|
281
|
+
self.setMaximumWidth(16777215)
|
|
282
|
+
self._layout.setContentsMargins(11, 0, 14, 0)
|
|
283
|
+
self._layout.setSpacing(7)
|
|
284
|
+
self._layout.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
|
285
|
+
|
|
286
|
+
def _sync_tooltip(self) -> None:
|
|
287
|
+
if self._icon_only:
|
|
288
|
+
state = "已勾选" if self._checked else "未勾选"
|
|
289
|
+
self.setToolTip(f"{self.label}({state})")
|
|
290
|
+
else:
|
|
291
|
+
self.setToolTip("")
|
|
292
|
+
|
|
293
|
+
def sizeHint(self) -> QSize: # noqa: N802 - Qt 命名
|
|
294
|
+
if self._icon_only:
|
|
295
|
+
return QSize(self.ICON_ONLY_WIDTH, self.HEIGHT)
|
|
296
|
+
width = 11 + 18 + 7 + self._text.sizeHint().width() + 14
|
|
297
|
+
return QSize(max(96, width), self.HEIGHT)
|
|
298
|
+
|
|
299
|
+
def minimumSizeHint(self) -> QSize: # noqa: N802 - Qt 命名
|
|
300
|
+
# 最小宽度取图标模式宽度:空间不足时宁可降级,也不把容器撑开
|
|
301
|
+
return QSize(self.ICON_ONLY_WIDTH, self.HEIGHT)
|
|
302
|
+
|
|
303
|
+
# -- 交互
|
|
304
|
+
|
|
305
|
+
def paintEvent(self, event) -> None: # noqa: N802 - Qt 命名
|
|
306
|
+
"""自绘胶囊底:QWidget 的样式表不支持 border-radius,必须自己画。"""
|
|
307
|
+
from PySide6.QtCore import QRectF
|
|
308
|
+
from PySide6.QtGui import QColor, QPainter
|
|
309
|
+
|
|
310
|
+
c = theme.colors(theme.effective_mode())
|
|
311
|
+
painter = QPainter(self)
|
|
312
|
+
painter.setRenderHint(QPainter.Antialiasing, True)
|
|
313
|
+
rect = QRectF(0.5, 0.5, self.width() - 1, self.height() - 1)
|
|
314
|
+
radius = rect.height() / 2
|
|
315
|
+
enabled = self.isEnabled()
|
|
316
|
+
|
|
317
|
+
if not enabled:
|
|
318
|
+
# 禁用态:灰底灰边,不响应悬停
|
|
319
|
+
painter.setBrush(QColor(c["disabled_bg"]))
|
|
320
|
+
painter.setPen(QPen(QColor(c["disabled_text"]), 1.0))
|
|
321
|
+
elif self._checked:
|
|
322
|
+
painter.setBrush(QColor(c["primary_soft"]))
|
|
323
|
+
pen = QPen(QColor(c["primary_hover"] if self.underMouse() else c["primary"]), 1.2)
|
|
324
|
+
painter.setPen(pen)
|
|
325
|
+
else:
|
|
326
|
+
painter.setBrush(QColor(c["nav_hover"] if self.underMouse() else "transparent"))
|
|
327
|
+
pen = QPen(QColor(c["border_hover"] if self.underMouse() else c["border"]), 1.0)
|
|
328
|
+
painter.setPen(pen)
|
|
329
|
+
painter.drawRoundedRect(rect, radius, radius)
|
|
330
|
+
painter.end()
|
|
331
|
+
|
|
332
|
+
def enterEvent(self, event) -> None: # noqa: N802 - Qt 命名
|
|
333
|
+
super().enterEvent(event)
|
|
334
|
+
self.update()
|
|
335
|
+
|
|
336
|
+
def leaveEvent(self, event) -> None: # noqa: N802 - Qt 命名
|
|
337
|
+
super().leaveEvent(event)
|
|
338
|
+
self.update()
|
|
339
|
+
|
|
340
|
+
def mouseReleaseEvent(self, event) -> None: # noqa: N802 - Qt 命名
|
|
341
|
+
# 禁用时不能切换:父页在「沿用全局设置」状态下会 setEnabled(False),
|
|
342
|
+
# 若不拦截,用户仍能点动胶囊,与界面暗示矛盾。
|
|
343
|
+
if not self.isEnabled():
|
|
344
|
+
event.ignore()
|
|
345
|
+
return
|
|
346
|
+
if event.button() == Qt.LeftButton and self.rect().contains(event.position().toPoint()):
|
|
347
|
+
self.toggle()
|
|
348
|
+
event.accept()
|
|
349
|
+
return
|
|
350
|
+
super().mouseReleaseEvent(event)
|
|
351
|
+
|
|
352
|
+
def keyPressEvent(self, event) -> None: # noqa: N802 - Qt 命名
|
|
353
|
+
if not self.isEnabled():
|
|
354
|
+
super().keyPressEvent(event)
|
|
355
|
+
return
|
|
356
|
+
if event.key() in (Qt.Key_Space, Qt.Key_Return, Qt.Key_Enter):
|
|
357
|
+
self.toggle()
|
|
358
|
+
event.accept()
|
|
359
|
+
return
|
|
360
|
+
super().keyPressEvent(event)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
# ---------------------------------------------------------------- 流式容器
|
|
364
|
+
|
|
365
|
+
class ChipRow(QWidget):
|
|
366
|
+
"""胶囊组:自动换行;宽度不足时整体降级为「只显图标」。"""
|
|
367
|
+
|
|
368
|
+
toggled = Signal()
|
|
369
|
+
|
|
370
|
+
SPACING = 10
|
|
371
|
+
# 文字模式要拆成多行、而图标模式能一行放下时,是否优先图标(更紧凑)。
|
|
372
|
+
# 阈值不再写死宽度,改为按实际内容动态判断,见 _apply_width()。
|
|
373
|
+
PREFER_SINGLE_ROW = True
|
|
374
|
+
|
|
375
|
+
def __init__(self, options, parent=None):
|
|
376
|
+
super().__init__(parent)
|
|
377
|
+
self._chips: list[Chip] = []
|
|
378
|
+
self._columns = 0
|
|
379
|
+
self._icon_only = False
|
|
380
|
+
self._hints: dict[str, str] = {}
|
|
381
|
+
self._risk: set[str] = set()
|
|
382
|
+
self.setObjectName("ChipRow")
|
|
383
|
+
# 容器必须能随父窗口收缩,否则永远撑在内容宽度、降级逻辑永不触发
|
|
384
|
+
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
|
|
385
|
+
self.setMinimumWidth(120)
|
|
386
|
+
self._grid = QVBoxLayout(self)
|
|
387
|
+
self._grid.setContentsMargins(0, 0, 0, 0)
|
|
388
|
+
self._grid.setSpacing(self.SPACING)
|
|
389
|
+
self._rows: list[QHBoxLayout] = []
|
|
390
|
+
for item in options:
|
|
391
|
+
# 支持 (key, label) / (key, label, checked) / (key, label, checked, hint)
|
|
392
|
+
key, label = item[0], item[1]
|
|
393
|
+
checked = item[2] if len(item) > 2 else True
|
|
394
|
+
hint = item[3] if len(item) > 3 else ""
|
|
395
|
+
risk = bool(item[4]) if len(item) > 4 else False
|
|
396
|
+
if hint:
|
|
397
|
+
self._hints[key] = hint
|
|
398
|
+
if risk:
|
|
399
|
+
self._risk.add(key)
|
|
400
|
+
chip = Chip(key, label, checked, self)
|
|
401
|
+
chip.toggled.connect(lambda _v: self.toggled.emit())
|
|
402
|
+
self._chips.append(chip)
|
|
403
|
+
# 先按初始宽度铺一遍;真正的宽度由随后的 resizeEvent 决定
|
|
404
|
+
self._relayout([list(self._chips)] if self._chips else [])
|
|
405
|
+
self._build_hint_label()
|
|
406
|
+
|
|
407
|
+
def _build_hint_label(self) -> None:
|
|
408
|
+
"""风险提示(如「关闭则不可回滚」)不能藏进 tooltip,必须可见。
|
|
409
|
+
|
|
410
|
+
这类提示关系数据安全,用户需要在不悬停的情况下也能看到。
|
|
411
|
+
"""
|
|
412
|
+
if not self._hints:
|
|
413
|
+
return
|
|
414
|
+
parts = []
|
|
415
|
+
for chip in self._chips:
|
|
416
|
+
hint = self._hints.get(chip.key, "")
|
|
417
|
+
if not hint:
|
|
418
|
+
continue
|
|
419
|
+
parts.append(f"{chip.label}:{hint}" if len(self._hints) > 1 else hint)
|
|
420
|
+
self.hint_label = QLabel(" · ".join(parts), self)
|
|
421
|
+
self.hint_label.setObjectName("RiskHint" if self._risk else "OptionHint")
|
|
422
|
+
self.hint_label.setWordWrap(True)
|
|
423
|
+
self.hint_label.setMinimumWidth(0)
|
|
424
|
+
self._grid.addWidget(self.hint_label)
|
|
425
|
+
|
|
426
|
+
@classmethod
|
|
427
|
+
def bind(
|
|
428
|
+
cls,
|
|
429
|
+
layout,
|
|
430
|
+
options,
|
|
431
|
+
*,
|
|
432
|
+
on_toggle=None,
|
|
433
|
+
icons: bool = True,
|
|
434
|
+
) -> "ChipRow":
|
|
435
|
+
"""在布局末尾追加一组胶囊,返回容器。
|
|
436
|
+
|
|
437
|
+
用法:chips = ChipRow.bind(card.layout(), [("links", "Excel 链接"), ...])
|
|
438
|
+
返回的容器带 QCheckBox 兼容的 chips["key"] 取值方式,便于替换原有控件。
|
|
439
|
+
"""
|
|
440
|
+
row = cls(options)
|
|
441
|
+
if on_toggle is not None:
|
|
442
|
+
row.toggled.connect(on_toggle)
|
|
443
|
+
if hasattr(layout, "addWidget"):
|
|
444
|
+
layout.addWidget(row)
|
|
445
|
+
else:
|
|
446
|
+
layout.addWidget(row)
|
|
447
|
+
return row
|
|
448
|
+
|
|
449
|
+
def __getitem__(self, key: str) -> Chip:
|
|
450
|
+
"""按 key 取单个胶囊,让调用方可以像用 QCheckBox 一样操作。"""
|
|
451
|
+
for chip in self._chips:
|
|
452
|
+
if chip.key == key:
|
|
453
|
+
return chip
|
|
454
|
+
raise KeyError(key)
|
|
455
|
+
|
|
456
|
+
def __contains__(self, key: str) -> bool:
|
|
457
|
+
return any(chip.key == key for chip in self._chips)
|
|
458
|
+
|
|
459
|
+
def keys(self) -> list[str]:
|
|
460
|
+
return [chip.key for chip in self._chips]
|
|
461
|
+
|
|
462
|
+
# -- 布局
|
|
463
|
+
|
|
464
|
+
def _relayout(self, rows: list[list["Chip"]]) -> None:
|
|
465
|
+
"""按给定的行分组重排;先清空旧行再逐行铺。
|
|
466
|
+
|
|
467
|
+
hint_label 与胶囊行同在一个 QVBoxLayout 里,清空时必须先摘出来,
|
|
468
|
+
否则重排后提示会脱离布局变成浮动控件、界面上看不见。
|
|
469
|
+
"""
|
|
470
|
+
hint = getattr(self, "hint_label", None)
|
|
471
|
+
if hint is not None:
|
|
472
|
+
self._grid.removeWidget(hint)
|
|
473
|
+
while self._grid.count():
|
|
474
|
+
item = self._grid.takeAt(0)
|
|
475
|
+
layout = item.layout()
|
|
476
|
+
if layout is not None:
|
|
477
|
+
while layout.count():
|
|
478
|
+
layout.takeAt(0)
|
|
479
|
+
layout.deleteLater()
|
|
480
|
+
self._rows.clear()
|
|
481
|
+
self._columns = max((len(r) for r in rows), default=1)
|
|
482
|
+
for chips in rows:
|
|
483
|
+
row_layout = QHBoxLayout()
|
|
484
|
+
row_layout.setContentsMargins(0, 0, 0, 0)
|
|
485
|
+
row_layout.setSpacing(self.SPACING)
|
|
486
|
+
self._grid.addLayout(row_layout)
|
|
487
|
+
self._rows.append(row_layout)
|
|
488
|
+
for chip in chips:
|
|
489
|
+
row_layout.addWidget(chip)
|
|
490
|
+
# addWidget 会隐式 show,把「图标模式」下隐藏的文字又显示出来,这里补一次
|
|
491
|
+
chip.apply_icon_only()
|
|
492
|
+
row_layout.addStretch(1)
|
|
493
|
+
# 提示始终排在最后一行之下
|
|
494
|
+
if hint is not None:
|
|
495
|
+
self._grid.addWidget(hint)
|
|
496
|
+
|
|
497
|
+
def _pack(self, available: int) -> list[list["Chip"]]:
|
|
498
|
+
"""贪心装箱:按每个胶囊的**实际**宽度逐行填,能塞就塞。
|
|
499
|
+
|
|
500
|
+
旧实现按「最宽的那个」算列数,长标签会把整组挤成多行
|
|
501
|
+
(如 3 项共需 495px,容器 640px 却排成 2 行)。
|
|
502
|
+
"""
|
|
503
|
+
rows: list[list[Chip]] = []
|
|
504
|
+
current: list[Chip] = []
|
|
505
|
+
used = 0
|
|
506
|
+
for chip in self._chips:
|
|
507
|
+
width = chip.sizeHint().width()
|
|
508
|
+
need = width if not current else self.SPACING + width
|
|
509
|
+
if current and used + need > available:
|
|
510
|
+
rows.append(current)
|
|
511
|
+
current = [chip]
|
|
512
|
+
used = width
|
|
513
|
+
else:
|
|
514
|
+
current.append(chip)
|
|
515
|
+
used += need
|
|
516
|
+
if current:
|
|
517
|
+
rows.append(current)
|
|
518
|
+
return rows
|
|
519
|
+
|
|
520
|
+
def resizeEvent(self, event) -> None: # noqa: N802 - Qt 命名
|
|
521
|
+
super().resizeEvent(event)
|
|
522
|
+
self._apply_width(self.width())
|
|
523
|
+
|
|
524
|
+
def _apply_width(self, available: int) -> None:
|
|
525
|
+
"""能放文字就放文字;连图标都放不下才降级。
|
|
526
|
+
|
|
527
|
+
阈值不再是写死的 620px:只要一行(图标模式)能放进可用宽度,
|
|
528
|
+
就保持文字。这样短标签的页面(如「空白表格」只需 227px)
|
|
529
|
+
在中等宽度下不会再被误降级。
|
|
530
|
+
"""
|
|
531
|
+
icon_widths = [chip.ICON_ONLY_WIDTH for chip in self._chips]
|
|
532
|
+
icons_total = sum(icon_widths) + self.SPACING * max(0, len(icon_widths) - 1)
|
|
533
|
+
# 图标模式下也放不下 → 才降级;否则一律尝试文字
|
|
534
|
+
icon_only = available < icons_total
|
|
535
|
+
if icon_only != self._icon_only:
|
|
536
|
+
self._icon_only = icon_only
|
|
537
|
+
for chip in self._chips:
|
|
538
|
+
chip.set_icon_only(icon_only)
|
|
539
|
+
rows = self._pack(available)
|
|
540
|
+
# 文字模式却要拆成多行、而图标模式能一行放下时,优先图标(更紧凑)
|
|
541
|
+
if not icon_only and len(rows) > 1:
|
|
542
|
+
if available >= icons_total and self.PREFER_SINGLE_ROW:
|
|
543
|
+
icon_only = True
|
|
544
|
+
self._icon_only = True
|
|
545
|
+
for chip in self._chips:
|
|
546
|
+
chip.set_icon_only(True)
|
|
547
|
+
rows = self._pack(available)
|
|
548
|
+
self._relayout(rows)
|
|
549
|
+
|
|
550
|
+
# -- 对外
|
|
551
|
+
|
|
552
|
+
def checked(self) -> dict[str, bool]:
|
|
553
|
+
return {chip.key: chip.is_checked() for chip in self._chips}
|
|
554
|
+
|
|
555
|
+
def set_checked(self, values: dict[str, bool], *, emit: bool = False) -> None:
|
|
556
|
+
for chip in self._chips:
|
|
557
|
+
if chip.key in values:
|
|
558
|
+
chip.set_checked(bool(values[chip.key]), emit=emit)
|
|
559
|
+
|
|
560
|
+
def all_checked(self) -> bool:
|
|
561
|
+
return all(chip.is_checked() for chip in self._chips)
|
|
562
|
+
|
|
563
|
+
def refresh_theme(self) -> None:
|
|
564
|
+
for chip in self._chips:
|
|
565
|
+
chip.refresh_theme()
|
|
@@ -18,7 +18,7 @@ class FileBar(QWidget):
|
|
|
18
18
|
on_open_folder: Callable[[], None],
|
|
19
19
|
):
|
|
20
20
|
super().__init__(parent)
|
|
21
|
-
self.
|
|
21
|
+
self.setObjectName("FileBar")
|
|
22
22
|
grid = QGridLayout(self)
|
|
23
23
|
grid.setContentsMargins(16, 10, 16, 10)
|
|
24
24
|
grid.setHorizontalSpacing(8)
|
|
@@ -5,6 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import html
|
|
6
6
|
from typing import Callable
|
|
7
7
|
|
|
8
|
+
from .. import theme
|
|
8
9
|
from PySide6.QtWidgets import (
|
|
9
10
|
QCheckBox,
|
|
10
11
|
QFileDialog,
|
|
@@ -18,12 +19,12 @@ from PySide6.QtWidgets import (
|
|
|
18
19
|
)
|
|
19
20
|
|
|
20
21
|
LEVEL_TAGS = {
|
|
21
|
-
"info": ("
|
|
22
|
-
"muted": ("
|
|
23
|
-
"ok": ("
|
|
24
|
-
"warn": ("
|
|
25
|
-
"error": ("
|
|
26
|
-
"step": ("
|
|
22
|
+
"info": ("text", False),
|
|
23
|
+
"muted": ("muted", False),
|
|
24
|
+
"ok": ("success", False),
|
|
25
|
+
"warn": ("warning", False),
|
|
26
|
+
"error": ("error", False),
|
|
27
|
+
"step": ("primary", True),
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
|
|
@@ -65,9 +66,11 @@ class LogPane(QWidget):
|
|
|
65
66
|
self.text.setReadOnly(True)
|
|
66
67
|
self.text.setLineWrapMode(QPlainTextEdit.WidgetWidth)
|
|
67
68
|
layout.addWidget(self.text, 1)
|
|
69
|
+
self._entries: list[tuple[str, str]] = []
|
|
68
70
|
|
|
69
|
-
def
|
|
70
|
-
|
|
71
|
+
def _append_entry(self, message: str, level: str) -> None:
|
|
72
|
+
color_key, bold = LEVEL_TAGS.get(level, LEVEL_TAGS["info"])
|
|
73
|
+
color = theme.colors()[color_key]
|
|
71
74
|
body = html.escape(message).replace("\n", "<br>")
|
|
72
75
|
if bold:
|
|
73
76
|
body = f"<b>{body}</b>"
|
|
@@ -76,7 +79,20 @@ class LogPane(QWidget):
|
|
|
76
79
|
bar = self.text.verticalScrollBar()
|
|
77
80
|
bar.setValue(bar.maximum())
|
|
78
81
|
|
|
82
|
+
def append(self, message: str, level: str = "info") -> None:
|
|
83
|
+
self._entries.append((message, level))
|
|
84
|
+
self._append_entry(message, level)
|
|
85
|
+
|
|
86
|
+
def refresh_theme(self) -> None:
|
|
87
|
+
scroll = self.text.verticalScrollBar().value()
|
|
88
|
+
self.text.clear()
|
|
89
|
+
for message, level in self._entries:
|
|
90
|
+
self._append_entry(message, level)
|
|
91
|
+
if not self.auto_scroll.isChecked():
|
|
92
|
+
self.text.verticalScrollBar().setValue(scroll)
|
|
93
|
+
|
|
79
94
|
def clear(self) -> None:
|
|
95
|
+
self._entries.clear()
|
|
80
96
|
self.text.clear()
|
|
81
97
|
|
|
82
98
|
def content(self) -> str:
|