audit-e2w 0.0.0-stage → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/cordis.patch.yml +3 -0
- package/dsh_plugins/audit-e2w/lib/engine.mjs +174 -0
- package/dsh_plugins/audit-e2w/lib/index.js +114 -0
- package/dsh_plugins/audit-e2w/lib/skill.js +41 -0
- package/excel_word/README.md +380 -0
- package/excel_word/qoder_engine.py +438 -0
- package/excel_word/requirements.txt +4 -0
- package/excel_word/wesync/__init__.py +19 -0
- package/excel_word/wesync/__main__.py +6 -0
- package/excel_word/wesync/align.py +154 -0
- package/excel_word/wesync/api.py +840 -0
- package/excel_word/wesync/backup_history.py +65 -0
- package/excel_word/wesync/changelog.py +58 -0
- package/excel_word/wesync/cli.py +173 -0
- package/excel_word/wesync/commands/__init__.py +8 -0
- package/excel_word/wesync/commands/blank_cmd.py +250 -0
- package/excel_word/wesync/commands/bookmark_cmd.py +115 -0
- package/excel_word/wesync/commands/clear_cmd.py +48 -0
- package/excel_word/wesync/commands/export_cmd.py +220 -0
- package/excel_word/wesync/commands/marks_cmd.py +152 -0
- package/excel_word/wesync/commands/placeholders_cmd.py +87 -0
- package/excel_word/wesync/commands/writeback_cmd.py +513 -0
- package/excel_word/wesync/config.py +96 -0
- package/excel_word/wesync/console.py +78 -0
- package/excel_word/wesync/docx_blank.py +156 -0
- package/excel_word/wesync/docx_bookmarks.py +287 -0
- package/excel_word/wesync/docx_columns.py +257 -0
- package/excel_word/wesync/docx_edit.py +77 -0
- package/excel_word/wesync/docx_grid.py +212 -0
- package/excel_word/wesync/docx_marks.py +291 -0
- package/excel_word/wesync/docx_meta.py +157 -0
- package/excel_word/wesync/docx_newtable.py +220 -0
- package/excel_word/wesync/docx_placeholders.py +161 -0
- package/excel_word/wesync/docx_rows.py +67 -0
- package/excel_word/wesync/errors.py +5 -0
- package/excel_word/wesync/excel_blocks.py +543 -0
- package/excel_word/wesync/excel_export.py +136 -0
- package/excel_word/wesync/excel_marks.py +193 -0
- package/excel_word/wesync/excel_totals.py +53 -0
- package/excel_word/wesync/fsops.py +214 -0
- package/excel_word/wesync/gui/__init__.py +34 -0
- package/excel_word/wesync/gui/__main__.py +6 -0
- package/excel_word/wesync/gui/app.py +399 -0
- package/excel_word/wesync/gui/manual.py +68 -0
- package/excel_word/wesync/gui/pages/__init__.py +31 -0
- package/excel_word/wesync/gui/pages/_page.py +89 -0
- package/excel_word/wesync/gui/pages/batch_page.py +423 -0
- package/excel_word/wesync/gui/pages/blank_page.py +465 -0
- package/excel_word/wesync/gui/pages/bookmark_page.py +37 -0
- package/excel_word/wesync/gui/pages/export_page.py +88 -0
- package/excel_word/wesync/gui/pages/format_page.py +429 -0
- package/excel_word/wesync/gui/pages/help_page.py +92 -0
- package/excel_word/wesync/gui/pages/history_page.py +145 -0
- package/excel_word/wesync/gui/pages/marks_page.py +178 -0
- package/excel_word/wesync/gui/pages/writeback_page.py +452 -0
- package/excel_word/wesync/gui/resources.py +22 -0
- package/excel_word/wesync/gui/runner.py +74 -0
- package/excel_word/wesync/gui/store.py +34 -0
- package/excel_word/wesync/gui/theme.py +100 -0
- package/excel_word/wesync/gui/widgets/__init__.py +8 -0
- package/excel_word/wesync/gui/widgets/cards.py +20 -0
- package/excel_word/wesync/gui/widgets/filebar.py +58 -0
- package/excel_word/wesync/gui/widgets/logpane.py +110 -0
- package/excel_word/wesync/gui/widgets/nav.py +39 -0
- package/excel_word/wesync/report_format.py +1577 -0
- package/excel_word/wesync/sort_rules.py +244 -0
- package/excel_word/wesync/valuefmt.py +462 -0
- package/package.json +49 -4
- package/qoder_plugins/audit-toolbox/README.md +156 -0
- package/qoder_plugins/audit-toolbox/catalog.mjs +265 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""后台任务执行器:在子线程里跑命令,把日志与结果投递到界面队列。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import queue
|
|
6
|
+
import threading
|
|
7
|
+
import time
|
|
8
|
+
import traceback
|
|
9
|
+
from typing import Callable, Iterable
|
|
10
|
+
|
|
11
|
+
from ..console import reset_log_state, set_log_sink
|
|
12
|
+
from ..errors import SyncError
|
|
13
|
+
|
|
14
|
+
Step = tuple[str, Callable[[], int]]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TaskRunner:
|
|
18
|
+
"""串行执行若干步骤;同一时刻只允许一个任务。"""
|
|
19
|
+
|
|
20
|
+
def __init__(self) -> None:
|
|
21
|
+
self.queue: queue.Queue[tuple[str, object]] = queue.Queue()
|
|
22
|
+
self.busy = False
|
|
23
|
+
|
|
24
|
+
def submit(self, steps: Iterable[Step]) -> bool:
|
|
25
|
+
steps = list(steps)
|
|
26
|
+
if self.busy or not steps:
|
|
27
|
+
return False
|
|
28
|
+
self.busy = True
|
|
29
|
+
|
|
30
|
+
def worker() -> None:
|
|
31
|
+
started = time.perf_counter()
|
|
32
|
+
done: list[tuple[str, int]] = []
|
|
33
|
+
reset_log_state()
|
|
34
|
+
set_log_sink(lambda message: self.queue.put(("log", message)))
|
|
35
|
+
try:
|
|
36
|
+
for title, func in steps:
|
|
37
|
+
self.queue.put(("step", title))
|
|
38
|
+
code = func()
|
|
39
|
+
if not isinstance(code, int):
|
|
40
|
+
code = 0 # 步骤返回摘要等非整数视为成功,避免误报执行失败
|
|
41
|
+
done.append((title, code))
|
|
42
|
+
if code not in (0, None):
|
|
43
|
+
self.queue.put(("log", f"步骤「{title}」返回码 {code},已停止后续步骤"))
|
|
44
|
+
break
|
|
45
|
+
self.queue.put(("done", {"steps": done, "elapsed": time.perf_counter() - started}))
|
|
46
|
+
except SyncError as exc:
|
|
47
|
+
self.queue.put(
|
|
48
|
+
("error", {"title": steps[-1][0], "message": str(exc), "elapsed": time.perf_counter() - started})
|
|
49
|
+
)
|
|
50
|
+
except Exception as exc: # 未预期异常:把堆栈写进日志便于排查
|
|
51
|
+
self.queue.put(
|
|
52
|
+
(
|
|
53
|
+
"error",
|
|
54
|
+
{
|
|
55
|
+
"title": steps[-1][0],
|
|
56
|
+
"message": f"{type(exc).__name__}: {exc}\n{traceback.format_exc()}",
|
|
57
|
+
"elapsed": time.perf_counter() - started,
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
finally:
|
|
62
|
+
set_log_sink(None)
|
|
63
|
+
self.busy = False
|
|
64
|
+
|
|
65
|
+
threading.Thread(target=worker, name="wesync-gui-task", daemon=True).start()
|
|
66
|
+
return True
|
|
67
|
+
|
|
68
|
+
def drain(self) -> list[tuple[str, object]]:
|
|
69
|
+
items: list[tuple[str, object]] = []
|
|
70
|
+
while True:
|
|
71
|
+
try:
|
|
72
|
+
items.append(self.queue.get_nowait())
|
|
73
|
+
except queue.Empty:
|
|
74
|
+
return items
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""界面偏好持久化:窗口尺寸与上次使用的文件(写在项目内,不进入系统目录)。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from ..fsops import project_root
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _config_path() -> Path:
|
|
12
|
+
return project_root() / ".wesync_ui.json"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def load() -> dict:
|
|
16
|
+
path = _config_path()
|
|
17
|
+
try:
|
|
18
|
+
with path.open("r", encoding="utf-8") as handle:
|
|
19
|
+
data = json.load(handle)
|
|
20
|
+
return data if isinstance(data, dict) else {}
|
|
21
|
+
except Exception:
|
|
22
|
+
return {}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def save(values: dict) -> None:
|
|
26
|
+
path = _config_path()
|
|
27
|
+
data = load()
|
|
28
|
+
data.update(values)
|
|
29
|
+
try:
|
|
30
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
31
|
+
with path.open("w", encoding="utf-8") as handle:
|
|
32
|
+
json.dump(data, handle, ensure_ascii=False, indent=2)
|
|
33
|
+
except Exception:
|
|
34
|
+
pass
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""界面统一视觉:配色、字体与 Qt 样式表(沿用原 tkinter 版配色)。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
FONT_CANDIDATES = ("Microsoft YaHei UI", "Microsoft YaHei", "微软雅黑", "SimHei", "SimSun")
|
|
6
|
+
|
|
7
|
+
COLORS = {
|
|
8
|
+
"primary": "#1F4E79",
|
|
9
|
+
"primary_hover": "#2A6399",
|
|
10
|
+
"primary_soft": "#EAF1F8",
|
|
11
|
+
"bg": "#F7F8FA",
|
|
12
|
+
"card": "#FFFFFF",
|
|
13
|
+
"border": "#E3E6EA",
|
|
14
|
+
"text": "#1F2937",
|
|
15
|
+
"muted": "#6B7280",
|
|
16
|
+
"success": "#15803D",
|
|
17
|
+
"warning": "#B45309",
|
|
18
|
+
"error": "#B91C1C",
|
|
19
|
+
"disabled": "#9AA3AF",
|
|
20
|
+
"nav_hover": "#F2F6FA",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_family = FONT_CANDIDATES[0]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def font_family() -> str:
|
|
27
|
+
return _family
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _qss() -> str:
|
|
31
|
+
c = COLORS
|
|
32
|
+
return f"""
|
|
33
|
+
QWidget {{ background: {c['bg']}; color: {c['text']}; }}
|
|
34
|
+
QMainWindow, QStackedWidget, QScrollArea {{ background: {c['bg']}; }}
|
|
35
|
+
QScrollArea {{ border: none; }}
|
|
36
|
+
QLabel {{ background: transparent; }}
|
|
37
|
+
QFrame#Card {{ background: {c['card']}; border: 1px solid {c['border']}; border-radius: 6px; }}
|
|
38
|
+
QFrame#Card QLabel, QFrame#Card QCheckBox {{ background: transparent; }}
|
|
39
|
+
QLabel#PageTitle {{ font-size: 18px; font-weight: 600; }}
|
|
40
|
+
QLabel#Desc, QLabel#CardDesc {{ color: {c['muted']}; }}
|
|
41
|
+
QLabel#SectionTitle {{ font-size: 15px; font-weight: 600; }}
|
|
42
|
+
QLabel#Status {{ color: {c['muted']}; font-size: 12px; }}
|
|
43
|
+
QLabel#NavTitle {{ color: {c['muted']}; font-size: 12px; font-weight: 600; }}
|
|
44
|
+
QLabel#PathBox {{ background: #FFFFFF; border: 1px solid {c['border']}; border-radius: 4px; padding: 4px 6px; }}
|
|
45
|
+
QPushButton {{ background: {c['card']}; border: 1px solid {c['border']}; border-radius: 6px; padding: 8px 18px; font-size: 14px; }}
|
|
46
|
+
QPushButton:hover {{ background: {c['nav_hover']}; }}
|
|
47
|
+
QPushButton:disabled {{ background: {c['bg']}; color: {c['disabled']}; }}
|
|
48
|
+
QPushButton#Primary {{ background: {c['primary']}; color: #FFFFFF; border: none; font-size: 16px; font-weight: 600; padding: 10px 28px; }}
|
|
49
|
+
QPushButton#Primary:hover {{ background: {c['primary_hover']}; }}
|
|
50
|
+
QPushButton#Primary:disabled {{ background: #B7C4D1; color: #F2F5F8; }}
|
|
51
|
+
QPushButton#Nav {{ text-align: left; border: none; background: {c['card']}; padding: 10px 14px; font-size: 15px; border-radius: 6px; }}
|
|
52
|
+
QPushButton#Nav:hover {{ background: {c['nav_hover']}; }}
|
|
53
|
+
QPushButton#Nav:checked {{ background: {c['primary_soft']}; color: {c['primary']}; font-weight: 600; }}
|
|
54
|
+
QPushButton#LogTool {{ padding: 4px 10px; font-size: 12px; }}
|
|
55
|
+
QCheckBox {{ background: transparent; spacing: 6px; }}
|
|
56
|
+
QRadioButton {{ background: transparent; spacing: 8px; }}
|
|
57
|
+
QRadioButton::indicator {{ width: 16px; height: 16px; border: 2px solid {c['disabled']}; border-radius: 9px; background: {c['card']}; }}
|
|
58
|
+
QRadioButton::indicator:hover {{ border-color: {c['primary_hover']}; }}
|
|
59
|
+
QRadioButton::indicator:checked {{ border: 5px solid {c['primary']}; border-radius: 13px; background: {c['card']}; }}
|
|
60
|
+
QRadioButton:checked {{ color: {c['primary']}; font-weight: 600; }}
|
|
61
|
+
QPlainTextEdit#LogText {{ background: #FBFCFD; border: 1px solid {c['border']}; border-radius: 4px; font-size: 13px; }}
|
|
62
|
+
QLineEdit, QSpinBox, QComboBox {{ background: #FFFFFF; border: 1px solid {c['border']}; border-radius: 4px; padding: 4px 6px; }}
|
|
63
|
+
QListWidget#ManualChapters {{ background: #FFFFFF; border: 1px solid {c['border']}; border-radius: 6px; padding: 4px; outline: 0; }}
|
|
64
|
+
QListWidget#ManualChapters::item {{ padding: 8px 10px; border-radius: 4px; }}
|
|
65
|
+
QListWidget#ManualChapters::item:selected {{ background: {c['primary_soft']}; color: {c['primary']}; font-weight: 600; }}
|
|
66
|
+
QTextBrowser#ManualView {{ background: #FFFFFF; border: 1px solid {c['border']}; border-radius: 6px; }}
|
|
67
|
+
QTabWidget::pane {{ border: 1px solid {c['border']}; border-radius: 6px; background: {c['card']}; top: -1px; }}
|
|
68
|
+
QTabBar::tab {{ background: {c['bg']}; border: 1px solid {c['border']}; border-bottom: none; padding: 8px 20px; border-top-left-radius: 6px; border-top-right-radius: 6px; }}
|
|
69
|
+
QTabBar::tab:selected {{ background: {c['card']}; color: {c['primary']}; font-weight: 600; }}
|
|
70
|
+
QStatusBar {{ background: {c['bg']}; }}
|
|
71
|
+
QStatusBar QLabel {{ background: transparent; }}
|
|
72
|
+
QProgressBar {{ border: 1px solid {c['border']}; border-radius: 4px; background: {c['card']}; }}
|
|
73
|
+
QProgressBar::chunk {{ background: {c['primary']}; border-radius: 3px; }}
|
|
74
|
+
QSplitter::handle {{ background: {c['border']}; }}
|
|
75
|
+
QScrollBar:vertical {{ background: {c['bg']}; width: 10px; }}
|
|
76
|
+
QScrollBar::handle:vertical {{ background: {c['border']}; border-radius: 5px; min-height: 30px; }}
|
|
77
|
+
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {{ height: 0; }}
|
|
78
|
+
QScrollBar:horizontal {{ background: {c['bg']}; height: 10px; }}
|
|
79
|
+
QScrollBar::handle:horizontal {{ background: {c['border']}; border-radius: 5px; min-width: 30px; }}
|
|
80
|
+
QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal {{ width: 0; }}
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def apply(app) -> str:
|
|
85
|
+
"""应用字体与样式表,返回实际使用的字体名。"""
|
|
86
|
+
global _family
|
|
87
|
+
from PySide6.QtGui import QFont, QFontDatabase
|
|
88
|
+
|
|
89
|
+
families = set(QFontDatabase.families())
|
|
90
|
+
for name in FONT_CANDIDATES:
|
|
91
|
+
if name in families:
|
|
92
|
+
_family = name
|
|
93
|
+
break
|
|
94
|
+
# 整数像素字号 + 完整 hinting:高分屏下避免 pt 换算出小数像素导致笔画发虚
|
|
95
|
+
font = QFont(_family)
|
|
96
|
+
font.setPixelSize(14)
|
|
97
|
+
font.setHintingPreference(QFont.PreferFullHinting)
|
|
98
|
+
app.setFont(font)
|
|
99
|
+
app.setStyleSheet(_qss())
|
|
100
|
+
return _family
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""卡片组件:白底细边框卡片与复选框。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from PySide6.QtWidgets import QCheckBox, QFrame, QVBoxLayout
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def make_card(parent=None, padding: int = 16) -> QFrame:
|
|
9
|
+
card = QFrame(parent)
|
|
10
|
+
card.setObjectName("Card")
|
|
11
|
+
layout = QVBoxLayout(card)
|
|
12
|
+
layout.setContentsMargins(padding, padding, padding, padding)
|
|
13
|
+
layout.setSpacing(8)
|
|
14
|
+
return card
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def make_checkbutton(parent, text: str, checked: bool = False) -> QCheckBox:
|
|
18
|
+
box = QCheckBox(text, parent)
|
|
19
|
+
box.setChecked(checked)
|
|
20
|
+
return box
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""顶部文件条:选择 Word 文件、显示/选择工作簿、打开所在文件夹(长地址自动换行完整显示)。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Callable
|
|
7
|
+
|
|
8
|
+
from PySide6.QtWidgets import QGridLayout, QLabel, QPushButton, QWidget
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FileBar(QWidget):
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
parent,
|
|
15
|
+
on_pick_docx: Callable[[], None],
|
|
16
|
+
on_pick_excel: Callable[[], None],
|
|
17
|
+
on_reset_excel: Callable[[], None],
|
|
18
|
+
on_open_folder: Callable[[], None],
|
|
19
|
+
):
|
|
20
|
+
super().__init__(parent)
|
|
21
|
+
self.setStyleSheet("FileBar { background: #FFFFFF; }")
|
|
22
|
+
grid = QGridLayout(self)
|
|
23
|
+
grid.setContentsMargins(16, 10, 16, 10)
|
|
24
|
+
grid.setHorizontalSpacing(8)
|
|
25
|
+
grid.setVerticalSpacing(6)
|
|
26
|
+
grid.setColumnStretch(1, 1)
|
|
27
|
+
|
|
28
|
+
grid.addWidget(QLabel("Word 文件"), 0, 0)
|
|
29
|
+
self.docx_box = self._make_path_box()
|
|
30
|
+
grid.addWidget(self.docx_box, 0, 1)
|
|
31
|
+
btn = QPushButton("选择…")
|
|
32
|
+
btn.clicked.connect(lambda _checked=False: on_pick_docx())
|
|
33
|
+
grid.addWidget(btn, 0, 2)
|
|
34
|
+
btn = QPushButton("打开所在文件夹")
|
|
35
|
+
btn.clicked.connect(lambda _checked=False: on_open_folder())
|
|
36
|
+
grid.addWidget(btn, 0, 3)
|
|
37
|
+
|
|
38
|
+
grid.addWidget(QLabel("Excel 工作簿"), 1, 0)
|
|
39
|
+
self.excel_box = self._make_path_box()
|
|
40
|
+
grid.addWidget(self.excel_box, 1, 1)
|
|
41
|
+
btn = QPushButton("选择…")
|
|
42
|
+
btn.clicked.connect(lambda _checked=False: on_pick_excel())
|
|
43
|
+
grid.addWidget(btn, 1, 2)
|
|
44
|
+
btn = QPushButton("用默认名")
|
|
45
|
+
btn.clicked.connect(lambda _checked=False: on_reset_excel())
|
|
46
|
+
grid.addWidget(btn, 1, 3)
|
|
47
|
+
|
|
48
|
+
@staticmethod
|
|
49
|
+
def _make_path_box() -> QLabel:
|
|
50
|
+
box = QLabel("(未选择)")
|
|
51
|
+
box.setObjectName("PathBox")
|
|
52
|
+
box.setWordWrap(True)
|
|
53
|
+
box.setMinimumWidth(0)
|
|
54
|
+
return box
|
|
55
|
+
|
|
56
|
+
def set_paths(self, docx: Path | None, excel: Path | None) -> None:
|
|
57
|
+
self.docx_box.setText(str(docx) if docx else "(未选择)")
|
|
58
|
+
self.excel_box.setText(str(excel) if excel else "(未选择)")
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""右侧日志区:分色显示、清空/复制/保存、自动滚动开关、隐藏按钮。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import html
|
|
6
|
+
from typing import Callable
|
|
7
|
+
|
|
8
|
+
from PySide6.QtWidgets import (
|
|
9
|
+
QCheckBox,
|
|
10
|
+
QFileDialog,
|
|
11
|
+
QHBoxLayout,
|
|
12
|
+
QLabel,
|
|
13
|
+
QMessageBox,
|
|
14
|
+
QPlainTextEdit,
|
|
15
|
+
QPushButton,
|
|
16
|
+
QVBoxLayout,
|
|
17
|
+
QWidget,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
LEVEL_TAGS = {
|
|
21
|
+
"info": ("#1F2937", False),
|
|
22
|
+
"muted": ("#6B7280", False),
|
|
23
|
+
"ok": ("#15803D", False),
|
|
24
|
+
"warn": ("#B45309", False),
|
|
25
|
+
"error": ("#B91C1C", False),
|
|
26
|
+
"step": ("#1F4E79", True),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class LogPane(QWidget):
|
|
31
|
+
def __init__(self, parent, on_hide: Callable[[], None] | None = None):
|
|
32
|
+
super().__init__(parent)
|
|
33
|
+
layout = QVBoxLayout(self)
|
|
34
|
+
layout.setContentsMargins(8, 8, 8, 8)
|
|
35
|
+
layout.setSpacing(8)
|
|
36
|
+
|
|
37
|
+
header = QHBoxLayout()
|
|
38
|
+
header.setSpacing(6)
|
|
39
|
+
title = QLabel("运行日志")
|
|
40
|
+
title.setObjectName("SectionTitle")
|
|
41
|
+
header.addWidget(title)
|
|
42
|
+
header.addStretch(1)
|
|
43
|
+
if on_hide is not None:
|
|
44
|
+
btn = QPushButton("隐藏")
|
|
45
|
+
btn.setObjectName("LogTool")
|
|
46
|
+
btn.clicked.connect(lambda _checked=False: on_hide())
|
|
47
|
+
header.addWidget(btn)
|
|
48
|
+
layout.addLayout(header)
|
|
49
|
+
|
|
50
|
+
tools = QHBoxLayout()
|
|
51
|
+
tools.setSpacing(6)
|
|
52
|
+
self.auto_scroll = QCheckBox("自动滚动")
|
|
53
|
+
self.auto_scroll.setChecked(True)
|
|
54
|
+
tools.addWidget(self.auto_scroll)
|
|
55
|
+
tools.addStretch(1)
|
|
56
|
+
for text, slot in (("复制全部", self.copy_all), ("保存…", self.save_to_file), ("清空", self.clear)):
|
|
57
|
+
btn = QPushButton(text)
|
|
58
|
+
btn.setObjectName("LogTool")
|
|
59
|
+
btn.clicked.connect(lambda _checked=False, fn=slot: fn())
|
|
60
|
+
tools.addWidget(btn)
|
|
61
|
+
layout.addLayout(tools)
|
|
62
|
+
|
|
63
|
+
self.text = QPlainTextEdit()
|
|
64
|
+
self.text.setObjectName("LogText")
|
|
65
|
+
self.text.setReadOnly(True)
|
|
66
|
+
self.text.setLineWrapMode(QPlainTextEdit.WidgetWidth)
|
|
67
|
+
layout.addWidget(self.text, 1)
|
|
68
|
+
|
|
69
|
+
def append(self, message: str, level: str = "info") -> None:
|
|
70
|
+
color, bold = LEVEL_TAGS.get(level, LEVEL_TAGS["info"])
|
|
71
|
+
body = html.escape(message).replace("\n", "<br>")
|
|
72
|
+
if bold:
|
|
73
|
+
body = f"<b>{body}</b>"
|
|
74
|
+
self.text.appendHtml(f'<span style="color:{color};">{body}</span>')
|
|
75
|
+
if self.auto_scroll.isChecked():
|
|
76
|
+
bar = self.text.verticalScrollBar()
|
|
77
|
+
bar.setValue(bar.maximum())
|
|
78
|
+
|
|
79
|
+
def clear(self) -> None:
|
|
80
|
+
self.text.clear()
|
|
81
|
+
|
|
82
|
+
def content(self) -> str:
|
|
83
|
+
return self.text.toPlainText()
|
|
84
|
+
|
|
85
|
+
def copy_all(self) -> None:
|
|
86
|
+
text = self.content()
|
|
87
|
+
if not text.strip():
|
|
88
|
+
return
|
|
89
|
+
from PySide6.QtWidgets import QApplication
|
|
90
|
+
|
|
91
|
+
QApplication.clipboard().setText(text)
|
|
92
|
+
QMessageBox.information(self, "复制成功", "日志已复制到剪贴板。")
|
|
93
|
+
|
|
94
|
+
def save_to_file(self) -> None:
|
|
95
|
+
text = self.content()
|
|
96
|
+
if not text.strip():
|
|
97
|
+
QMessageBox.information(self, "没有日志", "当前没有可保存的日志内容。")
|
|
98
|
+
return
|
|
99
|
+
path, _ = QFileDialog.getSaveFileName(
|
|
100
|
+
self, "保存运行日志", "运行日志.txt", "文本文件 (*.txt);;所有文件 (*.*)"
|
|
101
|
+
)
|
|
102
|
+
if not path:
|
|
103
|
+
return
|
|
104
|
+
try:
|
|
105
|
+
with open(path, "w", encoding="utf-8") as handle:
|
|
106
|
+
handle.write(text + "\n")
|
|
107
|
+
except OSError as exc:
|
|
108
|
+
QMessageBox.critical(self, "保存失败", f"写入文件失败:{exc}")
|
|
109
|
+
return
|
|
110
|
+
QMessageBox.information(self, "保存成功", f"日志已保存到:\n{path}")
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""左侧导航:功能列表 + 当前项高亮。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Callable
|
|
6
|
+
|
|
7
|
+
from PySide6.QtWidgets import QLabel, QPushButton, QVBoxLayout, QWidget
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class NavBar(QWidget):
|
|
11
|
+
def __init__(self, parent, on_select: Callable[[str], None]):
|
|
12
|
+
super().__init__(parent)
|
|
13
|
+
self.setObjectName("Nav")
|
|
14
|
+
self.setStyleSheet("QWidget#Nav { background: #FFFFFF; }")
|
|
15
|
+
self._on_select = on_select
|
|
16
|
+
self._buttons: dict[str, QPushButton] = {}
|
|
17
|
+
|
|
18
|
+
layout = QVBoxLayout(self)
|
|
19
|
+
layout.setContentsMargins(10, 14, 10, 14)
|
|
20
|
+
layout.setSpacing(6)
|
|
21
|
+
title = QLabel("审计工具箱")
|
|
22
|
+
title.setObjectName("NavTitle")
|
|
23
|
+
layout.addWidget(title)
|
|
24
|
+
self._body = QVBoxLayout()
|
|
25
|
+
self._body.setSpacing(6)
|
|
26
|
+
layout.addLayout(self._body)
|
|
27
|
+
layout.addStretch(1)
|
|
28
|
+
|
|
29
|
+
def add_item(self, key: str, text: str) -> None:
|
|
30
|
+
button = QPushButton(text)
|
|
31
|
+
button.setObjectName("Nav")
|
|
32
|
+
button.setCheckable(True)
|
|
33
|
+
button.clicked.connect(lambda _checked=False, k=key: self._on_select(k))
|
|
34
|
+
self._body.addWidget(button)
|
|
35
|
+
self._buttons[key] = button
|
|
36
|
+
|
|
37
|
+
def select(self, key: str) -> None:
|
|
38
|
+
for item_key, button in self._buttons.items():
|
|
39
|
+
button.setChecked(item_key == key)
|