From 21ac8c9e541b6b99be22e317b2411e74e50b0efd Mon Sep 17 00:00:00 2001 From: okraska-kropidlowski Date: Tue, 31 Oct 2023 23:43:25 +0100 Subject: [PATCH 1/2] Try to update the list of profiles in window --- profiles.py | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/profiles.py b/profiles.py index 201859c..fbb49d5 100644 --- a/profiles.py +++ b/profiles.py @@ -24,22 +24,33 @@ def add_profile(): #with open('data/profiles_list', "r") as existing_profiles: if new_profile in profiles_file_content: messagebox.showerror(title="Profile already existing", message="Profile with this name already exists. Please use another name.") - return - else: - with open('data/profiles_list', "a") as profiles_file: - if profiles_file_content == '': - profiles_file.write(new_profile) - add_profile_box.delete(0, tkinter.END) - return - elif not profiles_file_content.endswith('\n'): - profiles_file.write('\n') - profiles_file.write(new_profile) - add_profile_box.delete(0, tkinter.END) - return - elif profiles_file_content.endswith('\n'): - profiles_file.write(new_profile) - add_profile_box.delete(0, tkinter.END) - return + return + with open('data/profiles_list', "a") as profiles_file: + if profiles_file_content == '': + profiles_file.write(new_profile) + add_profile_box.delete(0, tkinter.END) + with open ('data/profiles_list') as profiles_file_updated: + profiles_list_updated = [line for line in profiles_file_updated] + profiles_file_content = profiles_file_updated.read() + remove_profile_list.config(values=tuple(profiles_list_updated)) + profiles.update() + elif not profiles_file_content.endswith('\n'): + profiles_file.write('\n') + profiles_file.write(new_profile) + add_profile_box.delete(0, tkinter.END) + with open ('data/profiles_list') as profiles_file_updated: + profiles_list_updated = [line for line in profiles_file_updated] + profiles_file_content = profiles_file_updated.read() + remove_profile_list.config(values=tuple(profiles_list_updated)) + profiles.update() + elif profiles_file_content.endswith('\n'): + profiles_file.write(new_profile) + add_profile_box.delete(0, tkinter.END) + with open ('data/profiles_list') as profiles_file_updated: + profiles_list_updated = [line for line in profiles_file_updated] + profiles_file_content = profiles_file_updated.read() + remove_profile_list.config(values=tuple(profiles_list_updated)) + profiles.update() def profile_name_check(profile_entry): if (profile_entry.isalnum() or profile_entry in ['_', '-']): From a85f35e54f95d9cb539c10b95280b4594493afe4 Mon Sep 17 00:00:00 2001 From: okraska-kropidlowski Date: Wed, 1 Nov 2023 21:58:26 +0100 Subject: [PATCH 2/2] Correct the profile management window --- profiles.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/profiles.py b/profiles.py index fbb49d5..83d671c 100644 --- a/profiles.py +++ b/profiles.py @@ -18,10 +18,10 @@ #Functions definition def add_profile(): global profiles_file_content + global profiles_list_updated new_profile = add_profile_box.get() if len(new_profile) > 16: new_profile = new_profile[:16] - #with open('data/profiles_list', "r") as existing_profiles: if new_profile in profiles_file_content: messagebox.showerror(title="Profile already existing", message="Profile with this name already exists. Please use another name.") return @@ -29,28 +29,19 @@ def add_profile(): if profiles_file_content == '': profiles_file.write(new_profile) add_profile_box.delete(0, tkinter.END) - with open ('data/profiles_list') as profiles_file_updated: - profiles_list_updated = [line for line in profiles_file_updated] - profiles_file_content = profiles_file_updated.read() - remove_profile_list.config(values=tuple(profiles_list_updated)) - profiles.update() elif not profiles_file_content.endswith('\n'): profiles_file.write('\n') profiles_file.write(new_profile) add_profile_box.delete(0, tkinter.END) - with open ('data/profiles_list') as profiles_file_updated: - profiles_list_updated = [line for line in profiles_file_updated] - profiles_file_content = profiles_file_updated.read() - remove_profile_list.config(values=tuple(profiles_list_updated)) - profiles.update() elif profiles_file_content.endswith('\n'): profiles_file.write(new_profile) add_profile_box.delete(0, tkinter.END) - with open ('data/profiles_list') as profiles_file_updated: - profiles_list_updated = [line for line in profiles_file_updated] - profiles_file_content = profiles_file_updated.read() - remove_profile_list.config(values=tuple(profiles_list_updated)) - profiles.update() + profiles_file.close() + with open ('data/profiles_list', "r") as profiles_file_updated: + profiles_list_updated = [line for line in profiles_file_updated] + profiles_file_content = profiles_file_updated.read() + remove_profile_list.config(values=tuple(profiles_list_updated)) + profiles.update_idletasks() def profile_name_check(profile_entry): if (profile_entry.isalnum() or profile_entry in ['_', '-']): @@ -64,15 +55,20 @@ def profile_selection(profile): global to_be_deleted profile = remove_profile_list.get() to_be_deleted = profile - print(to_be_deleted) def remove_profile(): with open('data\profiles_list', "r") as profiles_file: profiles_file_content = profiles_file.read() - with open('data\profiles_list', "w") as profiles_file: removed_profile = profiles_file_content.replace(to_be_deleted, "") profiles_file.write(removed_profile) + profiles_file.close() + with open ('data/profiles_list', "r") as profiles_file_updated: + profiles_list_updated = [line for line in profiles_file_updated] + profiles_file_content = profiles_file_updated.read() + remove_profile_list.config(values=tuple(profiles_list_updated)) + remove_profile_list.set('') + profiles.update_idletasks() #Window and widgets layout profiles_label = tkinter.LabelFrame(profiles, text="MANAGE PROFILES")