Added settings dialog with loglevel

This commit is contained in:
2026-07-26 15:01:49 +02:00
parent 3bd6cfb81d
commit 9312ea544b
7 changed files with 324 additions and 1 deletions

View File

@@ -0,0 +1,50 @@
from __future__ import annotations
from collections.abc import Callable
from typing import Protocol
from PySide6.QtCore import QObject
from PySide6.QtWidgets import QDialog
from bedit_gui.services.application_logging import get_logger, set_log_level
from bedit_gui.services.application_settings import ApplicationSettings
from bedit_gui.views.dialogs.settings_dialog import SettingsDialog
from bedit_gui.views.main_window import MainWindow
logger = get_logger(__name__)
class SettingsDialogLike(Protocol):
@property
def log_level(self) -> int: ...
def exec(self) -> int: ...
SettingsDialogFactory = Callable[[int, MainWindow], SettingsDialogLike]
class SettingsController(QObject):
"""Opens the settings dialog and applies accepted preferences."""
def __init__(
self,
window: MainWindow,
settings: ApplicationSettings,
dialog_factory: SettingsDialogFactory = SettingsDialog,
) -> None:
super().__init__(window)
self.window = window
self.settings = settings
self.dialog_factory = dialog_factory
window.ui.actionSettings.triggered.connect(self.open_settings)
def open_settings(self) -> None:
dialog = self.dialog_factory(self.settings.log_level, self.window)
if dialog.exec() != QDialog.DialogCode.Accepted:
return
self.settings.log_level = dialog.log_level
set_log_level(dialog.log_level)
logger.info("Application settings updated")