From 2b3ac6a31dcf10384cc2d2dc96fca78b95a1596f Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Tue, 31 Oct 2023 19:31:22 +0100 Subject: [PATCH] Added settings class. --- pg.py | 8 ++++++++ settings.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 settings.py diff --git a/pg.py b/pg.py index 2a12350..8ad8666 100644 --- a/pg.py +++ b/pg.py @@ -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 diff --git a/settings.py b/settings.py new file mode 100644 index 0000000..428395c --- /dev/null +++ b/settings.py @@ -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)