[gnome-music/wip/mschraal/gtk4-pre-squash-backup: 214/254] searchheaderbar: Use entry search-changed signal
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/gtk4-pre-squash-backup: 214/254] searchheaderbar: Use entry search-changed signal
- Date: Thu, 17 Feb 2022 11:35:45 +0000 (UTC)
commit 0b54189a471badd8aed728cf84626a500abfb154
Author: Jean Felder <jfelder src gnome org>
Date: Fri Feb 11 20:44:59 2022 +0100
searchheaderbar: Use entry search-changed signal
Contrary to the changed signal, this does not react to every change
in the entry text immediately, but only after a short delay.
This allows to remove the timeout logic.
gnomemusic/widgets/searchheaderbar.py | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
---
diff --git a/gnomemusic/widgets/searchheaderbar.py b/gnomemusic/widgets/searchheaderbar.py
index 30319b03e..c32aa56c5 100644
--- a/gnomemusic/widgets/searchheaderbar.py
+++ b/gnomemusic/widgets/searchheaderbar.py
@@ -24,7 +24,7 @@
from enum import IntEnum
-from gi.repository import Adw, GLib, GObject, Gtk
+from gi.repository import Adw, GObject, Gtk
from gnomemusic.search import Search
from gnomemusic.widgets.headerbar import HeaderBar, SelectionBarMenuButton
@@ -59,7 +59,6 @@ class SearchHeaderBar(Adw.Bin):
self._coregrilo = application.props.coregrilo
self._selection_mode = False
- self._timeout = None
self._entry = Gtk.SearchEntry()
self._entry.props.halign = Gtk.Align.CENTER
@@ -100,7 +99,7 @@ class SearchHeaderBar(Adw.Bin):
"notify::search-mode-active", self._on_search_mode_changed)
self.connect("notify::search-state", self._search_state_changed)
- self._entry.connect("changed", self._search_entry_timeout)
+ self._entry.connect("search-changed", self._search_entry_changed)
@GObject.Property(type=bool, default=False)
def selection_mode(self):
@@ -175,16 +174,7 @@ class SearchHeaderBar(Adw.Bin):
else:
self._select_button.props.sensitive = False
- def _search_entry_timeout(self, widget):
- if self._timeout:
- GLib.source_remove(self._timeout)
-
- self._timeout = GLib.timeout_add(
- 500, self._search_entry_changed, widget)
-
- def _search_entry_changed(self, widget):
- self._timeout = None
-
+ def _search_entry_changed(self, widget: Gtk.SearchEntry) -> bool:
search_term = self._entry.get_text()
if search_term != "":
self.props.stack.set_visible_child_name("search")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]