:right-sidebar: True EntryCompletion =================================================================== .. currentmodule:: gi.repository.Gtk .. deprecated:: 4.10 Please do not use it in newly written code .. class:: EntryCompletion(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gtk.Buildable`, :class:`~gi.repository.Gtk.CellLayout` ``GtkEntryCompletion`` is an auxiliary object to provide completion functionality for ``GtkEntry``\. It implements the :obj:`~gi.repository.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 :obj:`~gi.repository.Gtk.EntryCompletion.set_text_column`\), but this can be overridden with a custom match function (see :obj:`~gi.repository.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 :obj:`~gi.repository.Gtk.EntryCompletion.signals.match_selected` signal and updating the entry in the signal handler. Note that you should return :const:`True` from the signal handler to suppress the default behaviour. To add completion functionality to an entry, use :obj:`~gi.repository.Gtk.Entry.set_completion`\. ``GtkEntryCompletion`` uses a :obj:`~gi.repository.Gtk.TreeModelFilter` model to represent the subset of the entire model that is currently matching. While the ``GtkEntryCompletion`` signals :obj:`~gi.repository.Gtk.EntryCompletion.signals.match_selected` and :obj:`~gi.repository.Gtk.EntryCompletion.signals.cursor_on_match` take the original model and an iter pointing to that model as arguments, other callbacks and signals (such as ``GtkCellLayoutDataFunc`` or :obj:`~gi.repository.Gtk.CellArea.signals.apply_attributes)` will generally take the filter model as argument. As long as you are only calling :obj:`~gi.repository.Gtk.TreeModel.get`\, this will make no difference to you. If for some reason, you need the original model, use :obj:`~gi.repository.Gtk.TreeModelFilter.get_model`\. Don’t forget to use :obj:`~gi.repository.Gtk.TreeModelFilter.convert_iter_to_child_iter` to obtain a matching iter. Constructors ------------ .. rst-class:: interim-class .. class:: EntryCompletion :no-index: .. classmethod:: new() -> ~gi.repository.Gtk.EntryCompletion Creates a new ``GtkEntryCompletion`` object. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. classmethod:: new_with_area(area: ~gi.repository.Gtk.CellArea) -> ~gi.repository.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:: 4.10 GtkEntryCompletion will be removed in GTK 5. :param area: the ``GtkCellArea`` used to layout cells Methods ------- .. rst-class:: interim-class .. class:: EntryCompletion :no-index: .. method:: complete() -> None 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:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: compute_prefix(key: str) -> str | None Computes the common prefix that is shared by all rows in ``completion`` that start with ``key``\. If no row matches ``key``\, :const:`None` will be returned. Note that a text column must have been set for this function to work, see :obj:`~gi.repository.Gtk.EntryCompletion.set_text_column` for details. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. :param key: The text to complete for .. method:: get_completion_prefix() -> str | None Get the original text entered by the user that triggered the completion or :const:`None` if there’s no completion ongoing. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: get_entry() -> ~gi.repository.Gtk.Widget Gets the entry ``completion`` has been attached to. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: get_inline_completion() -> bool Returns whether the common prefix of the possible completions should be automatically inserted in the entry. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: get_inline_selection() -> bool Returns :const:`True` if inline-selection mode is turned on. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: get_minimum_key_length() -> int Returns the minimum key length as set for ``completion``\. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: get_model() -> ~gi.repository.Gtk.TreeModel | None Returns the model the ``GtkEntryCompletion`` is using as data source. Returns :const:`None` if the model is unset. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: get_popup_completion() -> bool Returns whether the completions should be presented in a popup window. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: get_popup_set_width() -> bool Returns whether the completion popup window will be resized to the width of the entry. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: get_popup_single_match() -> bool Returns whether the completion popup window will appear even if there is only a single match. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: get_text_column() -> int Returns the column in the model of ``completion`` to get strings from. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: insert_prefix() -> None Requests a prefix insertion. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. .. method:: set_inline_completion(inline_completion: bool) -> None Sets whether the common prefix of the possible completions should be automatically inserted in the entry. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. :param inline_completion: :const:`True` to do inline completion .. method:: set_inline_selection(inline_selection: bool) -> None Sets whether it is possible to cycle through the possible completions inside the entry. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. :param inline_selection: :const:`True` to do inline selection .. method:: set_match_func(func: ~typing.Callable[[~gi.repository.Gtk.EntryCompletion, str, ~gi.repository.Gtk.TreeIter, ~typing.Any], bool], func_data: ~typing.Any = None) -> None 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. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. :param func: the ``GtkEntryCompletion``\MatchFunc to use :param func_data: user data for ``func`` .. method:: set_minimum_key_length(length: int) -> None 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). .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. :param length: the minimum length of the key in order to start completing .. method:: set_model(model: ~gi.repository.Gtk.TreeModel | None = None) -> None 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 :const:`None`, then it will unset the model. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. :param model: the ``GtkTreeModel`` .. method:: set_popup_completion(popup_completion: bool) -> None Sets whether the completions should be presented in a popup window. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. :param popup_completion: :const:`True` to do popup completion .. method:: set_popup_set_width(popup_set_width: bool) -> None Sets whether the completion popup window will be resized to be the same width as the entry. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. :param popup_set_width: :const:`True` to make the width of the popup the same as the entry .. method:: set_popup_single_match(popup_single_match: bool) -> None Sets whether the completion popup window will appear even if there is only a single match. You may want to set this to :const:`False` if you are using :obj:`~gi.repository.Gtk.EntryCompletion.props.inline_completion`\. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. :param popup_single_match: :const:`True` if the popup should appear even for a single match .. method:: set_text_column(column: int) -> None 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 :func:`~gi.repository.GObject.GObject.Object.set` to set the :obj:`~gi.repository.Gtk.EntryCompletion.props.text_column` property directly. .. deprecated:: 4.10 GtkEntryCompletion will be removed in GTK 5. :param column: the column in the model of ``completion`` to get strings from Properties ---------- .. rst-class:: interim-class .. class:: EntryCompletion :no-index: .. attribute:: props.cell_area :type: ~gi.repository.Gtk.CellArea The type of the None singleton. .. attribute:: props.inline_completion :type: bool The type of the None singleton. .. attribute:: props.inline_selection :type: bool The type of the None singleton. .. attribute:: props.minimum_key_length :type: int The type of the None singleton. .. attribute:: props.model :type: ~gi.repository.Gtk.TreeModel The type of the None singleton. .. attribute:: props.popup_completion :type: bool The type of the None singleton. .. attribute:: props.popup_set_width :type: bool The type of the None singleton. .. attribute:: props.popup_single_match :type: bool The type of the None singleton. .. attribute:: props.text_column :type: int The type of the None singleton. Signals ------- .. rst-class:: interim-class .. class:: EntryCompletion.signals :no-index: .. method:: cursor_on_match(model: ~gi.repository.Gtk.TreeModel, iter: ~gi.repository.Gtk.TreeIter) -> bool The type of the None singleton. :param model: the ``GtkTreeModel`` containing the matches :param iter: a ``GtkTreeIter`` positioned at the selected match .. method:: insert_prefix(prefix: str) -> bool The type of the None singleton. :param prefix: the common prefix of all possible completions .. method:: match_selected(model: ~gi.repository.Gtk.TreeModel, iter: ~gi.repository.Gtk.TreeIter) -> bool The type of the None singleton. :param model: the ``GtkTreeModel`` containing the matches :param iter: a ``GtkTreeIter`` positioned at the selected match .. method:: no_matches() -> None The type of the None singleton.