SearchEntry

The SearchEntry widget provides a tailored interface for searching. Essentially, it is a stardard Entry with a find icon when the search field is empty, that then changes to a clear icon when text has been entered. Additional signals are also available which relate to the search functionality.

Constructor

The SearchEntry can be constructed using the following:

searchentry = Gtk.SearchEntry()

Methods

The text can be retrieved from the SearchEntry:

searchentry.get_text()

Text can also be added to the SearchEntry with the method:

searchentry.set_text()

Placeholder text can be added to the SearchEntry to describe the function of the widget:

searchentry.set_placeholder_text(text)

To initiate a default action when the user presses Enter or Return, the method used is:

searchentry.set_activates_default(activates)

Typically, the SearchEntry would only activate a default function when placed in a Dialog.

Signals

The commonly used signals of a SearchEntry are:

"search-changed" (searchentry)
"next-match" (searchentry)
"previous-match" (searchentry)
"stop-search" (searchentry)

The "search-changed" signal emits each time the user enters a character into the search field after a 150 millisecond delay. The "next-match" and "previous-match" signals emit when the user moves between next and previous matches for the search string. Finally, the "stop-search" is emitted when the user stops a search via keyboard input.

Example

Below is an example of a SearchEntry:

#!/usr/bin/env python3

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()

Download: SearchEntry