Move to src. Add midi and sound
This commit is contained in:
27
src/settings.py
Normal file
27
src/settings.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import json
|
||||
|
||||
class Settings(dict):
|
||||
SETTINGS_FILE = "settings.json"
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.load() # Load settings from file during initialization
|
||||
|
||||
def save(self):
|
||||
try:
|
||||
j = json.dumps(self, indent=4)
|
||||
with open(self.SETTINGS_FILE, 'w') as file:
|
||||
file.write(j)
|
||||
print("Settings saved successfully.")
|
||||
except Exception as e:
|
||||
print(f"Error saving settings: {e}")
|
||||
|
||||
def load(self):
|
||||
try:
|
||||
with open(self.SETTINGS_FILE, 'r') as file:
|
||||
loaded_settings = json.load(file)
|
||||
self.update(loaded_settings)
|
||||
print("Settings loaded successfully.")
|
||||
except Exception as e:
|
||||
print(f"Error loading settings {e}")
|
||||
self.save()
|
Reference in New Issue
Block a user