Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions modules/ui/ConceptWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(
self.text_ui_state = text_ui_state
self.image_preview_file_index = 0
self.preview_augmentations = ctk.BooleanVar(self, True)
self.bucket_fig = None

self.title("Concept")
self.geometry("800x700")
Expand Down Expand Up @@ -514,6 +515,10 @@ def __concept_stats_tab(self, master):
self.text_color = f"#{int(text_color[0]/256):x}{int(text_color[1]/256):x}{int(text_color[2]/256):x}"

plt.set_loglevel('WARNING') #suppress errors about data type in bar chart

# Store previous figure to release once we're no longer using it
prev_bucket_fig = self.bucket_fig

self.bucket_fig, self.bucket_ax = plt.subplots(figsize=(7,3))
self.canvas = FigureCanvasTkAgg(self.bucket_fig, master=frame)
self.canvas.get_tk_widget().grid(row=19, column=0, columnspan=4, rowspan=2)
Expand All @@ -531,6 +536,11 @@ def __concept_stats_tab(self, master):
self.bucket_ax.xaxis.label.set_color(self.text_color)
self.bucket_ax.yaxis.label.set_color(self.text_color)

# Close any previous figure handle (if we had one)
if prev_bucket_fig is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this ever happen?
isn't this function only called once during initialization of the window?

plt.close(prev_bucket_fig)
prev_bucket_fig = None

#refresh stats - must be after all labels are defined or will give error
self.refresh_basic_stats_button = components.button(master=frame, row=0, column=0, text="Refresh Basic", command=lambda: self.__get_concept_stats_threaded(False, 9999),
tooltip="Reload basic statistics for the concept directory")
Expand Down Expand Up @@ -921,5 +931,12 @@ def __auto_update_concept_stats(self):
if self.concept.concept_stats["processing_time"] < 0.1:
self.__get_concept_stats(True, 2) #do advanced scan automatically if basic took <0.1s

def destroy(self):
if self.bucket_fig is not None:
plt.close(self.bucket_fig)
self.bucket_fig = None

super().destroy()

def __ok(self):
self.destroy()