Skip to content

Commit

Permalink
abort loading popup (doesn't free memory yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePromidius committed Jul 22, 2023
1 parent 2185648 commit e716d96
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
6 changes: 6 additions & 0 deletions MangaManager/src/Common/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def stop(self):

class ProgressBar(abc.ABC):
running = False
PROCESSED_TAG = "$processed"
TOTAL_TAG = "$total"
ERRORS_TAG = "$errors"
ELAPSED_TIME_TAG = "$elapsed_time"
ESTIMATED_TIME_TAG = "$estimated_time"

def __init__(self):

self.timer = RepeatedTimer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def backcover_action(self, loaded_cinfo: LoadedComicInfo = None, auto_trigger=Fa
self.update()

def clear(self):
self.tooltip_filename.text = "No file selected"
try:
self.cover_canvas.itemconfig(self.cover_canvas.image_id, state="hidden")
except _tkinter.TclError as e:
Expand All @@ -282,6 +283,7 @@ def clear(self):
else:
# If the error is caused by something else, re-raise the exception
raise e

self.backcover_canvas.itemconfig(self.backcover_canvas.image_id, state="hidden")
self.hide_actions()

Expand Down
8 changes: 5 additions & 3 deletions MangaManager/src/MetadataManager/GUI/windows/LoadingWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

class LoadingWindow(tkinter.Toplevel):
initialized: bool = False
abort_flag:bool = None
# abort_flag:bool = None

def __init__(self, total,abort_flag):
def __init__(self, total):
super().__init__()
content = tkinter.Frame(self,background="white",borderwidth=3,border=3,highlightcolor="black",highlightthickness=2,highlightbackground="black")
content.pack(ipadx=20, ipady=20,expand=False,fill="both")
Expand All @@ -22,7 +22,7 @@ def __init__(self, total,abort_flag):
# Make the windows always on top
self.attributes("-topmost", True)
self.lift()
self.abort_flag = abort_flag
self.abort_flag = False
# Force focus on this window
self.grab_set()
center(self)
Expand All @@ -39,6 +39,8 @@ def __init__(self, total,abort_flag):
abort_btn = tkinter.Button(content,text="Abort",command=self.set_abort)
abort_btn.pack()
self.initialized = True
def is_abort(self):
return self.abort_flag
def set_abort(self,*_):
if self.initialized:
self.abort_flag = True
Expand Down
27 changes: 17 additions & 10 deletions MangaManager/src/MetadataManager/MetadataManagerGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from src.MetadataManager.GUI.ControlManager import ControlManager
from src.MetadataManager.GUI.MessageBox import MessageBoxWidgetFactory as mb
from src.MetadataManager.GUI.windows.AboutWindow import AboutWindow
from src.MetadataManager.GUI.windows.LoadingWindow import LoadingWindow
from src.Settings import SettingHeading
from src.Settings.Settings import Settings

Expand Down Expand Up @@ -150,13 +151,14 @@ def select_files(self):
self.selected_files_path = [file.name for file in selected_paths_list]

self.log.debug(f"Selected files [{', '.join(self.selected_files_path)}]")
abort_loading = False
self.loading_window = LoadingWindow(len(self.selected_files_path),
abort_flag=abort_loading) if len(self.selected_files_path) > 1 else LoadingWindow
if self.open_cinfo_list(abort_load_flag=abort_loading):
self.loading_window = LoadingWindow(len(self.selected_files_path))

if self.open_cinfo_list(abort_load_check=self.loading_window.is_abort):
self._serialize_cinfolist_to_gui()
else:
self.clean_selected()
self.loading_window.finish_loading()
self.loading_window = None
self.inserting_files = False
self.control_mngr.unlock()
self.widget_mngr.toggle_widgets(enabled=True)
Expand Down Expand Up @@ -187,16 +189,14 @@ def select_folder(self):
# self.selected_files_path = [str(Path(folder_path, file)) for file in os.listdir(folder_path) if file.endswith(".cbz")]

self.log.debug(f"Selected files [{', '.join(self.selected_files_path)}]")
abort_loading = False
self.loading_window = LoadingWindow(
len(self.selected_files_path), abort_flag=abort_loading) if len(
self.selected_files_path) > 1 else LoadingWindow
self.loading_window = LoadingWindow(len(self.selected_files_path))

self.open_cinfo_list()
if self.open_cinfo_list(abort_load_flag=abort_loading):
if self.open_cinfo_list(self.loading_window.is_abort):
self._serialize_cinfolist_to_gui()
else:
self.clean_selected()
self.loading_window.finish_loading()
self.loading_window = None
self.inserting_files = False
self.control_mngr.unlock()
self.widget_mngr.toggle_widgets(enabled=True)
Expand Down Expand Up @@ -518,3 +518,10 @@ def process_fetch_online(self, *_):
return

self._serialize_cinfolist_to_gui([LoadedComicInfo(None, cinfo, load_default_metadata=False)])

def clean_selected(self):

self.widget_mngr.clean_widgets()
self.image_cover_frame.clear()
self.selected_files_path = list()
self.selected_files_treeview.clear()
8 changes: 5 additions & 3 deletions MangaManager/src/MetadataManager/MetadataManagerLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def merge_changed_metadata(self, loaded_cinfo_list: list[LoadedComicInfo]) -> bo
self.new_edited_cinfo = None
return any_has_changes

def open_cinfo_list(self,abort_load_flag = False) -> bool:
def open_cinfo_list(self, abort_load_check:callable) -> bool:
"""
Creates a list of comicinfo with the comicinfo metadata from the selected files.
Expand All @@ -186,8 +186,10 @@ def open_cinfo_list(self,abort_load_flag = False) -> bool:
# Skip warnings if one was already displayed
missing_rar_tool = False
total_files = len(self.selected_files_path)
if total_files == 0:
return False
for i, file_path in enumerate(self.selected_files_path):
if abort_load_flag:
if abort_load_check():
logger.info("Abort loading")
self.loaded_cinfo_list: list[LoadedComicInfo] = list()
return False
Expand Down Expand Up @@ -218,7 +220,7 @@ def open_cinfo_list(self,abort_load_flag = False) -> bool:
continue

self.loaded_cinfo_list.append(loaded_cinfo)
abort_load_flag = self.on_item_loaded(loaded_cinfo=loaded_cinfo, cursor=i, total=total_files)
self.on_item_loaded(loaded_cinfo=loaded_cinfo, cursor=i, total=total_files)

# self.on_item_loaded(loaded_cinfo)
logger.debug("Files selected")
Expand Down

0 comments on commit e716d96

Please sign in to comment.