Skip to content

GLib.Completion

record (struct)

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

GCompletion provides support for automatic completion of a string using any group of target strings. It is typically used for file name completion as is common in many UNIX shells.

A GCompletion is created using Completion.new. Target items are added and removed with Completion.add_items, Completion.remove_items and Completion.clear_items. A completion attempt is requested with Completion.complete or Completion.complete_utf8. When no longer needed, the GCompletion is freed with Completion.free.

Items in the completion can be simple strings (e.g. filenames), or pointers to arbitrary data structures. If data structures are used you must provide a CompletionFunc in Completion.new, which retrieves the item’s string from the data structure. You can change the way in which strings are compared by setting a different CompletionStrncmpFunc in Completion.set_compare.

GCompletion has been marked as deprecated, since this API is rarely used and not very actively maintained.

Methods

clear_items

def clear_items(self) -> None

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

Removes all items from the Completion. The items are not freed, so if the memory was dynamically allocated, it should be freed after calling this function.

complete_utf8

def complete_utf8(self, prefix: str, new_prefix: str) -> list[str]

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

Attempts to complete the string prefix using the Completion target items. In contrast to g_completion_complete(), this function returns the largest common prefix that is a valid UTF-8 string, omitting a possible common partial character.

You should use this function instead of g_completion_complete() if your items are UTF-8 strings.

Parameters:

  • prefix — the prefix string, typically used by the user, which is compared with each of the items
  • new_prefix — if non-None, returns the longest prefix which is common to all items that matched prefix, or None if no items matched prefix. This string should be freed when no longer needed.

free

def free(self) -> None

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

Frees all memory used by the Completion. The items are not freed, so if the memory was dynamically allocated, it should be freed after calling this function.

Properties

items

items: list[int]  # read/write

func

func: CompletionFunc  # read/write

prefix

prefix: str  # read/write

cache

cache: list[int]  # read/write

strncmp_func

strncmp_func: CompletionStrncmpFunc  # read/write