/
VolcanoByte
/
vbNotes
Обзор
Документация
Войти
/
VolcanoByte
/
vbNotes
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
sources/uFormOptions.py
125 строк
5 KB
Eugene Gavrilyuk
fix sync and options
21 апр 2026, 15:03
21 апр 2026, 15:03
6f150f4
Код
Авторство
О чём код?
from PyQt6.QtCore import QByteArray from PyQt6.QtWidgets import QDialog from pygments.styles import get_all_styles from formOptions import Ui_Options from uConsts import (AppConsts, PageConsts, StoreConsts, ThemeConsts, style_example) from uGlobal import store from uLangConsts import translators from uThemes import lightPalette, darkPalette from uUtils import makeMarkdown, getInt, getBool class FormOptions(QDialog, Ui_Options): def __init__(self, parent): super().__init__(parent) self.setupUi(self) self.readSettings() # Язык self.updateLanguageComboBox() # Тема self.updateThemesComboBox() self.cbxTheme.currentIndexChanged.connect(self.updateExampleTheme) # Стиль self.updateStylesComboBox() self.cbxStyle.currentTextChanged.connect(self.updateExampleStyle) self.updateExampleStyle() # Шрифт self.cbxFontName.setCurrentText(store.value( StoreConsts.OptionsFontName, AppConsts.DefaultCodeFontName)) self.cbxFontName.currentFontChanged.connect(self.updateExampleFont) self.sbFontSize.setValue(getInt(store.value(StoreConsts.OptionsFontSize, AppConsts.DefaultCodeFontSize))) self.sbFontSize.valueChanged.connect(self.updateExampleFont) self.updateExampleFont() self.sbTabSize.setValue(getInt(store.value(StoreConsts.OptionsTabSize, AppConsts.DefaultCodeTabSize))) self.buttonBox.accepted.connect(self.on_accept) self.buttonBox.rejected.connect(self.on_reject) self.tabOptions.setCurrentIndex(PageConsts.PageGeneral) def updateLanguageComboBox(self): self.cbxLanguage.clear() for _lang in translators.keys(): self.cbxLanguage.addItem(_lang) _storeLanguage = store.value(StoreConsts.OptionsLanguage, AppConsts.DefaultLanguage) self.cbxLanguage.setCurrentText(_storeLanguage) def updateThemesComboBox(self): self.cbxTheme.clear() self.cbxTheme.addItem(ThemeConsts.Light) self.cbxTheme.addItem(ThemeConsts.Dark) _storeTheme = store.value(StoreConsts.OptionsTheme, AppConsts.DefaultTheme) self.cbxTheme.setCurrentText(_storeTheme) def updateStylesComboBox(self): self.cbxStyle.clear() self.cbxStyle.addItems(get_all_styles()) _storeStyle = store.value(StoreConsts.OptionsStyle, AppConsts.DefaultCodeStyle) self.cbxStyle.setCurrentText(_storeStyle) def updateExampleFont(self): font = self.cbxFontName.currentFont() # font.setFamily(self.cbxFontName.currentText()) font.setPointSize(self.sbFontSize.value()) self.tbExample.setFont(font) def updateExampleTheme(self): if self.cbxTheme.currentText() == ThemeConsts.Light: self.setPalette(lightPalette) elif self.cbxTheme.currentText() == ThemeConsts.Dark: self.setPalette(darkPalette) def updateExampleStyle(self): self.tbExample.setHtml( makeMarkdown(self.cbxStyle.currentText(), style_example)) def on_accept(self): store.setValue(StoreConsts.OptionsUpdateStart, self.cbCheckOnStart.isChecked()) store.setValue(StoreConsts.OptionsUpdateFinish, self.cbCheckOnFinish.isChecked()) store.setValue(StoreConsts.OptionsLanguage, self.cbxLanguage.currentText()) store.setValue(StoreConsts.OptionsTheme, self.cbxTheme.currentText()) store.setValue(StoreConsts.OptionsStyle, self.cbxStyle.currentText()) store.setValue(StoreConsts.OptionsFontName, self.cbxFontName.currentText()) store.setValue(StoreConsts.OptionsFontSize, self.sbFontSize.value()) store.setValue(StoreConsts.OptionsTabSize, self.sbTabSize.value()) self.writeSettings() def on_reject(self): self.writeSettings() def writeSettings(self): store.setValue(StoreConsts.OptionsFormGeometry, self.saveGeometry()) def readSettings(self): self.restoreGeometry(store.value( StoreConsts.OptionsFormGeometry, QByteArray())) # General self.cbCheckOnStart.setChecked(getBool(store.value( StoreConsts.OptionsUpdateStart, True))) self.cbCheckOnFinish.setChecked(getBool(store.value( StoreConsts.OptionsUpdateFinish, True)))