Gtk.SearchEntry
Gtk.SearchEntry — An entry which shows a search icon
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Entry
╰── Gtk.SearchEntry
Functions:
- new
() -> Gtk.Widget
- handle_event
(self, event:Gdk.Event) -> bool
Signals:
- “next-match”
(entry, user_data)
- “previous-match”
(entry, user_data)
- “search-changed”
(entry, user_data)
- “stop-search”
(entry, user_data)
Description:
Gtk.SearchEntry
is a subclass of GtkEntry that has been tailored for use as a search entry.
It will show an inactive symbolic find
icon when the search entry is empty, and a symbolic clear
icon when there is text.
Clicking on the clear
icon will empty the search entry.
Note that the search/clear icon is shown using a secondary icon, and thus does not work if you are using the secondary icon position for some other purpose.
To make filtering appear more reactive, it is a good idea to not react to every change in the entry text immediately, but only after a short delay. To support this, Gtk.SearchEntry
emits the Gtk.SearchEntry::search
-changed signal which can be used instead of the Gtk.Editable::changed signal.
moving between search results and ending the search.
Often, Gtk.SearchEntry
will be fed events by means of being placed inside a Gtk.SearchBar. If that is not the case, you can use Gtk.SearchEntry::handle_event()
to pass events.
Function Details:
new()
new () -> Gtk.Widget
Creates a Gtk.SearchEntry
, with a find icon when the search field isempty, and a clear icon when it isn't.
Returns: a new Gtk.SearchEntry
Since: 3.6
handle_event()
handle_event (self, event:Gdk.Event) -> bool
This function should be called when the top-level windowwhich contains the search entry received a key event. Ifthe entry is part of a Gtk.SearchBar
, it is preferableto call `Gtk.SearchBar:handle_event
()instead, which willreveal the entry in addition to passing the event to thisfunction.
If the key event is handled by the search entry and startsor continues a search,
GDK_EVENT_STOP` will be returned.The caller should ensure that the entry is shown in thiscase, and not propagate the event further.
Returns:
GDK_EVENT_STOP
if the key press event resultedin a search beginning or continuing,GDK_EVENT_PROPAGATE
otherwise.Since: 3.16
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class SearchEntry(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("SearchEntry")
self.connect("destroy", Gtk.main_quit)
searchentry = Gtk.SearchEntry()
searchentry.connect("activate", self.on_search_activated)
self.add(searchentry)
def on_search_activated(self, searchentry):
print("SearchEntry text: %s" % (searchentry.get_text()))
window = SearchEntry()
window.show_all()
Gtk.main()