Added saving and filling buttons from file.
TODO: Fix too long names and add functionality that removes buttons that are removed from list
This commit is contained in:
43
modules/padslist/padslist.py
Normal file
43
modules/padslist/padslist.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from modules.padslist.model import PadsModel
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
class Pads:
|
||||
@staticmethod
|
||||
def default():
|
||||
return {
|
||||
"first_pads": dict(),
|
||||
"second_pads": dict()
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def fix() -> None:
|
||||
try:
|
||||
with open("data/config.pads", "w") as file:
|
||||
json.dump(Pads.default(), file)
|
||||
except FileNotFoundError:
|
||||
if not os.path.exists('data'):
|
||||
os.mkdir('data')
|
||||
Pads.fix()
|
||||
|
||||
@staticmethod
|
||||
def get() -> PadsModel:
|
||||
try:
|
||||
with open("data/config.pads", "r") as file:
|
||||
return PadsModel.from_dict(json.load(file))
|
||||
except:
|
||||
Pads.fix()
|
||||
return Pads.get()
|
||||
|
||||
@staticmethod
|
||||
def update(key: str, value: str | None) -> dict:
|
||||
with open("data/config.pads", "r") as file:
|
||||
settings = json.load(file)
|
||||
|
||||
settings[key] = value
|
||||
|
||||
with open("data/config.pads", "w") as file:
|
||||
json.dump(settings, file)
|
||||
|
||||
return settings
|
||||
Reference in New Issue
Block a user