Skip to content

Commit

Permalink
added progressbar to the install tab (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ati1707 authored Nov 16, 2024
1 parent 35a1a0c commit 21cbb3b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 9 additions & 4 deletions installer.pyw → installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def add_to_database(root_path, item):


# Searching the content of extracted archive for target folders
def traverse_directory(folder_path, current_item, is_debug_mode):
def traverse_directory(folder_path, current_item, progressbar, is_debug_mode):
archive_extracted = False
for root, dirs, files in pathlib.Path(folder_path).walk():
for file in files:
Expand All @@ -106,25 +106,30 @@ def traverse_directory(folder_path, current_item, is_debug_mode):
time.sleep(0.5)
pathlib.Path(root).joinpath(file).unlink()
archive_extracted = True
progressbar.set(progressbar.get() + 0.1)
if archive_extracted:
return traverse_directory(folder_path, current_item, is_debug_mode)
progressbar.set(progressbar.get()+0.1)
return traverse_directory(folder_path, current_item, progressbar, is_debug_mode)
if any(target in dirs for target in target_folders):
progressbar.set(0.9)
clean_folder(root)
if add_to_database(root, current_item):
return False
shutil.copytree(root, get_library_path(), dirs_exist_ok=True)
return True
return False

def start_installer_gui(file_path, is_delete_archive=False):
def start_installer_gui(file_path, progressbar, is_delete_archive=False):
with lock:
logger.info(f"Installing {file_path}")
create_temp_folder()
clean_temp_folder()
progressbar.set(0.1)
if not extract_archive(file_path, get_debug_mode()):
clean_temp_folder()
return
if traverse_directory(temp_folder, pathlib.Path(file_path), get_debug_mode()):
progressbar.set(0.4)
if traverse_directory(temp_folder, pathlib.Path(file_path), progressbar, get_debug_mode()):
logger.info(f"Successfully imported: {file_path}")
else:
logger.warning(f"Failed to import {file_path}. Invalid folder structure or asset already exists.")
Expand Down
11 changes: 8 additions & 3 deletions main.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ class AssetWidget(ctk.CTkFrame):

# Install button
if tab_name == "Install":
self.progressbar = ctk.CTkProgressBar(self)
self.progressbar.set(-1)
self.progressbar.grid(row=0, column=1, padx=20, pady=10, sticky="w")

self.label = CTkLabel(self, text=self.file_size)
self.label.grid(row=0, column=1, padx=20, pady=10, sticky="w")
self.label.grid(row=0, column=2, padx=20, pady=10, sticky="w")

# Install button
self.button = ctk.CTkButton(self, text=tab_name, command=lambda: start_install_thread(self.install_asset))
self.button.grid(row=0, column=2, padx=20, pady=10, sticky="e")
self.button.grid(row=0, column=3, padx=20, pady=10, sticky="e")
else:

# Uninstall button
Expand All @@ -71,12 +75,13 @@ class AssetWidget(ctk.CTkFrame):
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=0)
self.columnconfigure(2, weight=0)
self.columnconfigure(3, weight=0)


def install_asset(self):
"""Installs the asset and removes its widget from the grid."""
self.button.configure(state=DISABLED)
start_installer_gui(self.file_path, is_delete_archive=self.winfo_toplevel().tab_view.is_delete_archive.get())
start_installer_gui(self.file_path, self.progressbar, is_delete_archive=self.winfo_toplevel().tab_view.is_delete_archive.get())
install_asset_list.remove(self)
self.grid_remove()

Expand Down

0 comments on commit 21cbb3b

Please sign in to comment.