/
Paff
/
declarant
Обзор
Документация
Войти
/
Paff
/
declarant
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
gui/settings_tab.py
103 строки
3 KB
1pash1985-gif
feat: AI Ensemble - DeepSeek + Kimi parallel parsing with debates
27 июл 2026, 11:14
27 июл 2026, 11:14
5ea7945
Код
Авторство
О чём код?
# -*- coding: utf-8 -*- """Вкладка 'Настройки' — API ключи и пути.""" from __future__ import annotations import json import os from pathlib import Path from PyQt6.QtCore import Qt from PyQt6.QtWidgets import ( QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QLineEdit, QGroupBox, QFormLayout, QFileDialog, QMessageBox, ) _SETTINGS_PATH = Path(__file__).resolve().parent.parent / 'settings.json' def get_ai_settings() -> dict: """Load AI settings (used by verify_tab).""" if _SETTINGS_PATH.exists(): try: with open(_SETTINGS_PATH, 'r', encoding='utf-8') as f: return json.load(f) except (json.JSONDecodeError, OSError): pass return {'api_key': '', 'corrections_path': ''} def save_ai_settings(settings: dict): """Persist AI settings to disk.""" with open(_SETTINGS_PATH, 'w', encoding='utf-8') as f: json.dump(settings, f, ensure_ascii=False, indent=2) class SettingsTab(QWidget): def __init__(self, parent=None): super().__init__(parent) self._setup_ui() self._load() def _setup_ui(self): layout = QVBoxLayout(self) # --- AI Provider --- grp_ai = QGroupBox('AI-агент') form = QFormLayout(grp_ai) self.txt_api_key = QLineEdit() self.txt_api_key.setEchoMode(QLineEdit.EchoMode.Password) self.txt_api_key.setPlaceholderText('Вставьте API-ключ Groq...') form.addRow('API ключ:', self.txt_api_key) self.lbl_hint = QLabel( 'Groq: https://console.groq.com/keys' ) self.lbl_hint.setStyleSheet('color: #666; font-size: 11px;') form.addRow('', self.lbl_hint) layout.addWidget(grp_ai) # --- Corrections path --- grp_corr = QGroupBox('Система обучения') h_corr = QHBoxLayout(grp_corr) self.txt_corr_path = QLineEdit() self.txt_corr_path.setPlaceholderText('(по умолчанию: corrections.json рядом с программой)') self.btn_corr_browse = QPushButton('Обзор...') self.btn_corr_browse.setFixedWidth(80) self.btn_corr_browse.clicked.connect(self._browse_corrections) h_corr.addWidget(QLabel('Путь к corrections.json:')) h_corr.addWidget(self.txt_corr_path, 1) h_corr.addWidget(self.btn_corr_browse) layout.addWidget(grp_corr) # --- Save button --- h_btn = QHBoxLayout() h_btn.addStretch() self.btn_save = QPushButton('💾 Сохранить настройки') self.btn_save.setFixedHeight(36) self.btn_save.clicked.connect(self._save) h_btn.addWidget(self.btn_save) layout.addLayout(h_btn) layout.addStretch() def _browse_corrections(self): path, _ = QFileDialog.getOpenFileName( self, 'Выберите corrections.json', '', 'JSON (*.json)') if path: self.txt_corr_path.setText(path) def _load(self): settings = get_ai_settings() self.txt_api_key.setText(settings.get('api_key', '')) self.txt_corr_path.setText(settings.get('corrections_path', '')) def _save(self): settings = { 'api_key': self.txt_api_key.text().strip(), 'corrections_path': self.txt_corr_path.text().strip(), } save_ai_settings(settings) QMessageBox.information(self, 'Настройки', 'Настройки сохранены.')