store font size in settings file
This commit is contained in:
36
settingsstore.py
Normal file
36
settingsstore.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import os
|
||||
from typing import Callable
|
||||
|
||||
from settings import Settings
|
||||
from pathlib import Path
|
||||
from os.path import join, isfile
|
||||
from configparser import ConfigParser
|
||||
|
||||
|
||||
class SettingsStore():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _config_file() -> str:
|
||||
return join(Path.home(), ".ravenlog", "settings.ini")
|
||||
|
||||
@staticmethod
|
||||
def load() -> Settings:
|
||||
config_file = SettingsStore._config_file()
|
||||
config = ConfigParser()
|
||||
|
||||
# apply default settings
|
||||
config.add_section('general')
|
||||
config.set('general', 'font_size', '12')
|
||||
config.read(config_file)
|
||||
|
||||
return Settings(config)
|
||||
|
||||
@staticmethod
|
||||
def save(settings: Settings):
|
||||
config_file = SettingsStore._config_file()
|
||||
dir = os.path.dirname(config_file)
|
||||
os.makedirs(dir, exist_ok=True)
|
||||
with open(config_file, 'w+') as fp:
|
||||
settings.config.write(fp)
|
||||
Reference in New Issue
Block a user