move files into a package structure
This commit is contained in:
0
raven/settings/__init__.py
Normal file
0
raven/settings/__init__.py
Normal file
13
raven/settings/cutesettings.py
Normal file
13
raven/settings/cutesettings.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from PySide6.QtCore import QSettings
|
||||
|
||||
|
||||
class CuteSettings:
|
||||
|
||||
def __init__(self):
|
||||
self._settings = QSettings("opentext", "ravenlog")
|
||||
|
||||
def set_value(self, key: str, value: any):
|
||||
self._settings.setValue(key, value)
|
||||
|
||||
def value(self, key: str, default=None):
|
||||
return self._settings.value(key, default)
|
||||
23
raven/settings/settings.py
Normal file
23
raven/settings/settings.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from configparser import ConfigParser
|
||||
|
||||
|
||||
class Settings():
|
||||
|
||||
def __init__(self, session: ConfigParser):
|
||||
self.session = session
|
||||
|
||||
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) -> str:
|
||||
return self.session.get(section, option)
|
||||
|
||||
def getint_session(self, section: str, option: str) -> int:
|
||||
return self.session.getint(section, option)
|
||||
|
||||
def getboolean_session(self, section: str, option: str) -> bool:
|
||||
return self.session.getboolean(section, option)
|
||||
|
||||
@staticmethod
|
||||
def max_line_length():
|
||||
return 4096
|
||||
45
raven/settings/settingsstore.py
Normal file
45
raven/settings/settingsstore.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from os.path import join
|
||||
from configparser import ConfigParser
|
||||
|
||||
from raven.settings.settings import Settings
|
||||
|
||||
|
||||
class SettingsStore():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@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:
|
||||
session = SettingsStore._load_session()
|
||||
return Settings(session)
|
||||
|
||||
@staticmethod
|
||||
def _load_session() -> ConfigParser:
|
||||
session_file = SettingsStore._session_file()
|
||||
session = ConfigParser()
|
||||
|
||||
# apply default settings
|
||||
session.add_section('general')
|
||||
session.set('general', 'font_size', '12')
|
||||
session.set('general', 'highlight_search_term', 'True')
|
||||
session.set('general', 'open_tab_on_save_as_file', 'True')
|
||||
session.read(session_file)
|
||||
return session
|
||||
|
||||
@staticmethod
|
||||
def save(settings: Settings):
|
||||
session_file = SettingsStore._session_file()
|
||||
dir = os.path.dirname(session_file)
|
||||
os.makedirs(dir, exist_ok=True)
|
||||
with open(session_file, 'w+') as fp:
|
||||
settings.session.write(fp)
|
||||
Reference in New Issue
Block a user