Gtk.EntryCompletion - Classes - Gtk 3.0 (original) (raw)

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 (10), Gtk.CellLayout (9)

Structs:

GObject.ObjectClass (5)

class new ()
class new_with_area (area)
complete ()
compute_prefix (key)
delete_action (index_)
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_action_markup (index_, markup)
insert_action_text (index_, text)
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 (10), Gtk.CellLayout (9)

do_action_activated (index_)
do_cursor_on_match (model, iter)
do_insert_prefix (prefix)
do_match_selected (model, iter)
do_no_matches ()

Properties

Name Type Flags Short Description
cell-area Gtk.CellArea r/w/co The Gtk.CellArea used to layout cells
inline-completion bool r/w/en Whether the common prefix should be inserted automatically
inline-selection bool r/w/en Your description here
minimum-key-length int r/w/en Minimum length of the search key in order to look up matches
model Gtk.TreeModel r/w The model to find matches in
popup-completion bool r/w/en Whether the completions should be shown in a popup window
popup-set-width bool r/w/en If True, the popup window will have the same size as the entry
popup-single-match bool r/w/en If True, the popup window will appear for a single match.
text-column int r/w The column of the model containing the strings.

Signals

Inherited:

GObject.Object (1)

Name Short Description
action-activated Gets emitted when an action is activated.
cursor-on-match Gets emitted when a match from the cursor is on a match of the list.
insert-prefix Gets emitted when the inline autocompletion is triggered.
match-selected Gets emitted when a match from the list is selected.
no-matches Gets emitted when the filter model has zero number of rows in completion_complete method.

Fields

Inherited:

GObject.Object (1)

Name Type Access Description
parent_instance GObject.Object r

Class Details

class Gtk.EntryCompletion(**kwargs)

Bases:

GObject.Object, Gtk.Buildable, Gtk.CellLayout

Abstract:

No

Structure:

Gtk.EntryCompletionClass

Gtk.EntryCompletion is an auxiliary object to be used in conjunction withGtk.Entry to provide the completion functionality. It implements theGtk.CellLayout interface, to allow the user to add extra cells to theGtk.TreeView with completion matches.

“Completion functionality” means that when the user modifies the text in the entry, Gtk.EntryCompletion 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 (seeGtk.EntryCompletion.set_text_column()), but this can be overridden with a custom match function (see 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 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 Gtk.Entry.set_completion().

In addition to regular completion matches, which will be inserted into the entry when they are selected, Gtk.EntryCompletion also allows to display “actions” in the popup window. Their appearance is similar to menuitems, to differentiate them clearly from completion strings. When an action is selected, the Gtk.EntryCompletion ::action-activated signal is emitted.

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

classmethod new()[source]

Returns:

A newly created Gtk.EntryCompletion object

Return type:

Gtk.EntryCompletion

Creates a new Gtk.EntryCompletion object.

New in version 2.4.

classmethod new_with_area(area)[source]

Parameters:

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

Returns:

A newly created Gtk.EntryCompletion object

Return type:

Gtk.EntryCompletion

Creates a new Gtk.EntryCompletion object using the specified area to layout cells in the underlyingGtk.TreeViewColumn for the drop-down menu.

New in version 3.0.

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.

New in version 2.4.

compute_prefix(key)[source]

Parameters:

key (str) – The text to complete for

Returns:

The common prefix all rows starting withkey or None if no row matches key.

Return type:

str or None

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

New in version 3.4.

delete_action(index_)[source]

Parameters:

index (int) – the index of the item to delete

Deletes the action at index_ from self’s action list.

Note that index_ is a relative position and the position of an action may have changed since it was inserted.

New in version 2.4.

get_completion_prefix()[source]

Returns:

the prefix for the current completion

Return type:

str

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

New in version 2.12.

get_entry()[source]

Returns:

The entry self has been attached to

Return type:

Gtk.Widget

Gets the entry self has been attached to.

New in version 2.4.

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.

New in version 2.6.

get_inline_selection()[source]

Returns:

True if inline-selection mode is on

Return type:

bool

Returns True if inline-selection mode is turned on.

New in version 2.12.

get_minimum_key_length()[source]

Returns:

The currently used minimum key length

Return type:

int

Returns the minimum key length as set for self.

New in version 2.4.

get_model()[source]

Returns:

A Gtk.TreeModel, or None if none is currently being used

Return type:

Gtk.TreeModel or None

Returns the model the Gtk.EntryCompletion is using as data source. Returns None if the model is unset.

New in version 2.4.

Returns:

True if popup completion is turned on

Return type:

bool

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

New in version 2.6.

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.

New in version 2.8.

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.

New in version 2.8.

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.

New in version 2.6.

insert_action_markup(index_, markup)[source]

Parameters:

Inserts an action in self’s action item list at position index_with markup markup.

New in version 2.4.

insert_action_text(index_, text)[source]

Parameters:

Inserts an action in self’s action item list at position index_with text text. If you want the action item to have markup, useGtk.EntryCompletion.insert_action_markup().

Note that index_ is a relative position in the list of actions and the position of an action can change when deleting a different action.

New in version 2.4.

insert_prefix()[source]

Requests a prefix insertion.

New in version 2.6.

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.

New in version 2.6.

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.

New in version 2.12.

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.

New in version 2.4.

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 leastlength. 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).

