-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettings.py
75 lines (61 loc) · 1.99 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import json
import os
class Settings:
"""Settings class for the GUI."""
def __init__(self, filename="settings.json"):
"""
Initialize the settings class.
:param filename: The name of the settings file.
"""
self.filename = filename
# Default settings
self.settings = {
"serial_port": "COM30",
"programmer_serial_number": "1E660",
"chip_part": "PIC16F627A",
"last_user": "dmh",
"testing_speed": 1.0,
"auto_test": True,
"font_family": "Consolas",
"font_size": 14,
"font_style": "normal",
"font_color": "#000000",
"skip_login": True,
"arduino_instance_id": 1,
"debug": True,
}
# Load settings from file
self.load()
def get(self, key):
"""
Get a setting.
:param key: The key of the setting.
:return: The value of the setting.
"""
return self.settings.get(key)
def set(self, key, value):
"""
Set a setting.
:param key: The key of the setting.
:param value: The value of the setting.
"""
self.settings[key] = value
self.save()
def load(self):
"""Load the settings from a JSON file."""
if not os.path.exists(self.filename):
# Create a settings file from defaults
with open(os.path.join(".", self.filename), "w") as file:
json.dump(self.settings, file, indent=4)
with open(self.filename, "r") as file:
self.settings.update(json.load(file))
def save(self):
"""Save the settings to a JSON file."""
with open(self.filename, "w") as file:
json.dump(self.settings, file, indent=4)
def get_path(self):
"""
Get the path of the settings file.
:return: The path of the settings file.
"""
return os.path.abspath(self.filename)