• Handy 1 »
  • Classes »
  • Handy.SearchBar
  • Handy.SearchBar
    • Methods
    • Virtual Methods
    • Properties
    • Style Properties
    • Signals
    • Fields
    • Class Details
      • Handy.SearchBar
        • Handy.SearchBar.new()
        • Handy.SearchBar.connect_entry()
        • Handy.SearchBar.get_search_mode()
        • Handy.SearchBar.get_show_close_button()
        • Handy.SearchBar.handle_event()
        • Handy.SearchBar.set_search_mode()
        • Handy.SearchBar.set_show_close_button()
    • Property Details
      • Handy.SearchBar.props.search_mode_enabled
      • Handy.SearchBar.props.show_close_button
  • Handy 1 »
  • Classes »
  • Handy.SearchBar
  • Handy.SearchBar
    • Methods
    • Virtual Methods
    • Properties
    • Style Properties
    • Signals
    • Fields
    • Class Details
      • Handy.SearchBar
        • Handy.SearchBar.new()
        • Handy.SearchBar.connect_entry()
        • Handy.SearchBar.get_search_mode()
        • Handy.SearchBar.get_show_close_button()
        • Handy.SearchBar.handle_event()
        • Handy.SearchBar.set_search_mode()
        • Handy.SearchBar.set_show_close_button()
    • Property Details
      • Handy.SearchBar.props.search_mode_enabled
      • Handy.SearchBar.props.show_close_button

Handy.SearchBar¶

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Bin Gtk.Bin Handy.SearchBar Handy.SearchBar Gtk.Bin->Handy.SearchBar Gtk.Buildable->Gtk.Widget Gtk.Container Gtk.Container Gtk.Container->Gtk.Bin Gtk.Widget->Gtk.Container

Subclasses:

None

Methods¶

Inherited:

Gtk.Bin (1), Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10)

Structs:

Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)

class

new ()

connect_entry (entry)

get_search_mode ()

get_show_close_button ()

handle_event (event)

set_search_mode (search_mode)

set_show_close_button (visible)

Virtual Methods¶

Inherited:

Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10)

Properties¶

Inherited:

Gtk.Container (3), Gtk.Widget (39)

Name

Type

Flags

Short Description

search-mode-enabled

bool

r/w/en

Whether the search mode is on and the search bar shown

show-close-button

bool

r/w/c/en

Whether to show the close button in the toolbar

Style Properties¶

Inherited:

Gtk.Widget (17)

Signals¶

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Fields¶

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name

Type

Access

Description

parent_instance

Gtk.Bin

r

Class Details¶

class Handy.SearchBar(**kwargs)¶
Bases:

Gtk.Bin

Abstract:

No

Structure:

Handy.SearchBarClass

A toolbar to integrate a search entry with.

HdySearchBar is a container made to have a search entry (possibly with additional connex widgets, such as drop-down menus, or buttons) built-in. The search bar would appear when a search is started through typing on the keyboard, or the application’s search mode is toggled on.

For keyboard presses to start a search, events will need to be forwarded from the top-level window that contains the search bar. See [method`SearchBar`.handle_event] for example code. Common shortcuts such as <kbd>Ctrl</kbd>+<kbd>F</kbd> should be handled as an application action, or through the menu items.

You will also need to tell the search bar about which entry you are using as your search entry using [method`SearchBar`.connect_entry]. The following example shows you how to create a more complex search entry.

HdySearchBar is very similar to [class`Gtk`.SearchBar], the main difference being that it allows the search entry to fill all the available space. This allows you to control your search entry’s width with a [class`Clamp`].

CSS nodes

HdySearchBar has a single CSS node with name searchbar.

New in version 1.0.

classmethod new()¶
Returns:

the newly created HdySearchBar

Return type:

Gtk.Widget

Creates a new `:obj:Handy.SearchBar.

You will need to tell it about which widget is going to be your text entry using [method`SearchBar`.connect_entry].

New in version 1.0.

connect_entry(entry)¶
Parameters:

entry (Gtk.Entry) – an entry

Sets the entry widget passed as the one to be used in this search bar.

The entry should be a descendant of the search bar. This is only required if the entry isn’t the direct child of the search bar (as in our main example).

New in version 1.0.

get_search_mode()¶
Returns:

whether search mode is toggled on

Return type:

bool

Gets whether the search mode is on.

New in version 1.0.

get_show_close_button()¶
Returns:

whether the close button is shown

Return type:

bool

Gets whether the close button is shown.

New in version 1.0.

handle_event(event)¶
Parameters:

event (Gdk.Event) – a [struct`Gdk`.Event] containing key press events

Returns:

GDK_EVENT_STOP if the key press event resulted in text being entered in the search entry (and revealing the search bar if necessary), GDK_EVENT_PROPAGATE otherwise.

Return type:

bool

Handles key press events.

This function should be called when the top-level window which contains the search bar received a key event.

If the key event is handled by the search bar, the bar will be shown, the entry populated with the entered text and GDK_EVENT_STOP will be returned. The caller should ensure that events are not propagated further.

If no entry has been connected to the search bar, using [method`SearchBar`.connect_entry], this function will return immediately with a warning.

Showing the search bar on key presses

```c static bool on_key_press_event (Gtk.Widget *widget, Gdk.Event *event, object user_data) { Handy.SearchBar *bar = HDY_SEARCH_BAR (user_data); return Handy.SearchBar.handle_event (self, event); }

static void create_toplevel (void) { Gtk.Widget *window = Gtk.Window.new (Gtk.WindowType.TOPLEVEL); Gtk.Window *search_bar = Handy.SearchBar.new ();

// Add more widgets to the window…

g_signal_connect (window, “key-press-event”, G_CALLBACK (on_key_press_event), search_bar); } ```

New in version 1.0.

set_search_mode(search_mode)¶
Parameters:

search_mode (bool) – the new state of the search mode

Switches the search mode on or off.

New in version 1.0.

set_show_close_button(visible)¶
Parameters:

visible (bool) – whether the close button will be shown or not

Shows or hides the close button.

Applications that already have a “search” toggle button should not show a close button in their search bar, as it duplicates the role of the toggle button.

New in version 1.0.

Property Details¶

Handy.SearchBar.props.search_mode_enabled¶
Name:

search-mode-enabled

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the search mode is on and the search bar shown.

New in version 1.0.

Handy.SearchBar.props.show_close_button¶
Name:

show-close-button

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, CONSTRUCT, EXPLICIT_NOTIFY

Whether to show the close button in the toolbar.

New in version 1.0.