Init repo - gui can launch and first pad list generates from list in pads settings!
This commit is contained in:
0
modules/__init__.py
Normal file
0
modules/__init__.py
Normal file
1
modules/config/__init__.py
Normal file
1
modules/config/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .settings import Config
|
||||
8
modules/config/model.py
Normal file
8
modules/config/model.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from dataclasses import dataclass
|
||||
from dataclasses_json import dataclass_json
|
||||
|
||||
|
||||
@dataclass_json
|
||||
@dataclass(frozen=True)
|
||||
class ConfigModel:
|
||||
theme: str
|
||||
42
modules/config/settings.py
Normal file
42
modules/config/settings.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from modules.config.model import ConfigModel
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
class Config:
|
||||
@staticmethod
|
||||
def default():
|
||||
return {
|
||||
"theme": "Dark gray"
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def fix() -> None:
|
||||
try:
|
||||
with open("data/config.cfg", "w") as file:
|
||||
json.dump(Config.default(), file)
|
||||
except FileNotFoundError:
|
||||
if not os.path.exists('data'):
|
||||
os.mkdir('data')
|
||||
Config.fix()
|
||||
|
||||
@staticmethod
|
||||
def get() -> ConfigModel:
|
||||
try:
|
||||
with open("data/config.cfg", "r") as file:
|
||||
return ConfigModel.from_dict(json.load(file))
|
||||
except:
|
||||
Config.fix()
|
||||
return Config.get()
|
||||
|
||||
@staticmethod
|
||||
def update(key: str, value: str | None) -> dict:
|
||||
with open("data/config.cfg", "r") as file:
|
||||
settings = json.load(file)
|
||||
|
||||
settings[key] = value
|
||||
|
||||
with open("data/config.cfg", "w") as file:
|
||||
json.dump(settings, file)
|
||||
|
||||
return settings
|
||||
Reference in New Issue
Block a user