Skip to content

Commit

Permalink
Optimizations for CoverManager
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePromidius committed Jan 9, 2024
1 parent a83f2f9 commit c64e576
Showing 1 changed file with 46 additions and 19 deletions.
65 changes: 46 additions & 19 deletions MangaManager/src/MetadataManager/CoverManager/CoverManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def __init__(self, master, super_: GUIApp = None, **kwargs):
"""
Initializes the toplevel window but hides the window.
"""
self.last_width = None
self.last_height = None
if self.name is None: # Check if the "name" attribute has been set
raise ValueError(
f"Error initializing the {self.__class__.__name__} Extension. The 'name' attribute must be set in the ExtensionApp class.")
Expand All @@ -161,7 +163,7 @@ def __init__(self, master, super_: GUIApp = None, **kwargs):
# so that it will be called whenever the window is resized
self.bind("<Configure>", self.redraw)

def redraw(self, event):
def redraw(self, event,frames=None):
"""
Redraws the widgets in the scrolled widget based on the current size of the window.
Expand All @@ -175,19 +177,34 @@ def redraw(self, event):
"""
width = self.winfo_width()
height = self.winfo_height()
if not event:
return
if not (width != event.width or height != event.height):
if self.last_width is None and self.last_height is None:
self.last_width = width
self.last_height = height
elif self.last_width == width and self.last_height == height:
return
else:
self.last_width = width
self.last_height = height
if event:

if isinstance(event.widget,ComicFrame):
return

width = self.winfo_width() - 300
width = self.winfo_width()- 120
if width == self.prev_width:
return
childrens = self.scrolled_widget.winfo_children()
for child in childrens:
child.grid_forget()
if not self.scrolled_widget.winfo_children():
return
if frames is None:
childrens = self.scrolled_widget.winfo_children()
for child in childrens:
child.grid_forget()
if not self.scrolled_widget.winfo_children():
return
widgets_to_redraw = list(
reversed(copy.copy(self.scrolled_widget.winfo_children()))) # self.scrolled_widget.grid_slaves()
else:
childrens = frames
widgets_to_redraw = frames# self.scrolled_widget.grid_slaves()
width = width - self.side_panel_control.winfo_width()

num_widgets = width // 414
try:
Expand All @@ -196,14 +213,16 @@ def redraw(self, event):
except ZeroDivisionError:
pass
# redraw the widgets
widgets_to_redraw = list(
reversed(copy.copy(self.scrolled_widget.winfo_children()))) # self.scrolled_widget.grid_slaves()

i = 0
j = 0
while widgets_to_redraw:
if j >= num_widgets:
if i%12 == 0:
self.update()
i += 1
j = 0

widgets_to_redraw.pop().grid(row=i, column=j)
j += 1

Expand All @@ -220,19 +239,19 @@ def serve_gui(self):
self.attributes('-zoomed', True)
elif platform.system() == "Windows":
self.state('zoomed')
side_panel_control = Frame(self)
side_panel_control.pack(side="right", expand=False, fill="y")
self.side_panel_control = Frame(self)
self.side_panel_control.pack(side="right", expand=False, fill="y")
ctr_btn = Frame(self)
ctr_btn.pack()
#
#
tree = self.tree = Treeview(side_panel_control, columns=("Filename", "type"), show="headings", height=8)
tree = self.tree = Treeview(self.side_panel_control, columns=("Filename", "type"), show="headings", height=8)
tree.column("#1")
tree.heading("#1", text="Filename")
tree.column("#2", anchor=CENTER, width=80)
tree.heading("#2", text="Type")
tree.pack(expand=True, fill="y", pady=(80, 0), padx=30, side="top")
action_buttons = Frame(side_panel_control)
action_buttons = Frame(self.side_panel_control)
action_buttons.pack(ipadx=20, ipady=20, pady=(0, 80), fill="x", padx=30)

ButtonWidget(master=action_buttons, text="Delete Selected",
Expand Down Expand Up @@ -291,18 +310,26 @@ def serve_gui(self):
self.prev_width = 0
self.last_folder = ""
self.selected_frames: list[tuple[ComicFrame, str]] = []

self.shadow_frame_size = None
frames = []
for i, cinfo in enumerate(self._super.loaded_cinfo_list):

# create a ComicFrame for each LoadedComicInfo object
comic_frame = ComicFrame(self.scrolled_widget, cinfo)


comic_frame.cover_canvas.bind("<Button-1>",
lambda event, frame_=comic_frame: self.select_frame(event, frame_, "front"))
comic_frame.backcover_canvas.bind("<Button-1>",
lambda event, frame_=comic_frame: self.select_frame(event, frame_,
"back"))
comic_frame.grid()
self.redraw(None)
# comic_frame.grid()
if self.shadow_frame_size is None:
comic_frame.grid()
self.shadow_frame_size = comic_frame.winfo_width()
comic_frame.grid_forget()
frames.append(comic_frame)
self.redraw(None,frames=frames)
def process(self):

frames_with_actions = [frame for frame in self.scrolled_widget.winfo_children() if frame.loaded_cinfo.cover_action or frame.loaded_cinfo.backcover_action]
Expand Down

0 comments on commit c64e576

Please sign in to comment.