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,271 @@
|
|
|
1
|
+
"""界面统一视觉:配色、字体与 Qt 样式表。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
FONT_CANDIDATES = ("Microsoft YaHei UI", "Microsoft YaHei", "微软雅黑", "SimHei", "SimSun")
|
|
6
|
+
APPEARANCE_MODES = ("system", "light", "dark")
|
|
7
|
+
APPEARANCE_LABELS = {"system": "系统", "light": "浅色", "dark": "深色"}
|
|
8
|
+
|
|
9
|
+
PALETTES = {
|
|
10
|
+
"light": {
|
|
11
|
+
"primary": "#0F6CBD",
|
|
12
|
+
"primary_hover": "#115EA3",
|
|
13
|
+
"primary_soft": "#EAF3FC",
|
|
14
|
+
"bg": "#F4F6F9",
|
|
15
|
+
"card": "#FFFFFF",
|
|
16
|
+
"surface": "#F8FAFC",
|
|
17
|
+
"border": "#E3E8EF",
|
|
18
|
+
"border_hover": "#C8D2DE",
|
|
19
|
+
"text": "#172033",
|
|
20
|
+
"muted": "#667085",
|
|
21
|
+
"success": "#15803D",
|
|
22
|
+
"success_soft": "#E9F7F1",
|
|
23
|
+
"warning": "#B45309",
|
|
24
|
+
"error": "#B91C1C",
|
|
25
|
+
"disabled": "#98A2B3",
|
|
26
|
+
"disabled_bg": "#CBD5E1",
|
|
27
|
+
"disabled_text": "#F2F5F8",
|
|
28
|
+
"nav": "#FFFFFF",
|
|
29
|
+
"nav_hover": "#F0F5FA",
|
|
30
|
+
"nav_pressed": "#E6EDF5",
|
|
31
|
+
"nav_group": "#8A94A3",
|
|
32
|
+
"nav_group_hover": "#4B5563",
|
|
33
|
+
"input": "#FFFFFF",
|
|
34
|
+
"log_bg": "#FBFCFD",
|
|
35
|
+
"scroll": "#CDD5DF",
|
|
36
|
+
"scroll_hover": "#AAB6C4",
|
|
37
|
+
"tooltip_bg": "#172033",
|
|
38
|
+
"tooltip_text": "#FFFFFF",
|
|
39
|
+
"on_primary": "#FFFFFF",
|
|
40
|
+
"adjust_bg": "#F7FBFF",
|
|
41
|
+
"adjust_border": "#CFE2F7",
|
|
42
|
+
"switch_off": "#CBD5E1",
|
|
43
|
+
"switch_off_hover": "#AEBCCD",
|
|
44
|
+
},
|
|
45
|
+
"dark": {
|
|
46
|
+
"primary": "#6EA8FE",
|
|
47
|
+
"primary_hover": "#8AB4FF",
|
|
48
|
+
"primary_soft": "#193554",
|
|
49
|
+
"bg": "#111827",
|
|
50
|
+
"card": "#1B2430",
|
|
51
|
+
"surface": "#202C3B",
|
|
52
|
+
"border": "#344256",
|
|
53
|
+
"border_hover": "#4A5B73",
|
|
54
|
+
"text": "#E5ECF5",
|
|
55
|
+
"muted": "#9AA9BC",
|
|
56
|
+
"success": "#5BC98C",
|
|
57
|
+
"success_soft": "#183B31",
|
|
58
|
+
"warning": "#F0B45D",
|
|
59
|
+
"error": "#FF8080",
|
|
60
|
+
"disabled": "#5F7087",
|
|
61
|
+
"disabled_bg": "#303E50",
|
|
62
|
+
"disabled_text": "#8190A5",
|
|
63
|
+
"nav": "#172130",
|
|
64
|
+
"nav_hover": "#233247",
|
|
65
|
+
"nav_pressed": "#2B3C54",
|
|
66
|
+
"nav_group": "#91A1B5",
|
|
67
|
+
"nav_group_hover": "#C3CFDD",
|
|
68
|
+
"input": "#111927",
|
|
69
|
+
"log_bg": "#101925",
|
|
70
|
+
"scroll": "#43536A",
|
|
71
|
+
"scroll_hover": "#62748D",
|
|
72
|
+
"tooltip_bg": "#2B3C54",
|
|
73
|
+
"tooltip_text": "#F7FAFC",
|
|
74
|
+
"on_primary": "#0E1B2B",
|
|
75
|
+
"adjust_bg": "#162C46",
|
|
76
|
+
"adjust_border": "#2C5278",
|
|
77
|
+
"switch_off": "#3D4C61",
|
|
78
|
+
"switch_off_hover": "#50617A",
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
_effective = "light"
|
|
83
|
+
_family = FONT_CANDIDATES[0]
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def normalize_mode(value) -> str:
|
|
87
|
+
mode = value.lower() if isinstance(value, str) else ""
|
|
88
|
+
return mode if mode in APPEARANCE_MODES else "system"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def resolve_mode(app, mode: str) -> str:
|
|
92
|
+
mode = normalize_mode(mode)
|
|
93
|
+
if mode != "system":
|
|
94
|
+
return mode
|
|
95
|
+
scheme = app.styleHints().colorScheme()
|
|
96
|
+
return "dark" if getattr(scheme, "name", "").lower() == "dark" else "light"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def colors(mode: str | None = None) -> dict[str, str]:
|
|
100
|
+
return PALETTES[mode] if mode in PALETTES else PALETTES[_effective]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def effective_mode() -> str:
|
|
104
|
+
return _effective
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def font_family() -> str:
|
|
108
|
+
return _family
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _qss(c: dict[str, str]) -> str:
|
|
112
|
+
return f"""
|
|
113
|
+
QWidget {{ background: {c['bg']}; color: {c['text']}; }}
|
|
114
|
+
QMainWindow, QStackedWidget, QScrollArea {{ background: {c['bg']}; }}
|
|
115
|
+
QScrollArea {{ border: none; }}
|
|
116
|
+
QLabel {{ background: transparent; }}
|
|
117
|
+
QWidget#FileBar {{ background: {c['card']}; }}
|
|
118
|
+
QWidget#Nav {{ background: {c['nav']}; }}
|
|
119
|
+
QFrame#Card {{ background: {c['card']}; border: 1px solid {c['border']}; border-radius: 12px; }}
|
|
120
|
+
QFrame#Card QLabel, QFrame#Card QCheckBox {{ background: transparent; }}
|
|
121
|
+
QFrame#AdjustBlock {{ background: {c['adjust_bg']}; border: 1px solid {c['adjust_border']}; border-radius: 10px; }}
|
|
122
|
+
QFrame#AdjustBlock QLabel, QFrame#AdjustBlock QCheckBox {{ background: transparent; }}
|
|
123
|
+
QLabel#PageTitle {{ font-size: 22px; font-weight: 600; color: {c['text']}; }}
|
|
124
|
+
QLabel#Desc {{ color: {c['muted']}; font-size: 13px; }}
|
|
125
|
+
QLabel#CardDesc {{ color: {c['muted']}; font-size: 12px; }}
|
|
126
|
+
QLabel#SectionTitle {{ font-size: 15px; font-weight: 600; color: {c['text']}; }}
|
|
127
|
+
QLabel#SettingTitle {{ font-size: 15px; font-weight: 600; }}
|
|
128
|
+
QLabel#SettingName {{ font-weight: 600; }}
|
|
129
|
+
QLabel#SettingTag {{ color: {c['primary']}; background: {c['primary_soft']}; border-radius: 10px; padding: 2px 9px; font-size: 11px; }}
|
|
130
|
+
QLabel#OptionHint {{ color: {c['muted']}; font-size: 12px; }}
|
|
131
|
+
QLabel#RiskHint {{ color: {c['warning']}; font-size: 12px; }}
|
|
132
|
+
QLabel#Status {{ color: {c['muted']}; font-size: 12px; }}
|
|
133
|
+
QLabel#Version {{ color: {c['muted']}; font-size: 12px; }}
|
|
134
|
+
QLabel#Notice {{ color: {c['primary']}; }}
|
|
135
|
+
QLabel#ContactEmail {{ color: {c['primary']}; font-size: 18px; font-weight: 600; }}
|
|
136
|
+
QLabel#ContactTag {{ color: {c['success']}; background: {c['success_soft']}; border-radius: 10px; padding: 3px 9px; font-size: 11px; }}
|
|
137
|
+
QLabel#NavTitle {{ color: {c['muted']}; font-size: 12px; font-weight: 600; }}
|
|
138
|
+
QFrame#ContactBanner {{ border-left: 4px solid {c['primary']}; }}
|
|
139
|
+
QFrame#DonationPlaceholder {{ background: {c['surface']}; border: 1px dashed {c['border_hover']}; border-radius: 8px; color: {c['muted']}; }}
|
|
140
|
+
QPushButton#NavBrand {{ background: transparent; border: none; color: {c['text']}; text-align: left; padding: 0; font-size: 15px; font-weight: 700; }}
|
|
141
|
+
QPushButton#NavBrand:hover {{ color: {c['primary']}; }}
|
|
142
|
+
QPushButton#NavGroup {{ background: transparent; border: none; color: {c['nav_group']}; font-size: 12px; font-weight: 600; padding: 6px 10px 2px; text-align: left; }}
|
|
143
|
+
QPushButton#NavGroup:hover {{ color: {c['nav_group_hover']}; }}
|
|
144
|
+
QWidget#NavGroupItems {{ background: transparent; }}
|
|
145
|
+
QWidget#NavIndicator {{ background: {c['primary']}; border-radius: 2px; }}
|
|
146
|
+
QLabel#PathBox {{ background: {c['card']}; border: 1px solid {c['border']}; border-radius: 6px; padding: 6px 8px; }}
|
|
147
|
+
QPushButton {{ background: {c['card']}; border: 1px solid {c['border']}; border-radius: 7px; padding: 7px 16px; min-height: 18px; font-size: 13px; }}
|
|
148
|
+
QPushButton:hover {{ background: {c['nav_hover']}; border-color: {c['border_hover']}; }}
|
|
149
|
+
QPushButton:pressed {{ background: {c['nav_pressed']}; }}
|
|
150
|
+
QPushButton:disabled {{ background: {c['bg']}; color: {c['disabled']}; border-color: {c['border']}; }}
|
|
151
|
+
QPushButton#Primary {{ background: {c['primary']}; color: {c['on_primary']}; border: 1px solid {c['primary']}; font-size: 14px; font-weight: 600; padding: 8px 22px; }}
|
|
152
|
+
QPushButton#Primary:hover {{ background: {c['primary_hover']}; border-color: {c['primary_hover']}; }}
|
|
153
|
+
QPushButton#Primary:disabled {{ background: {c['disabled_bg']}; color: {c['disabled_text']}; border-color: {c['disabled_bg']}; }}
|
|
154
|
+
/* 首次启动的外观选择:整块可点的选项卡,选中态用主色描边 */
|
|
155
|
+
QLabel#DialogTitle {{ color: {c['text']}; font-size: 16px; font-weight: 700; }}
|
|
156
|
+
QPushButton#ThemeOption {{ background: {c['surface']}; color: {c['text']}; border: 1px solid {c['border']}; border-radius: 10px; padding: 10px 12px; font-size: 13px; text-align: center; }}
|
|
157
|
+
QPushButton#ThemeOption:hover {{ background: {c['nav_hover']}; border-color: {c['border_hover']}; }}
|
|
158
|
+
QPushButton#ThemeOption:checked {{ background: {c['primary_soft']}; color: {c['primary']}; border: 2px solid {c['primary']}; font-weight: 600; }}
|
|
159
|
+
/* 胶囊开关外观由 _Switch.paintEvent 自绘;这里只清掉按钮默认的边框与文字内边距,
|
|
160
|
+
避免样式表与自绘叠加出方形底或文字残影。 */
|
|
161
|
+
QPushButton#SettingSwitch {{ border: none; background: transparent; padding: 0; min-width: 0; }}
|
|
162
|
+
QPushButton#SettingSwitch:focus {{ outline: none; }}
|
|
163
|
+
QWidget#ExportActions QPushButton {{ padding: 7px 10px; }}
|
|
164
|
+
QWidget#ExportActions QPushButton#Primary {{ padding: 7px 14px; }}
|
|
165
|
+
/* min-height 在 Qt 样式表里指内容区高度,不含 padding;这里同时压 max-height 才能真的矮下来 */
|
|
166
|
+
QPushButton#Nav {{ text-align: left; border: none; background: transparent; padding: 3px 12px; min-height: 26px; max-height: 26px; font-size: 13px; border-radius: 8px; }}
|
|
167
|
+
QPushButton#Nav:hover {{ background: {c['nav_hover']}; }}
|
|
168
|
+
QPushButton#Nav:pressed {{ background: {c['nav_pressed']}; }}
|
|
169
|
+
QPushButton#Nav:checked {{ background: {c['primary_soft']}; color: {c['primary']}; font-weight: 600; }}
|
|
170
|
+
QWidget#Nav[collapsed="true"] QPushButton#Nav {{ padding: 0; min-width: 46px; max-width: 46px; }}
|
|
171
|
+
QPushButton#LogTool {{ padding: 4px 10px; font-size: 12px; }}
|
|
172
|
+
QFrame#OptionTile {{ background: {c['surface']}; border: 1px solid {c['border']}; border-radius: 9px; }}
|
|
173
|
+
QFrame#OptionTile:hover {{ background: {c['nav_hover']}; border-color: {c['border_hover']}; }}
|
|
174
|
+
QFrame#OptionTile QCheckBox {{ font-weight: 500; }}
|
|
175
|
+
/* 胶囊勾选项:底色与描边由 Chip.paintEvent 自绘(QWidget 不支持样式表圆角),
|
|
176
|
+
这里只管文字与图标的颜色。 */
|
|
177
|
+
QWidget#Chip QLabel#ChipText {{ color: {c['text']}; font-size: 13px; font-weight: 500; background: transparent; border: none; }}
|
|
178
|
+
QWidget#Chip[checked="true"] QLabel#ChipText {{ color: {c['primary']}; font-weight: 600; }}
|
|
179
|
+
QWidget#Chip QLabel#ChipIcon {{ background: transparent; border: none; }}
|
|
180
|
+
QCheckBox {{ background: transparent; spacing: 7px; }}
|
|
181
|
+
QCheckBox::indicator {{ width: 16px; height: 16px; }}
|
|
182
|
+
QRadioButton {{ background: transparent; spacing: 8px; }}
|
|
183
|
+
QRadioButton::indicator {{ width: 16px; height: 16px; border: 2px solid {c['disabled']}; border-radius: 9px; background: {c['card']}; }}
|
|
184
|
+
QRadioButton::indicator:hover {{ border-color: {c['primary_hover']}; }}
|
|
185
|
+
QRadioButton::indicator:checked {{ border: 5px solid {c['primary']}; border-radius: 13px; background: {c['card']}; }}
|
|
186
|
+
QRadioButton:checked {{ color: {c['primary']}; font-weight: 600; }}
|
|
187
|
+
QPlainTextEdit, QTextEdit {{ background: {c['input']}; border: 1px solid {c['border']}; border-radius: 6px; padding: 6px; }}
|
|
188
|
+
QPlainTextEdit#LogText {{ background: {c['log_bg']}; border-radius: 7px; padding: 0; font-size: 13px; }}
|
|
189
|
+
QLineEdit, QSpinBox, QComboBox {{ background: {c['input']}; border: 1px solid {c['border']}; border-radius: 6px; padding: 6px 8px; min-height: 18px; }}
|
|
190
|
+
QLineEdit:focus, QSpinBox:focus, QComboBox:focus {{ border-color: {c['primary']}; }}
|
|
191
|
+
QComboBox QAbstractItemView {{ background: {c['card']}; color: {c['text']}; border: 1px solid {c['border']}; selection-background-color: {c['primary']}; selection-color: {c['on_primary']}; }}
|
|
192
|
+
QListWidget, QTableWidget {{ background: {c['card']}; alternate-background-color: {c['surface']}; color: {c['text']}; gridline-color: {c['border']}; }}
|
|
193
|
+
QListWidget#ManualChapters {{ border: 1px solid {c['border']}; border-radius: 8px; padding: 4px; outline: 0; }}
|
|
194
|
+
QListWidget#ManualChapters::item {{ padding: 8px 10px; border-radius: 5px; }}
|
|
195
|
+
QListWidget#ManualChapters::item:selected {{ background: {c['primary_soft']}; color: {c['primary']}; font-weight: 600; }}
|
|
196
|
+
QHeaderView::section {{ background: {c['surface']}; color: {c['text']}; border: 1px solid {c['border']}; padding: 5px; }}
|
|
197
|
+
QTextBrowser#ManualView {{ background: {c['card']}; border: 1px solid {c['border']}; border-radius: 8px; }}
|
|
198
|
+
QTabWidget::pane {{ border: 1px solid {c['border']}; border-radius: 9px; background: {c['card']}; top: -1px; }}
|
|
199
|
+
QTabBar::tab {{ background: transparent; border: none; border-bottom: 2px solid transparent; padding: 9px 18px; color: {c['muted']}; }}
|
|
200
|
+
QTabBar::tab:selected {{ background: transparent; color: {c['primary']}; font-weight: 600; border-bottom-color: {c['primary']}; }}
|
|
201
|
+
QTabBar::tab:hover {{ color: {c['primary']}; }}
|
|
202
|
+
QMenu {{ background: {c['card']}; color: {c['text']}; border: 1px solid {c['border']}; padding: 4px; }}
|
|
203
|
+
QMenu::item {{ padding: 6px 20px; border-radius: 4px; }}
|
|
204
|
+
QMenu::item:selected {{ background: {c['primary_soft']}; color: {c['primary']}; }}
|
|
205
|
+
QStatusBar {{ background: {c['bg']}; }}
|
|
206
|
+
QStatusBar QLabel {{ background: transparent; }}
|
|
207
|
+
QProgressBar {{ border: 1px solid {c['border']}; border-radius: 5px; background: {c['card']}; text-align: center; }}
|
|
208
|
+
QProgressBar::chunk {{ background: {c['primary']}; border-radius: 4px; }}
|
|
209
|
+
QSplitter::handle {{ background: {c['border']}; }}
|
|
210
|
+
QScrollBar:vertical {{ background: transparent; width: 10px; margin: 2px; }}
|
|
211
|
+
QScrollBar::handle:vertical {{ background: {c['scroll']}; border-radius: 5px; min-height: 30px; }}
|
|
212
|
+
QScrollBar::handle:vertical:hover {{ background: {c['scroll_hover']}; }}
|
|
213
|
+
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {{ height: 0; }}
|
|
214
|
+
QScrollBar:horizontal {{ background: transparent; height: 10px; margin: 2px; }}
|
|
215
|
+
QScrollBar::handle:horizontal {{ background: {c['scroll']}; border-radius: 5px; min-width: 30px; }}
|
|
216
|
+
QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal {{ width: 0; }}
|
|
217
|
+
QToolTip {{ background: {c['tooltip_bg']}; color: {c['tooltip_text']}; border: none; padding: 6px 8px; border-radius: 5px; }}
|
|
218
|
+
"""
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def _palette(c: dict[str, str]):
|
|
222
|
+
from PySide6.QtGui import QColor, QPalette
|
|
223
|
+
|
|
224
|
+
palette = QPalette()
|
|
225
|
+
roles = {
|
|
226
|
+
QPalette.Window: "bg",
|
|
227
|
+
QPalette.WindowText: "text",
|
|
228
|
+
QPalette.Base: "input",
|
|
229
|
+
QPalette.AlternateBase: "surface",
|
|
230
|
+
QPalette.Text: "text",
|
|
231
|
+
QPalette.Button: "card",
|
|
232
|
+
QPalette.ButtonText: "text",
|
|
233
|
+
QPalette.BrightText: "on_primary",
|
|
234
|
+
QPalette.ToolTipBase: "tooltip_bg",
|
|
235
|
+
QPalette.ToolTipText: "tooltip_text",
|
|
236
|
+
QPalette.Highlight: "primary",
|
|
237
|
+
QPalette.HighlightedText: "on_primary",
|
|
238
|
+
QPalette.Link: "primary",
|
|
239
|
+
QPalette.LinkVisited: "primary",
|
|
240
|
+
QPalette.PlaceholderText: "muted",
|
|
241
|
+
}
|
|
242
|
+
for role, key in roles.items():
|
|
243
|
+
palette.setColor(role, QColor(c[key]))
|
|
244
|
+
for role in (QPalette.Text, QPalette.ButtonText, QPalette.WindowText):
|
|
245
|
+
palette.setColor(QPalette.Disabled, role, QColor(c["disabled"]))
|
|
246
|
+
for role in (QPalette.Base, QPalette.Button, QPalette.Window):
|
|
247
|
+
palette.setColor(QPalette.Disabled, role, QColor(c["disabled_bg"]))
|
|
248
|
+
return palette
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def apply(app, mode: str = "system") -> str:
|
|
252
|
+
"""应用外观、字体与样式表,返回实际使用的字体名。"""
|
|
253
|
+
global _family, _effective
|
|
254
|
+
from PySide6.QtGui import QFont, QFontDatabase
|
|
255
|
+
|
|
256
|
+
mode = normalize_mode(mode)
|
|
257
|
+
_effective = resolve_mode(app, mode)
|
|
258
|
+
c = PALETTES[_effective]
|
|
259
|
+
families = set(QFontDatabase.families())
|
|
260
|
+
for name in FONT_CANDIDATES:
|
|
261
|
+
if name in families:
|
|
262
|
+
_family = name
|
|
263
|
+
break
|
|
264
|
+
# 整数像素字号 + 完整 hinting:高分屏下避免 pt 换算出小数像素导致笔画发虚
|
|
265
|
+
font = QFont(_family)
|
|
266
|
+
font.setPixelSize(14)
|
|
267
|
+
font.setHintingPreference(QFont.PreferFullHinting)
|
|
268
|
+
app.setFont(font)
|
|
269
|
+
app.setPalette(_palette(c))
|
|
270
|
+
app.setStyleSheet(_qss(c))
|
|
271
|
+
return _family
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"""AI 大模型配置卡片:供「全局设置」页使用。
|
|
2
|
+
|
|
3
|
+
独立成组件的原因:
|
|
4
|
+
- 配置项多(服务商/地址/模型/密钥/隐私/超时/字数),塞进设置页会让该文件过长;
|
|
5
|
+
- 配置存 `.wesync_ai.json`,与设置页的 `.wesync_ui.json` 是两份文件,
|
|
6
|
+
所以本卡片自带「保存 AI 配置」按钮,不混用设置页的主保存按钮。
|
|
7
|
+
|
|
8
|
+
边界:只读写配置文件与发一次连通性测试,不碰报告。
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from PySide6.QtCore import Qt
|
|
14
|
+
from PySide6.QtWidgets import (
|
|
15
|
+
QComboBox,
|
|
16
|
+
QFormLayout,
|
|
17
|
+
QFrame,
|
|
18
|
+
QHBoxLayout,
|
|
19
|
+
QLabel,
|
|
20
|
+
QLineEdit,
|
|
21
|
+
QPushButton,
|
|
22
|
+
QVBoxLayout,
|
|
23
|
+
QWidget,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from ... import api
|
|
27
|
+
from .cards import make_card, make_checkbutton
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class AiConfigCard(QFrame):
|
|
31
|
+
"""AI 大模型配置卡片;调用方负责把它放进页面布局。"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, ctx, parent=None):
|
|
34
|
+
super().__init__(parent)
|
|
35
|
+
self.ctx = ctx
|
|
36
|
+
self._providers: dict[str, dict] = {}
|
|
37
|
+
self._saved_key_mask = ""
|
|
38
|
+
self._has_key = False
|
|
39
|
+
self._busy_kind: str | None = None
|
|
40
|
+
self._pending: dict = {}
|
|
41
|
+
|
|
42
|
+
card = make_card(self)
|
|
43
|
+
outer = QVBoxLayout(self)
|
|
44
|
+
outer.setContentsMargins(0, 0, 0, 0)
|
|
45
|
+
outer.addWidget(card)
|
|
46
|
+
self._card = card
|
|
47
|
+
|
|
48
|
+
header = QWidget()
|
|
49
|
+
header_layout = QHBoxLayout(header)
|
|
50
|
+
header_layout.setContentsMargins(0, 0, 0, 4)
|
|
51
|
+
title = QLabel("AI 大模型")
|
|
52
|
+
title.setObjectName("SettingTitle")
|
|
53
|
+
header_layout.addWidget(title)
|
|
54
|
+
header_layout.addStretch(1)
|
|
55
|
+
tag = QLabel("可选 · 默认关闭")
|
|
56
|
+
tag.setObjectName("SettingTag")
|
|
57
|
+
header_layout.addWidget(tag)
|
|
58
|
+
card.layout().addWidget(header)
|
|
59
|
+
|
|
60
|
+
self.enabled_switch = make_checkbutton(card, "启用 AI", False)
|
|
61
|
+
self.enabled_switch.toggled.connect(self._refresh_enabled)
|
|
62
|
+
card.layout().addWidget(self.enabled_switch)
|
|
63
|
+
|
|
64
|
+
form = QFormLayout()
|
|
65
|
+
form.setLabelAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
|
66
|
+
form.setContentsMargins(0, 4, 0, 0)
|
|
67
|
+
form.setSpacing(8)
|
|
68
|
+
|
|
69
|
+
self.provider_combo = QComboBox()
|
|
70
|
+
self.provider_combo.currentIndexChanged.connect(self._provider_changed)
|
|
71
|
+
form.addRow("服务商", self.provider_combo)
|
|
72
|
+
|
|
73
|
+
self.base_url_edit = QLineEdit()
|
|
74
|
+
self.base_url_edit.setPlaceholderText("例如 https://api.deepseek.com/v1")
|
|
75
|
+
form.addRow("接口地址", self.base_url_edit)
|
|
76
|
+
|
|
77
|
+
self.model_edit = QComboBox()
|
|
78
|
+
self.model_edit.setEditable(True)
|
|
79
|
+
self.model_edit.setInsertPolicy(QComboBox.NoInsert)
|
|
80
|
+
self.model_edit.lineEdit().setPlaceholderText("例如 deepseek-flash 或 qwen3:8b")
|
|
81
|
+
model_row = QWidget()
|
|
82
|
+
model_layout = QHBoxLayout(model_row)
|
|
83
|
+
model_layout.setContentsMargins(0, 0, 0, 0)
|
|
84
|
+
model_layout.setSpacing(8)
|
|
85
|
+
model_layout.addWidget(self.model_edit, 1)
|
|
86
|
+
self.list_models_button = QPushButton("获取模型列表")
|
|
87
|
+
self.list_models_button.setToolTip("向服务商查询当前可用的模型名,避免手填的名字已过期")
|
|
88
|
+
self.list_models_button.clicked.connect(lambda _checked=False: self._fetch_models())
|
|
89
|
+
model_layout.addWidget(self.list_models_button)
|
|
90
|
+
form.addRow("模型名", model_row)
|
|
91
|
+
|
|
92
|
+
self.provider_hint = QLabel()
|
|
93
|
+
self.provider_hint.setObjectName("CardDesc")
|
|
94
|
+
self.provider_hint.setWordWrap(True)
|
|
95
|
+
self.provider_hint.setMinimumWidth(0)
|
|
96
|
+
form.addRow("", self.provider_hint)
|
|
97
|
+
|
|
98
|
+
self.key_edit = QLineEdit()
|
|
99
|
+
self.key_edit.setEchoMode(QLineEdit.Password)
|
|
100
|
+
self.key_edit.setPlaceholderText("留空表示沿用已保存密钥;本机服务可留空")
|
|
101
|
+
form.addRow("API Key", self.key_edit)
|
|
102
|
+
|
|
103
|
+
self.privacy_combo = QComboBox()
|
|
104
|
+
form.addRow("隐私级别", self.privacy_combo)
|
|
105
|
+
|
|
106
|
+
self.timeout_edit = QLineEdit()
|
|
107
|
+
self.timeout_edit.setPlaceholderText("5~600 秒,默认 60")
|
|
108
|
+
self.timeout_edit.setMaximumWidth(180)
|
|
109
|
+
form.addRow("超时秒数", self.timeout_edit)
|
|
110
|
+
|
|
111
|
+
self.limit_edit = QLineEdit()
|
|
112
|
+
self.limit_edit.setPlaceholderText("每个候选最多发送多少字,默认 200")
|
|
113
|
+
self.limit_edit.setMaximumWidth(180)
|
|
114
|
+
form.addRow("上下文字数", self.limit_edit)
|
|
115
|
+
|
|
116
|
+
card.layout().addLayout(form)
|
|
117
|
+
|
|
118
|
+
self.tip_label = QLabel(
|
|
119
|
+
"只发送本地筛出的候选片段(候选标题、表格前段落、附注边界,及前后各最多 200 字),"
|
|
120
|
+
"绝不发送整篇报告、表格单元格或页眉页脚;接口地址填本机服务时数据不出机器。"
|
|
121
|
+
)
|
|
122
|
+
self.tip_label.setObjectName("CardDesc")
|
|
123
|
+
self.tip_label.setWordWrap(True)
|
|
124
|
+
self.tip_label.setMinimumWidth(0)
|
|
125
|
+
card.layout().addWidget(self.tip_label)
|
|
126
|
+
|
|
127
|
+
row = QWidget()
|
|
128
|
+
row_layout = QHBoxLayout(row)
|
|
129
|
+
row_layout.setContentsMargins(0, 4, 0, 0)
|
|
130
|
+
row_layout.setSpacing(10)
|
|
131
|
+
self.test_button = QPushButton("测试连接")
|
|
132
|
+
self.test_button.clicked.connect(lambda _checked=False: self._test())
|
|
133
|
+
row_layout.addWidget(self.test_button)
|
|
134
|
+
self.save_button = QPushButton("保存 AI 配置")
|
|
135
|
+
self.save_button.setObjectName("Primary")
|
|
136
|
+
self.save_button.clicked.connect(lambda _checked=False: self._save())
|
|
137
|
+
row_layout.addWidget(self.save_button)
|
|
138
|
+
self.reload_button = QPushButton("重新读取")
|
|
139
|
+
self.reload_button.clicked.connect(lambda _checked=False: self.reload())
|
|
140
|
+
row_layout.addWidget(self.reload_button)
|
|
141
|
+
self.status_label = QLabel()
|
|
142
|
+
self.status_label.setObjectName("CardDesc")
|
|
143
|
+
self.status_label.setWordWrap(True)
|
|
144
|
+
self.status_label.setMinimumWidth(0)
|
|
145
|
+
row_layout.addWidget(self.status_label, 1)
|
|
146
|
+
card.layout().addWidget(row)
|
|
147
|
+
|
|
148
|
+
self.reload()
|
|
149
|
+
|
|
150
|
+
# ------------------------------------------------------------------ 数据
|
|
151
|
+
|
|
152
|
+
def is_enabled(self) -> bool:
|
|
153
|
+
return self.enabled_switch.isChecked()
|
|
154
|
+
|
|
155
|
+
def reload(self) -> None:
|
|
156
|
+
try:
|
|
157
|
+
data = api.ai_settings()
|
|
158
|
+
except Exception as exc:
|
|
159
|
+
self.status_label.setText(f"读取 AI 配置失败:{exc}")
|
|
160
|
+
self._set_controls(False)
|
|
161
|
+
return
|
|
162
|
+
self._providers = data.get("providers", {})
|
|
163
|
+
config = data.get("config", {})
|
|
164
|
+
self._saved_key_mask = config.get("api_key_mask", "")
|
|
165
|
+
self._has_key = bool(config.get("has_key"))
|
|
166
|
+
|
|
167
|
+
self.provider_combo.blockSignals(True)
|
|
168
|
+
try:
|
|
169
|
+
self.provider_combo.clear()
|
|
170
|
+
for name, item in self._providers.items():
|
|
171
|
+
self.provider_combo.addItem(item.get("label", name), name)
|
|
172
|
+
index = self.provider_combo.findData(config.get("provider"))
|
|
173
|
+
self.provider_combo.setCurrentIndex(index if index >= 0 else 0)
|
|
174
|
+
finally:
|
|
175
|
+
self.provider_combo.blockSignals(False)
|
|
176
|
+
|
|
177
|
+
self.privacy_combo.clear()
|
|
178
|
+
for name, label in (data.get("privacy_levels") or {}).items():
|
|
179
|
+
self.privacy_combo.addItem(label, name)
|
|
180
|
+
index = self.privacy_combo.findData(config.get("privacy_level"))
|
|
181
|
+
self.privacy_combo.setCurrentIndex(index if index >= 0 else 0)
|
|
182
|
+
|
|
183
|
+
self.base_url_edit.setText(str(config.get("base_url", "")))
|
|
184
|
+
self.model_edit.clear()
|
|
185
|
+
self.model_edit.setCurrentText(str(config.get("model", "")))
|
|
186
|
+
self.timeout_edit.setText(str(config.get("timeout_seconds", 60)))
|
|
187
|
+
self.limit_edit.setText(str(config.get("max_context_chars", 200)))
|
|
188
|
+
preset = self._providers.get(config.get("provider"), {})
|
|
189
|
+
hint = preset.get("hint", "")
|
|
190
|
+
self.provider_hint.setText(hint)
|
|
191
|
+
self.provider_hint.setVisible(bool(hint))
|
|
192
|
+
self.enabled_switch.blockSignals(True)
|
|
193
|
+
try:
|
|
194
|
+
self.enabled_switch.setChecked(bool(config.get("enabled")))
|
|
195
|
+
finally:
|
|
196
|
+
self.enabled_switch.blockSignals(False)
|
|
197
|
+
self.key_edit.clear()
|
|
198
|
+
self.key_edit.setPlaceholderText(
|
|
199
|
+
f"已保存:{self._saved_key_mask}(留空表示不修改)" if self._has_key
|
|
200
|
+
else "尚未保存密钥;本机服务可留空"
|
|
201
|
+
)
|
|
202
|
+
self._refresh_enabled()
|
|
203
|
+
|
|
204
|
+
def _refresh_enabled(self, *_args) -> None:
|
|
205
|
+
enabled = self.enabled_switch.isChecked()
|
|
206
|
+
self._set_controls(enabled)
|
|
207
|
+
provider = self._providers.get(self.provider_combo.currentData(), {})
|
|
208
|
+
needs_key = bool(provider.get("needs_key", True))
|
|
209
|
+
self.key_edit.setEnabled(enabled and needs_key)
|
|
210
|
+
self.status_label.setText(
|
|
211
|
+
"AI 已启用;改完请点「保存 AI 配置」。" if enabled
|
|
212
|
+
else "AI 未启用:所有功能与原来完全一致,不会加载 AI 模块、不会联网。"
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
def _set_controls(self, enabled: bool) -> None:
|
|
216
|
+
for widget in (
|
|
217
|
+
self.test_button, self.list_models_button, self.provider_combo,
|
|
218
|
+
self.base_url_edit, self.model_edit, self.privacy_combo,
|
|
219
|
+
self.timeout_edit, self.limit_edit,
|
|
220
|
+
):
|
|
221
|
+
widget.setEnabled(enabled)
|
|
222
|
+
|
|
223
|
+
def _provider_changed(self, _index: int) -> None:
|
|
224
|
+
preset = self._providers.get(self.provider_combo.currentData())
|
|
225
|
+
if not preset:
|
|
226
|
+
return
|
|
227
|
+
self.base_url_edit.setText(preset.get("base_url", ""))
|
|
228
|
+
self.model_edit.clear()
|
|
229
|
+
self.model_edit.setCurrentText(preset.get("model", ""))
|
|
230
|
+
hint = preset.get("hint", "")
|
|
231
|
+
self.provider_hint.setText(hint)
|
|
232
|
+
self.provider_hint.setVisible(bool(hint))
|
|
233
|
+
self.key_edit.setEnabled(self.enabled_switch.isChecked() and bool(preset.get("needs_key", True)))
|
|
234
|
+
|
|
235
|
+
def _collect(self) -> dict:
|
|
236
|
+
return {
|
|
237
|
+
"enabled": self.enabled_switch.isChecked(),
|
|
238
|
+
"provider": self.provider_combo.currentData(),
|
|
239
|
+
"base_url": self.base_url_edit.text().strip(),
|
|
240
|
+
"model": self.model_edit.currentText().strip(),
|
|
241
|
+
"privacy_level": self.privacy_combo.currentData(),
|
|
242
|
+
"timeout_seconds": _int_or(self.timeout_edit.text(), 60),
|
|
243
|
+
"max_context_chars": _int_or(self.limit_edit.text(), 200),
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
# ------------------------------------------------------------------ 动作
|
|
247
|
+
|
|
248
|
+
def _run(self, kind: str, title: str, work) -> None:
|
|
249
|
+
self._busy_kind = kind
|
|
250
|
+
self._pending = {}
|
|
251
|
+
|
|
252
|
+
def wrapped() -> int:
|
|
253
|
+
self._pending[kind] = work()
|
|
254
|
+
return 0
|
|
255
|
+
|
|
256
|
+
if not self.ctx.run_steps([(title, wrapped)], on_success=self._done):
|
|
257
|
+
self.status_label.setText("已有任务在执行,请稍候。")
|
|
258
|
+
self._busy_kind = None
|
|
259
|
+
self._set_controls(self.enabled_switch.isChecked())
|
|
260
|
+
|
|
261
|
+
def _done(self, _data=None) -> None:
|
|
262
|
+
kind, self._busy_kind = self._busy_kind, None
|
|
263
|
+
payload = self._pending.get(kind) or {}
|
|
264
|
+
if kind == "models":
|
|
265
|
+
self._render_models(payload)
|
|
266
|
+
elif kind == "test":
|
|
267
|
+
self._render_test(payload)
|
|
268
|
+
self._set_controls(self.enabled_switch.isChecked())
|
|
269
|
+
|
|
270
|
+
def _save(self) -> None:
|
|
271
|
+
typed = self.key_edit.text().strip()
|
|
272
|
+
try:
|
|
273
|
+
api.ai_save_settings(self._collect(), api_key=typed if typed else None)
|
|
274
|
+
except Exception as exc:
|
|
275
|
+
self.ctx.error("保存 AI 配置失败", f"配置未保存。\n\n{exc}")
|
|
276
|
+
return
|
|
277
|
+
self.reload()
|
|
278
|
+
self.status_label.setText("AI 配置已保存到项目内 .wesync_ai.json。")
|
|
279
|
+
self.ctx.log("AI 配置已保存。", "ok")
|
|
280
|
+
# 保存后立刻让「AI 助手」页同步启用状态,避免它停留在旧状态
|
|
281
|
+
page = self.ctx.page("AiPage")
|
|
282
|
+
if page is not None and hasattr(page, "_reload"):
|
|
283
|
+
try:
|
|
284
|
+
page._reload()
|
|
285
|
+
except Exception:
|
|
286
|
+
pass
|
|
287
|
+
|
|
288
|
+
def _fetch_models(self) -> None:
|
|
289
|
+
values = self._collect()
|
|
290
|
+
if not values.get("base_url"):
|
|
291
|
+
self.ctx.error("缺少接口地址", "请先填写接口地址,再获取模型列表。")
|
|
292
|
+
return
|
|
293
|
+
typed = self.key_edit.text().strip()
|
|
294
|
+
self.list_models_button.setEnabled(False)
|
|
295
|
+
self.list_models_button.setText("查询中…")
|
|
296
|
+
|
|
297
|
+
def work():
|
|
298
|
+
from ...ai.config import load_ai_config, save_api_key
|
|
299
|
+
|
|
300
|
+
config = {**load_ai_config(), **values}
|
|
301
|
+
if typed:
|
|
302
|
+
config["api_key_enc"] = save_api_key(typed)
|
|
303
|
+
return api.ai_list_models(config)
|
|
304
|
+
|
|
305
|
+
self._run("models", "获取模型列表", work)
|
|
306
|
+
|
|
307
|
+
def _render_models(self, payload: dict) -> None:
|
|
308
|
+
self.list_models_button.setText("获取模型列表")
|
|
309
|
+
if not payload.get("ok"):
|
|
310
|
+
self.provider_hint.setText(f"获取失败:{payload.get('message', '未知错误')}")
|
|
311
|
+
self.provider_hint.setVisible(True)
|
|
312
|
+
return
|
|
313
|
+
models = payload.get("models") or []
|
|
314
|
+
current = self.model_edit.currentText().strip()
|
|
315
|
+
self.model_edit.blockSignals(True)
|
|
316
|
+
try:
|
|
317
|
+
self.model_edit.clear()
|
|
318
|
+
self.model_edit.addItems(models)
|
|
319
|
+
if current:
|
|
320
|
+
self.model_edit.setCurrentText(current)
|
|
321
|
+
elif models:
|
|
322
|
+
self.model_edit.setCurrentText(models[0])
|
|
323
|
+
finally:
|
|
324
|
+
self.model_edit.blockSignals(False)
|
|
325
|
+
self.provider_hint.setText(f"已获取 {len(models)} 个模型,可从下拉框选择;也可继续手填。")
|
|
326
|
+
self.provider_hint.setVisible(True)
|
|
327
|
+
|
|
328
|
+
def _test(self) -> None:
|
|
329
|
+
values = self._collect()
|
|
330
|
+
typed = self.key_edit.text().strip()
|
|
331
|
+
self.test_button.setEnabled(False)
|
|
332
|
+
self.status_label.setText("正在连接…")
|
|
333
|
+
|
|
334
|
+
def work():
|
|
335
|
+
from ...ai.config import load_ai_config, save_api_key
|
|
336
|
+
|
|
337
|
+
config = {**load_ai_config(), **values}
|
|
338
|
+
if typed:
|
|
339
|
+
config["api_key_enc"] = save_api_key(typed)
|
|
340
|
+
return api.ai_test_connection(config)
|
|
341
|
+
|
|
342
|
+
self._run("test", "测试 AI 连接", work)
|
|
343
|
+
|
|
344
|
+
def _render_test(self, payload: dict) -> None:
|
|
345
|
+
self.test_button.setEnabled(True)
|
|
346
|
+
if payload.get("ok"):
|
|
347
|
+
self.status_label.setText(
|
|
348
|
+
f"连接正常 · {payload.get('model', '')} · {payload.get('elapsed_ms', 0)} 毫秒"
|
|
349
|
+
)
|
|
350
|
+
return
|
|
351
|
+
message = payload.get("message", "未知错误")
|
|
352
|
+
text = f"连接失败:{message}"
|
|
353
|
+
if "模型" in message and ("不存在" in message or "列表" in message):
|
|
354
|
+
text += "\n提示:点「获取模型列表」选一个可用模型,再试一次。"
|
|
355
|
+
self.status_label.setText(text)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _int_or(text: str, default: int) -> int:
|
|
359
|
+
try:
|
|
360
|
+
return int(str(text).strip())
|
|
361
|
+
except (TypeError, ValueError):
|
|
362
|
+
return default
|