more font_size to a new config file for session data
We need config and session data. config is what the user changes. Only read by the app. session is what the app remembers. Read and written by the app.
This commit is contained in:
@@ -138,9 +138,9 @@ class InnerBigText(QWidget):
|
|||||||
direction = 1 if event.angleDelta().y() < 0 else -1
|
direction = 1 if event.angleDelta().y() < 0 else -1
|
||||||
if event.modifiers() == Qt.KeyboardModifier.ControlModifier:
|
if event.modifiers() == Qt.KeyboardModifier.ControlModifier:
|
||||||
# self.model.settings.update_font_size(-direction)
|
# self.model.settings.update_font_size(-direction)
|
||||||
old_font_size = self.model.settings.getint('general', 'font_size')
|
old_font_size = self.model.settings.getint_session('general', 'font_size')
|
||||||
new_font_size = old_font_size - direction
|
new_font_size = max(4, min(50, old_font_size - direction))
|
||||||
self.model.settings.set('general', 'font_size', str(new_font_size))
|
self.model.settings.set_session('general', 'font_size', str(new_font_size))
|
||||||
RavenUI.update_ui()
|
RavenUI.update_ui()
|
||||||
self.update()
|
self.update()
|
||||||
else:
|
else:
|
||||||
@@ -235,7 +235,7 @@ class InnerBigText(QWidget):
|
|||||||
# print("paintEvent")
|
# print("paintEvent")
|
||||||
painter = QPainter(self)
|
painter = QPainter(self)
|
||||||
# painter.setFont(self.model.settings.font())
|
# 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))
|
painter.setPen(QColor(0, 0, 0))
|
||||||
self.update_font_metrics(painter)
|
self.update_font_metrics(painter)
|
||||||
|
|
||||||
|
|||||||
2
main.py
2
main.py
@@ -125,8 +125,8 @@ if __name__ == "__main__":
|
|||||||
timer.start(100)
|
timer.start(100)
|
||||||
|
|
||||||
window = MainWindow()
|
window = MainWindow()
|
||||||
window.show()
|
|
||||||
RavenUI.window = window
|
RavenUI.window = window
|
||||||
|
window.show()
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, stop_signal)
|
signal.signal(signal.SIGINT, stop_signal)
|
||||||
signal.signal(signal.SIGTERM, stop_signal)
|
signal.signal(signal.SIGTERM, stop_signal)
|
||||||
|
|||||||
43
settings.py
43
settings.py
@@ -1,43 +1,36 @@
|
|||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from typing import Callable
|
|
||||||
|
|
||||||
from PyQt6.QtGui import QFont
|
|
||||||
|
|
||||||
from ravenui import RavenUI
|
|
||||||
|
|
||||||
|
|
||||||
class Settings():
|
class Settings():
|
||||||
|
|
||||||
def __init__(self, config: ConfigParser):
|
def __init__(self, config: ConfigParser, session: ConfigParser):
|
||||||
self.config = config
|
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)
|
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)
|
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)
|
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)
|
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
|
@staticmethod
|
||||||
def max_line_length():
|
def max_line_length():
|
||||||
return 4096
|
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()
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
@@ -15,22 +16,42 @@ class SettingsStore():
|
|||||||
def _config_file() -> str:
|
def _config_file() -> str:
|
||||||
return join(Path.home(), ".ravenlog", "settings.ini")
|
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
|
@staticmethod
|
||||||
def load() -> Settings:
|
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_file = SettingsStore._config_file()
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
|
config.read(config_file)
|
||||||
|
return config
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _load_session() -> ConfigParser:
|
||||||
|
session_file = SettingsStore._session_file()
|
||||||
|
session = ConfigParser()
|
||||||
|
|
||||||
# apply default settings
|
# apply default settings
|
||||||
config.add_section('general')
|
session.add_section('general')
|
||||||
config.set('general', 'font_size', '12')
|
session.set('general', 'font_size', '12')
|
||||||
config.read(config_file)
|
session.read(session_file)
|
||||||
|
return session
|
||||||
return Settings(config)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def save(settings: Settings):
|
def save(settings: Settings):
|
||||||
config_file = SettingsStore._config_file()
|
session_file = SettingsStore._session_file()
|
||||||
dir = os.path.dirname(config_file)
|
dir = os.path.dirname(session_file)
|
||||||
os.makedirs(dir, exist_ok=True)
|
os.makedirs(dir, exist_ok=True)
|
||||||
with open(config_file, 'w+') as fp:
|
with open(session_file, 'w+') as fp:
|
||||||
settings.config.write(fp)
|
settings.session.write(fp)
|
||||||
|
|||||||
Reference in New Issue
Block a user