Gtk.EntryCompletion

g GObject.GInterface GObject.GInterface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.CellLayout Gtk.CellLayout GObject.GInterface->Gtk.CellLayout GObject.Object GObject.Object Gtk.EntryCompletion Gtk.EntryCompletion GObject.Object->Gtk.EntryCompletion Gtk.Buildable->Gtk.EntryCompletion Gtk.CellLayout->Gtk.EntryCompletion

Subclasses:

None

Methods

Inherited:

GObject.Object (37), Gtk.Buildable (1), Gtk.CellLayout (9)

Structs:

GObject.ObjectClass (5)

class

new ()

class

new_with_area (area)

complete ()

compute_prefix (key)

get_completion_prefix ()

get_entry ()

get_inline_completion ()

get_inline_selection ()

get_minimum_key_length ()

get_model ()

get_popup_completion ()

get_popup_set_width ()

get_popup_single_match ()

get_text_column ()

insert_prefix ()

set_inline_completion (inline_completion)

set_inline_selection (inline_selection)

set_match_func (func, *func_data)

set_minimum_key_length (length)

set_model (model)

set_popup_completion (popup_completion)

set_popup_set_width (popup_set_width)

set_popup_single_match (popup_single_match)

set_text_column (column)

Virtual Methods

Inherited:

GObject.Object (7), Gtk.Buildable (9), Gtk.CellLayout (9)

Properties

Name

Type

Flags

Short Description

cell-area

Gtk.CellArea

r/w/co

inline-completion

bool

r/w/en

inline-selection

bool

r/w/en

minimum-key-length

int

r/w/en

model

Gtk.TreeModel

r/w

popup-completion

bool

r/w/en

popup-set-width

bool

r/w/en

popup-single-match

bool

r/w/en

text-column

int

r/w

Signals

Inherited:

GObject.Object (1)

Name

Short Description

cursor-on-match

Emitted when a match from the cursor is on a match of the list.

insert-prefix

Emitted when the inline autocompletion is triggered.

match-selected

Emitted when a match from the list is selected.

no-matches

Emitted when the filter model has zero number of rows in completion_complete method.

Fields

Inherited:

GObject.Object (1)

Class Details

class Gtk.EntryCompletion(**kwargs)
Bases:

GObject.Object, Gtk.Buildable, Gtk.CellLayout

Abstract:

No

GtkEntryCompletion is an auxiliary object to provide completion functionality for GtkEntry.

It implements the [iface`Gtk`.CellLayout] interface, to allow the user to add extra cells to the GtkTreeView with completion matches.

“Completion functionality” means that when the user modifies the text in the entry, GtkEntryCompletion checks which rows in the model match the current content of the entry, and displays a list of matches. By default, the matching is done by comparing the entry text case-insensitively against the text column of the model (see [method`Gtk`.EntryCompletion.set_text_column]), but this can be overridden with a custom match function (see [method`Gtk`.EntryCompletion.set_match_func]).

When the user selects a completion, the content of the entry is updated. By default, the content of the entry is replaced by the text column of the model, but this can be overridden by connecting to the [signal`Gtk`.EntryCompletion::match-selected] signal and updating the entry in the signal handler. Note that you should return True from the signal handler to suppress the default behaviour.

To add completion functionality to an entry, use [method`Gtk`.Entry.set_completion].

GtkEntryCompletion uses a [class`Gtk`.TreeModelFilter] model to represent the subset of the entire model that is currently matching. While the GtkEntryCompletion signals [signal`Gtk`.EntryCompletion::match-selected] and [signal`Gtk`.EntryCompletion::cursor-on-match] take the original model and an iter pointing to that model as arguments, other callbacks and signals (such as GtkCellLayoutDataFunc or [signal`Gtk`.CellArea::apply-attributes)] will generally take the filter model as argument. As long as you are only calling [method`Gtk`.TreeModel.get], this will make no difference to you. If for some reason, you need the original model, use [method`Gtk`.TreeModelFilter.get_model]. Don’t forget to use [method`Gtk`.TreeModelFilter.convert_iter_to_child_iter] to obtain a matching iter.

Deprecated since version 4.10.

classmethod new()[source]
Returns:

A newly created GtkEntryCompletion object

