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:
2021-10-29 09:53:53 +02:00
parent 99d9be795b
commit 4f50fd03a4
4 changed files with 53 additions and 39 deletions

View File

@@ -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)