-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSettings.py
55 lines (39 loc) · 1.12 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
import configparser
class Settings:
def __init__(self):
self.path = "Config.ini"
self.config = configparser.ConfigParser()
self.DefaultSettings = {
"Level": "Easy",
"TryTime": str("2"),
"NumberTries": str("15"),
"Sounds": str("True"),
"TypingSounds": str("True")
}
def WriteSettings(self, **NewSettings):
try:
self.config.read(self.path, encoding='utf-8')
except:
pass
try:
self.config.add_section("default")
except configparser.DuplicateSectionError:
pass
for Setting in NewSettings:
self.config.set("default", Setting, NewSettings[Setting])
with open(self.path, "w", encoding='utf-8') as config_file:
self.config.write(config_file)
def ReadSettings(self):
try:
self.config.read(self.path, encoding='utf-8')
except:
self.WriteSettings(**self.DefaultSettings)
CurrentSettings = self.DefaultSettings.copy()
for Setting in CurrentSettings:
try:
CurrentSettings[Setting] = self.config.get("default", Setting)
except:
DefaultSetting = {Setting: self.DefaultSettings[Setting]}
self.WriteSettings(**DefaultSetting)
return CurrentSettings
#end of class