New in version 2.4.

set_model(model)[source]

Parameters:

model (Gtk.TreeModel or None) – the Gtk.TreeModel

Sets the model for a Gtk.EntryCompletion. 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.

New in version 2.4.

Parameters:

popup_completion (bool) – True to do popup completion

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

New in version 2.6.

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.

New in version 2.8.

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

New in version 2.8.

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 selfto 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 Gtk.CellRendererText 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 Gtk.EntryCompletion :text-columnproperty directly.

New in version 2.4.

do_action_activated(index_) virtual

Parameters:

index (int) –

do_cursor_on_match(model, iter) virtual

Parameters:

Return type:

bool

do_insert_prefix(prefix) virtual

Parameters:

prefix (str) –

Return type:

bool

do_match_selected(model, iter) virtual

Parameters:

Return type:

bool

do_no_matches() virtual

Signal Details

Gtk.EntryCompletion.signals.action_activated(entry_completion, index)

Signal Name:

action-activated

Flags:

RUN_LAST

Parameters:

Gets emitted when an action is activated.

New in version 2.4.

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

Gets 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 toGtk.EntryCompletion.set_model().

New in version 2.12.

Gtk.EntryCompletion.signals.insert_prefix(entry_completion, prefix)

Signal Name:

insert-prefix

Flags:

RUN_LAST

Parameters:

Returns:

True if the signal has been handled

Return type:

bool

Gets 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 Gtk.FileChooser inserts only the part of the prefix up to the next ‘/’.

New in version 2.6.

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

Gets 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 toGtk.EntryCompletion.set_model().

New in version 2.4.

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

Gets emitted when the filter model has zero number of rows in completion_complete method. (In other words when Gtk.EntryCompletion is out of suggestions)

New in version 3.14.

Property Details

Gtk.EntryCompletion.props.cell_area

Name:

cell-area

Type:

Gtk.CellArea

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The Gtk.CellArea used to layout cell renderers in the treeview column.

If no area is specified when creating the entry completion withGtk.EntryCompletion.new_with_area() a horizontally orientedGtk.CellAreaBox will be used.

New in version 3.0.

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.

New in version 2.6.

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.

New in version 2.12.

Gtk.EntryCompletion.props.minimum_key_length

Name:

minimum-key-length

Type:

int

Default Value:

1

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Minimum length of the search key in order to look up matches

Gtk.EntryCompletion.props.model

Name:

model

Type:

Gtk.TreeModel

Default Value:

None

Flags:

READABLE, WRITABLE

The model to find matches in

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.

New in version 2.6.

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.

New in version 2.8.

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 usinginline completion.

New in version 2.8.

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.

New in version 2.6.