Return type:

Gtk.EntryCompletion

Creates a new GtkEntryCompletion object.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

classmethod new_with_area(area)[source]
Parameters:

area (Gtk.CellArea) – the GtkCellArea used to layout cells

Returns:

A newly created GtkEntryCompletion object

Return type:

Gtk.EntryCompletion

Creates a new GtkEntryCompletion object using the specified area.

The GtkCellArea is used to layout cells in the underlying GtkTreeViewColumn for the drop-down menu.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

complete()[source]

Requests a completion operation, or in other words a refiltering of the current list with completions, using the current key.

The completion list view will be updated accordingly.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

compute_prefix(key)[source]
Parameters:

key (str) – The text to complete for

Returns:

The common prefix all rows starting with key

Return type:

str or None

Computes the common prefix that is shared by all rows in self that start with key.

If no row matches key, None will be returned. Note that a text column must have been set for this function to work, see [method`Gtk`.EntryCompletion.set_text_column] for details.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

get_completion_prefix()[source]
Returns:

the prefix for the current completion

Return type:

str or None

Get the original text entered by the user that triggered the completion or None if there’s no completion ongoing.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

get_entry()[source]
Returns:

The entry self has been attached to

Return type:

Gtk.Widget

Gets the entry self has been attached to.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

get_inline_completion()[source]
Returns:

True if inline completion is turned on

Return type:

bool

Returns whether the common prefix of the possible completions should be automatically inserted in the entry.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

get_inline_selection()[source]
Returns:

True if inline-selection mode is on

Return type:

bool

Returns True if inline-selection mode is turned on.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

get_minimum_key_length()[source]
Returns:

The currently used minimum key length

Return type:

int

Returns the minimum key length as set for self.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

get_model()[source]
Returns:

A GtkTreeModel

Return type:

Gtk.TreeModel or None

Returns the model the GtkEntryCompletion is using as data source.

Returns None if the model is unset.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

get_popup_completion()[source]
Returns:

True if popup completion is turned on

Return type:

bool

Returns whether the completions should be presented in a popup window.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

get_popup_set_width()[source]
Returns:

True if the popup window will be resized to the width of the entry

Return type:

bool

Returns whether the completion popup window will be resized to the width of the entry.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

get_popup_single_match()[source]
Returns:

True if the popup window will appear regardless of the number of matches

Return type:

bool

Returns whether the completion popup window will appear even if there is only a single match.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

get_text_column()[source]
Returns:

the column containing the strings

Return type:

int

Returns the column in the model of self to get strings from.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

insert_prefix()[source]

Requests a prefix insertion.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

set_inline_completion(inline_completion)[source]
Parameters:

inline_completion (bool) – True to do inline completion

Sets whether the common prefix of the possible completions should be automatically inserted in the entry.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

set_inline_selection(inline_selection)[source]
Parameters:

inline_selection (bool) – True to do inline selection

Sets whether it is possible to cycle through the possible completions inside the entry.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

set_match_func(func, *func_data)[source]
Parameters:

Sets the match function for self to be func.

The match function is used to determine if a row should or should not be in the completion list.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

set_minimum_key_length(length)[source]
Parameters:

length (int) – the minimum length of the key in order to start completing

Requires the length of the search key for self to be at least length.

This is useful for long lists, where completing using a small key takes a lot of time and will come up with meaningless results anyway (ie, a too large dataset).

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

set_model(model)[source]
Parameters:

model (Gtk.TreeModel or None) – the GtkTreeModel

Sets the model for a GtkEntryCompletion.

If self already has a model set, it will remove it before setting the new model. If model is None, then it will unset the model.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

set_popup_completion(popup_completion)[source]
Parameters:

popup_completion (bool) – True to do popup completion

Sets whether the completions should be presented in a popup window.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

set_popup_set_width(popup_set_width)[source]
Parameters:

popup_set_width (bool) – True to make the width of the popup the same as the entry

Sets whether the completion popup window will be resized to be the same width as the entry.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

set_popup_single_match(popup_single_match)[source]
Parameters:

popup_single_match (bool) – True if the popup should appear even for a single match

Sets whether the completion popup window will appear even if there is only a single match.

