Skip to content

Commit

Permalink
We don't even need an event anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende committed Jan 6, 2024
1 parent 016bfea commit 5cd1ccf
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions cozy/ui/search_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class SearchView(Adw.Bin):
main_view = inject.attr("MainWindow")

search_thread: threading.Thread
search_thread_stop: threading.Event

def __init__(self, main_window_builder: Gtk.Builder, headerbar: Headerbar) -> None:
super().__init__()
Expand All @@ -47,7 +46,6 @@ def __init__(self, main_window_builder: Gtk.Builder, headerbar: Headerbar) -> No
self.entry.connect("search-changed", self._on_search_changed)

self.search_thread = threading.Thread(target=self.view_model.search)
self.search_thread_stop = threading.Event()

self.view_model.bind_to("close", self.close)
self.main_view.create_action("search", self.open, ["<primary>f"])
Expand All @@ -69,17 +67,14 @@ def on_state_changed(self, widget: Gtk.Widget, param) -> None:
self.close()

def _on_search_changed(self, _) -> None:
self.search_thread_stop.set()

search_query = self.entry.get_text()
if not search_query:
self.stack.set_visible_child(self.start_searching_page)
return

if self.search_thread.is_alive():
self.search_thread.join(timeout=0.2)
self.search_thread.join(timeout=0.1)

self.search_thread_stop.clear()
self.search_thread = threading.Thread(
target=self.view_model.search, args=(search_query, self._display_results)
)
Expand Down Expand Up @@ -120,9 +115,6 @@ def _populate_listbox(
row_type = ArtistResultRow

for result in results:
if self.search_thread_stop.is_set():
return

listbox.append(row_type(result, callback))

box.set_visible(True)

0 comments on commit 5cd1ccf

Please sign in to comment.