Skip to content

Commit

Permalink
Fix bug with stop search function/button not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielx committed Jul 7, 2023
1 parent 50768cf commit 739227e
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions frames/AnydeskFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,23 @@ def find_files(filename: str, search_path: str) -> int:
del dir[dir.index("REPORTS")]
else:
for file in files:
if stop_searching:
break
if fnmatch.fnmatch(file, filename):
message_queue.append(os.path.join(root, file))
number_of_found_files += 1
return number_of_found_files


def stop_threads():
"""A function that sets the flag to stop searching threads"""
global stop_searching
stop_searching = True


class AnydeskFrame(customtkinter.CTkFrame):
"""A frame that contains widgets for fetching AnyDesk logs and displaying them in a textbox."""

def stop_threads(self):
"""A function that sets the flag to stop searching threads"""
global stop_searching
stop_searching = True

def __init__(self, master, **kwargs):
"""Initialize the frame and its widgets."""
super().__init__(master, **kwargs)
Expand Down Expand Up @@ -233,7 +236,7 @@ def search_filesystem_callback(self, search_location: str, worker_threads_queue:

# Update fetch button to allow stopping of search
# When search is in progress
self.fetch_logs_button.configure(text=_("Stop fetching"), command=self.stop_threads,
self.fetch_logs_button.configure(text=_("Stop fetching"), command=stop_threads,
fg_color=("#f59e0b", "#d97706"),
hover_color=("#d97706", "#b45309"), text_color="#fff")

Expand Down Expand Up @@ -291,6 +294,12 @@ def generate_and_present_search_results(self):
write_header = False
except IndexError:
pass
if stop_searching:
# Message queue holds all the files that were found by the search function
# If stop_searching is True, it means that the search function has been stopped
# So we need to clear the message queue and stop the recursive function
self.textbox.insert("insert", '\n---- {}! ----\n\n'.format(_('Search stopped')))
message_queue.clear()
if not search_finished or len(message_queue) > 0:
self.after(200, self.generate_and_present_search_results)
else:
Expand Down

0 comments on commit 739227e

Please sign in to comment.