Added settings class.

This commit is contained in:
The Wobbler 2023-10-31 19:31:22 +01:00
parent e867318c7f
commit 2b3ac6a31d
2 changed files with 54 additions and 0 deletions

8
pg.py
View file

@ -83,6 +83,14 @@ class HoverTitle:
self.delay = delay
def update_2(pressed_mousebuttons: tuple): # call this function before clock.tick() but after everything else in your loop
if not pressed_mousebuttons[0] and not pressed_mousebuttons[1] and not pressed_mousebuttons[2]:
global mouse_button_hold
mouse_button_hold = False
def check_button(button: Button, pressed: tuple, mouse_button: str, mouse_position: tuple):
mx, my = mouse_position # Make variable names shorter

46
settings.py Normal file
View file

@ -0,0 +1,46 @@
#!/usr/bin/python3
class Settings:
def __init__(self, path: str=None):
self.path = path
if path is None:
self.settings = {"abc" : "abftdc"}
else:
self.load_from_file(path)
def load_from_file(self, path):
file = open(path, "r")
self.settings = eval(file.read())
file.close()
def save_settings(self):
file = open(self.path, "w")
new_settings_str = "{\n"
for key in self.settings.keys:
new_settings_str += "\t" + repr(key) + ": " + repr(self.settings[key]) + ",\n"
new_settings_str = new_settings_str[:-2] + "\n}"
file.write(new_settings_str)
file.close()
def __repr__(self):
return repr(self.settings)
def __getitem__(self, key):
return self.settings[key]
def __setitem__(self, key, value):
self.settings[key] = value
def __delitem__(self, key):
self.settings.pop(key)
def __iter__(self):
return self.settings
def __len__(self):
return len(self.settings)