You may want to set this to False if you are using [property`Gtk`.EntryCompletion:inline-completion].

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

set_text_column(column)[source]
Parameters:

column (int) – the column in the model of self to get strings from

Convenience function for setting up the most used case of this code: a completion list with just strings.

This function will set up self to have a list displaying all (and just) strings in the completion list, and to get those strings from column in the model of self.

This functions creates and adds a GtkCellRendererText for the selected column. If you need to set the text column, but don’t want the cell renderer, use g_object_set() to set the [property`Gtk`.EntryCompletion:text-column] property directly.

Deprecated since version 4.10: Gtk.EntryCompletion will be removed in GTK 5.

Signal Details

Gtk.EntryCompletion.signals.cursor_on_match(entry_completion, model, iter)
Signal Name:

cursor-on-match

Flags:

RUN_LAST

Parameters:
Returns:

True if the signal has been handled

Return type:

bool

Emitted when a match from the cursor is on a match of the list.

The default behaviour is to replace the contents of the entry with the contents of the text column in the row pointed to by iter.

Note that model is the model that was passed to [method`Gtk`.EntryCompletion.set_model].

Gtk.EntryCompletion.signals.insert_prefix(entry_completion, prefix)
Signal Name:

insert-prefix

Flags:

RUN_LAST

Parameters:
  • entry_completion (Gtk.EntryCompletion) – The object which received the signal

  • prefix (str) – the common prefix of all possible completions

Returns:

True if the signal has been handled

Return type:

bool

Emitted when the inline autocompletion is triggered.

The default behaviour is to make the entry display the whole prefix and select the newly inserted part.

Applications may connect to this signal in order to insert only a smaller part of the prefix into the entry - e.g. the entry used in the GtkFileChooser inserts only the part of the prefix up to the next ‘/’.

Gtk.EntryCompletion.signals.match_selected(entry_completion, model, iter)
Signal Name:

match-selected

Flags:

RUN_LAST

Parameters:
Returns:

True if the signal has been handled

Return type:

bool

Emitted when a match from the list is selected.

The default behaviour is to replace the contents of the entry with the contents of the text column in the row pointed to by iter.

Note that model is the model that was passed to [method`Gtk`.EntryCompletion.set_model].

Gtk.EntryCompletion.signals.no_matches(entry_completion)
Signal Name:

no-matches

Flags:

RUN_LAST

Parameters:

entry_completion (Gtk.EntryCompletion) – The object which received the signal

Emitted when the filter model has zero number of rows in completion_complete method.

In other words when GtkEntryCompletion is out of suggestions.

Property Details

Gtk.EntryCompletion.props.cell_area
Name:

cell-area

Type:

Gtk.CellArea

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The GtkCellArea used to layout cell renderers in the treeview column.

If no area is specified when creating the entry completion with [ctor`Gtk`.EntryCompletion.new_with_area], a horizontally oriented [class`Gtk`.CellAreaBox] will be used.

Gtk.EntryCompletion.props.inline_completion
Name:

inline-completion

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Determines whether the common prefix of the possible completions should be inserted automatically in the entry.

Note that this requires text-column to be set, even if you are using a custom match function.

Gtk.EntryCompletion.props.inline_selection
Name:

inline-selection

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Determines whether the possible completions on the popup will appear in the entry as you navigate through them.

Gtk.EntryCompletion.props.minimum_key_length
Name:

minimum-key-length

Type:

int

Default Value:

1

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Gtk.EntryCompletion.props.model
Name:

model

Type:

Gtk.TreeModel

Default Value:

None

Flags:

READABLE, WRITABLE

Gtk.EntryCompletion.props.popup_completion
Name:

popup-completion

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Determines whether the possible completions should be shown in a popup window.

Gtk.EntryCompletion.props.popup_set_width
Name:

popup-set-width

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Determines whether the completions popup window will be resized to the width of the entry.

Gtk.EntryCompletion.props.popup_single_match
Name:

popup-single-match

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Determines whether the completions popup window will shown for a single possible completion.

You probably want to set this to False if you are using [property`Gtk`.EntryCompletion:inline-completion].

Gtk.EntryCompletion.props.text_column
Name:

text-column

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE

The column of the model containing the strings.

Note that the strings must be UTF-8.