Skip to content

Gtk.EntryCompletion

class — extends GObject.Object, Buildable, CellLayout

:::warning Deprecated since 4.10 This API is deprecated. :::

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

It implements the 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 EntryCompletion.set_text_column), but this can be overridden with a custom match function (see 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 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 Entry.set_completion.

GtkEntryCompletion uses a TreeModelFilter model to represent the subset of the entire model that is currently matching. While the GtkEntryCompletion signals EntryCompletion.match-selected and 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 [signalGtk.CellArea::apply-attributes)] will generally take the filter model as argument. As long as you are only calling TreeModel.get, this will make no difference to you. If for some reason, you need the original model, use TreeModelFilter.get_model. Don’t forget to use TreeModelFilter.convert_iter_to_child_iter to obtain a matching iter.

Constructors

new

@classmethod
def new(cls) -> EntryCompletion

:::warning Deprecated since 4.10 This API is deprecated. :::

Creates a new GtkEntryCompletion object.

new_with_area

@classmethod
def new_with_area(cls, area: CellArea) -> EntryCompletion

:::warning Deprecated since 4.10 This API is deprecated. :::

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.

Parameters:

  • area — the GtkCellArea used to layout cells

Methods

complete

def complete(self) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

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.

compute_prefix

def compute_prefix(self, key: str) -> str | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Computes the common prefix that is shared by all rows in completion 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 EntryCompletion.set_text_column for details.

Parameters:

  • key — The text to complete for

get_completion_prefix

def get_completion_prefix(self) -> str | None

:::warning Deprecated since 4.10 This API is deprecated. :::

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

get_entry

def get_entry(self) -> Widget

:::warning Deprecated since 4.10 This API is deprecated. :::

Gets the entry completion has been attached to.

get_inline_completion

def get_inline_completion(self) -> bool

:::warning Deprecated since 4.10 This API is deprecated. :::

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

get_inline_selection

def get_inline_selection(self) -> bool

:::warning Deprecated since 4.10 This API is deprecated. :::

Returns True if inline-selection mode is turned on.

get_minimum_key_length

def get_minimum_key_length(self) -> int

:::warning Deprecated since 4.10 This API is deprecated. :::

Returns the minimum key length as set for completion.

get_model

def get_model(self) -> TreeModel | None

:::warning Deprecated since 4.10 This API is deprecated. :::

Returns the model the GtkEntryCompletion is using as data source.

Returns None if the model is unset.

get_popup_completion

def get_popup_completion(self) -> bool

:::warning Deprecated since 4.10 This API is deprecated. :::

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

get_popup_set_width

def get_popup_set_width(self) -> bool

:::warning Deprecated since 4.10 This API is deprecated. :::

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

get_popup_single_match

def get_popup_single_match(self) -> bool

:::warning Deprecated since 4.10 This API is deprecated. :::

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

get_text_column

def get_text_column(self) -> int

:::warning Deprecated since 4.10 This API is deprecated. :::

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

insert_prefix

def insert_prefix(self) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Requests a prefix insertion.

set_inline_completion

def set_inline_completion(self, inline_completion: bool) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

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

Parameters:

  • inline_completionTrue to do inline completion

set_inline_selection

def set_inline_selection(self, inline_selection: bool) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

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

Parameters:

  • inline_selectionTrue to do inline selection

set_match_func

def set_match_func(self, func: EntryCompletionMatchFunc) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets the match function for completion to be func.

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

Parameters:

  • func — the GtkEntryCompletionMatchFunc to use

set_minimum_key_length

def set_minimum_key_length(self, length: int) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Requires the length of the search key for completion 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).

Parameters:

  • length — the minimum length of the key in order to start completing

set_model

def set_model(self, model: TreeModel | None = ...) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

Sets the model for a GtkEntryCompletion.

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

Parameters:

  • model — the GtkTreeModel

set_popup_completion

def set_popup_completion(self, popup_completion: bool) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

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

Parameters:

  • popup_completionTrue to do popup completion

set_popup_set_width

def set_popup_set_width(self, popup_set_width: bool) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

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

Parameters:

  • popup_set_widthTrue to make the width of the popup the same as the entry

set_popup_single_match

def set_popup_single_match(self, popup_single_match: bool) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

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 EntryCompletion.inline-completion.

Parameters:

  • popup_single_matchTrue if the popup should appear even for a single match

set_text_column

def set_text_column(self, column: int) -> None

:::warning Deprecated since 4.10 This API is deprecated. :::

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

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

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 EntryCompletion.text-column property directly.

Parameters:

  • column — the column in the model of completion to get strings from

Properties

cell_area

cell_area: CellArea  # read/write

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

If no area is specified when creating the entry completion with EntryCompletion.new_with_area, a horizontally oriented CellAreaBox will be used.

inline_completion

inline_completion: bool  # read/write

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.

inline_selection

inline_selection: bool  # read/write

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

minimum_key_length

minimum_key_length: int  # read/write

The minimum key length as set for completion.

model

model: TreeModel  # read/write

The model used as data source.

popup_completion

popup_completion: bool  # read/write

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

popup_set_width

popup_set_width: bool  # read/write

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

popup_single_match

popup_single_match: bool  # read/write

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 EntryCompletion.inline-completion.

text_column

text_column: int  # read/write

The column of the model containing the strings.

Note that the strings must be UTF-8.

Signals

cursor-on-match

def on_cursor_on_match(self, model: TreeModel, iter: TreeIter) -> 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 EntryCompletion.set_model.

insert-prefix

def on_insert_prefix(self, prefix: str) -> 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 '/'.

match-selected

def on_match_selected(self, model: TreeModel, iter: TreeIter) -> 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 EntryCompletion.set_model.

no-matches

def on_no_matches(self) -> None: ...

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

In other words when GtkEntryCompletion is out of suggestions.