mirror of
https://github.com/FAUSheppy/homelab_gamevault
synced 2025-12-06 06:51:36 +01:00
feat: implement progress text
This commit is contained in:
@@ -38,17 +38,26 @@ def create_details_page(app, software, backswitch_function):
|
||||
|
||||
img = PIL.ImageTk.PhotoImage(img)
|
||||
|
||||
# navbar & progress bar #
|
||||
# navbar #
|
||||
navbar = customtkinter.CTkFrame(app, fg_color="transparent")
|
||||
navbar.grid(column=0, row=0, padx=10, pady=5, sticky="ew")
|
||||
back_button = customtkinter.CTkButton(navbar, text="Back",
|
||||
command=backswitch_function)
|
||||
|
||||
# back button
|
||||
back_button = customtkinter.CTkButton(navbar, text="Back", command=backswitch_function)
|
||||
back_button.pack(anchor="nw", side="left")
|
||||
|
||||
# progress bar #
|
||||
progress_bar = software.progress_bar_wrapper.new(navbar)
|
||||
progress_bar.pack(anchor="nw", side="left", padx=20, pady=5)
|
||||
|
||||
# progress bar text #
|
||||
progress_text = software.progress_bar_wrapper.new_text(navbar)
|
||||
progress_text.pack(anchor="nw", side="left", padx=20, pady=5)
|
||||
|
||||
elements.append(navbar)
|
||||
elements.append(back_button)
|
||||
elements.append(progress_bar)
|
||||
elements.append(progress_text)
|
||||
|
||||
# thumbnail image #
|
||||
thumbnail_image = customtkinter.CTkButton(app, text="", image=img, width=500, height=700,
|
||||
@@ -118,7 +127,7 @@ def create_details_page(app, software, backswitch_function):
|
||||
remove_text = "Remove Manually"
|
||||
else:
|
||||
install_text = "Install"
|
||||
remove_text = "Remove"
|
||||
remove_text = "Remove (not implemented)" # FIXME: change text once implemented
|
||||
|
||||
install_button = customtkinter.CTkButton(button_frame, text=install_text,
|
||||
command=lambda: software.install())
|
||||
@@ -131,6 +140,9 @@ def create_details_page(app, software, backswitch_function):
|
||||
remove_button.configure(state=tkinter.DISABLED)
|
||||
remove_button.configure(fg_color="gray")
|
||||
|
||||
# FIXME: disable remove button until implemented
|
||||
remove_button.configure(state=tkinter.DISABLED)
|
||||
|
||||
remove_button.pack(padx=10, pady=15, anchor="sw", side="left")
|
||||
|
||||
|
||||
|
||||
@@ -184,13 +184,15 @@ class FTP(DataBackend):
|
||||
# print("Cachedir:", cache_dir, os.path.basename(path), local_file)
|
||||
|
||||
if not os.path.isfile(local_file):
|
||||
|
||||
ftp = self._connect(individual_connection=True)
|
||||
ftp.sendcmd('TYPE I')
|
||||
|
||||
# load the file on remote #
|
||||
if not new_connection:
|
||||
|
||||
total_size = ftp.size(fullpath)
|
||||
print(total_size)
|
||||
print("Total Size:", total_size)
|
||||
self.progress_bar_wrapper.get_pb()["maximum"] = total_size
|
||||
|
||||
print(local_file, "not in cache, retriving..")
|
||||
@@ -209,8 +211,10 @@ class FTP(DataBackend):
|
||||
if new_connection: # return if parralell
|
||||
return
|
||||
self.root.update_idletasks() # Update the GUI
|
||||
self.progress_bar_wrapper.get_pb().set(
|
||||
self.progress_bar_wrapper.get_pb().get() + len(data)/total_size)
|
||||
current_total = self.progress_bar_wrapper.get_pb().get() + len(data)/total_size
|
||||
self.progress_bar_wrapper.get_pb().set(current_total)
|
||||
self.progress_bar_wrapper.set_text(
|
||||
text="Downloading: {:.2f}%".format(current_total*100))
|
||||
cmd_progress_bar.update(len(data))
|
||||
|
||||
# run with callback #
|
||||
|
||||
25
pgwrapper.py
25
pgwrapper.py
@@ -6,16 +6,41 @@ class ProgressBarWrapper:
|
||||
in the DataBackend and Software Objects'''
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.progress_bar = None
|
||||
self.progress_text = None
|
||||
self.tk_parent = None
|
||||
|
||||
def update(self):
|
||||
|
||||
if self.tk_parent:
|
||||
self.tk_parent.update_idletasks()
|
||||
|
||||
def new(self, tk_parent):
|
||||
|
||||
self.tk_parent = tk_parent
|
||||
self.progress_bar = customtkinter.CTkProgressBar(tk_parent, height=20, width=200)
|
||||
self.progress_bar["maximum"] = 10000
|
||||
self.progress_bar.set(0)
|
||||
|
||||
return self.progress_bar
|
||||
|
||||
def new_text(self, tk_parent):
|
||||
|
||||
self.tk_parent = tk_parent
|
||||
self.progress_text = customtkinter.CTkLabel(tk_parent, height=20, width=130, text="")
|
||||
return self.progress_text
|
||||
|
||||
def get_pb(self):
|
||||
|
||||
if self.progress_bar:
|
||||
return self.progress_bar
|
||||
else:
|
||||
raise AssertionError("No progress bar in this wrapper created")
|
||||
|
||||
def set_text(self, text):
|
||||
|
||||
if self.progress_text:
|
||||
self.progress_text.configure(text=text)
|
||||
else:
|
||||
raise AssertionError("No progress text in this wrapper created")
|
||||
|
||||
10
software.py
10
software.py
@@ -78,10 +78,16 @@ class Software:
|
||||
count += 1
|
||||
self.progress_bar_wrapper.get_pb().set(count/len(total_count))
|
||||
self.progress_bar_wrapper.get_pb().update_idletasks()
|
||||
self.progress_bar_wrapper.set_text(
|
||||
text="Extracting: {:.2f}%".format(count/len(total_count)*100))
|
||||
except zipfile.error as e:
|
||||
pass # TODO ???
|
||||
#zip_ref.extractall(software_path)
|
||||
|
||||
self.progress_bar_wrapper.set_text(text="Loading..")
|
||||
self.progress_bar_wrapper.update()
|
||||
|
||||
|
||||
def install(self):
|
||||
'''Install this software from the backend'''
|
||||
|
||||
@@ -92,6 +98,8 @@ class Software:
|
||||
webbrowser.open(self.link_only)
|
||||
return
|
||||
|
||||
self.progress_bar_wrapper.set_text(text="Please wait..")
|
||||
self.progress_bar_wrapper.tk_parent.update_idletasks()
|
||||
path = os.path.join(self.directory, "main_dir")
|
||||
|
||||
try:
|
||||
@@ -146,6 +154,8 @@ class Software:
|
||||
os.makedirs(dest_dir, exist_ok=True)
|
||||
shutil.copy(tmp, dest_dir)
|
||||
|
||||
self.progress_bar_wrapper.set_text(text="")
|
||||
|
||||
def run(self):
|
||||
'''Run the configured exe for this software'''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user