diff --git a/bigtext.py b/bigtext.py index 325d438..36cc01a 100644 --- a/bigtext.py +++ b/bigtext.py @@ -138,9 +138,9 @@ class InnerBigText(QWidget): direction = 1 if event.angleDelta().y() < 0 else -1 if event.modifiers() == Qt.KeyboardModifier.ControlModifier: # self.model.settings.update_font_size(-direction) - old_font_size = self.model.settings.getint('general', 'font_size') - new_font_size = old_font_size - direction - self.model.settings.set('general', 'font_size', str(new_font_size)) + old_font_size = self.model.settings.getint_session('general', 'font_size') + new_font_size = max(4, min(50, old_font_size - direction)) + self.model.settings.set_session('general', 'font_size', str(new_font_size)) RavenUI.update_ui() self.update() else: @@ -235,7 +235,7 @@ class InnerBigText(QWidget): # print("paintEvent") painter = QPainter(self) # painter.setFont(self.model.settings.font()) - painter.setFont(QFont("monospace", self.model.settings.getint('general', "font_size"))) + painter.setFont(QFont("monospace", self.model.settings.getint_session('general', "font_size"))) painter.setPen(QColor(0, 0, 0)) self.update_font_metrics(painter) diff --git a/main.py b/main.py index d59515a..cbe896b 100644 --- a/main.py +++ b/main.py @@ -125,8 +125,8 @@ if __name__ == "__main__": timer.start(100) window = MainWindow() - window.show() RavenUI.window = window + window.show() signal.signal(signal.SIGINT, stop_signal) signal.signal(signal.SIGTERM, stop_signal) diff --git a/settings.py b/settings.py index 95d1c7b..c31292e 100644 --- a/settings.py +++ b/settings.py @@ -1,43 +1,36 @@ from configparser import ConfigParser -from typing import Callable - -from PyQt6.QtGui import QFont - -from ravenui import RavenUI class Settings(): - def __init__(self, config: ConfigParser): + def __init__(self, config: ConfigParser, session: ConfigParser): self.config = config + self.session = session - def set(self, section: str, option: str, value: str): + def set_config(self, section: str, option: str, value: str): return self.config.set(section, option, value) - def get(self, section: str, option: str): + def get_config(self, section: str, option: str): return self.config.get(section, option) - def getint(self, section: str, option: str): + def getint_config(self, section: str, option: str): return self.config.getint(section, option) - def getboolean(self, section: str, option: str): + def getboolean_config(self, section: str, option: str): return self.config.getboolean(section, option) + def set_session(self, section: str, option: str, value: str): + return self.session.set(section, option, value) + + def get_session(self, section: str, option: str): + return self.session.get(section, option) + + def getint_session(self, section: str, option: str): + return self.session.getint(section, option) + + def getboolean_session(self, section: str, option: str): + return self.session.getboolean(section, option) + @staticmethod def max_line_length(): return 4096 - - # def font(self) -> QFont: - # return self._font - - # def get_font_size(self) -> int: - # return self._font_size - - # def update_font_size(self, increment: int): - # font_size = min(max(4, self._font_size + increment), 50) - # self.font_size(font_size) - - # def font_size(self, font_size: int): - # self._font_size = font_size - # self._font = QFont("monospace", font_size) - # #RavenUI.update_ui() diff --git a/settingsstore.py b/settingsstore.py index ded1ed1..2c7835d 100644 --- a/settingsstore.py +++ b/settingsstore.py @@ -1,4 +1,5 @@ import os +import sys from typing import Callable from settings import Settings @@ -15,22 +16,42 @@ class SettingsStore(): def _config_file() -> str: return join(Path.home(), ".ravenlog", "settings.ini") + @staticmethod + def _session_file() -> str: + if sys.platform == 'win32' or sys.platform == 'cygwin': + return join(Path.home(), "AppData", "Local", "ravenlog", "session.ini") + else: + return join(Path.home(), ".local", "share", "ravenlog", "session.ini") + @staticmethod def load() -> Settings: + + config = SettingsStore._load_config() + session = SettingsStore._load_session() + return Settings(config, session) + + @staticmethod + def _load_config() -> ConfigParser: config_file = SettingsStore._config_file() config = ConfigParser() + config.read(config_file) + return config + + @staticmethod + def _load_session() -> ConfigParser: + session_file = SettingsStore._session_file() + session = ConfigParser() # apply default settings - config.add_section('general') - config.set('general', 'font_size', '12') - config.read(config_file) - - return Settings(config) + session.add_section('general') + session.set('general', 'font_size', '12') + session.read(session_file) + return session @staticmethod def save(settings: Settings): - config_file = SettingsStore._config_file() - dir = os.path.dirname(config_file) + session_file = SettingsStore._session_file() + dir = os.path.dirname(session_file) os.makedirs(dir, exist_ok=True) - with open(config_file, 'w+') as fp: - settings.config.write(fp) + with open(session_file, 'w+') as fp: + settings.session.write(fp)