GLib.Completion

Fields

Name

Type

Access

Description

cache

[object]

r/w

the list of items which begin with prefix.

func

GLib.CompletionFunc

r/w

function which is called to get the string associated with a target item. It is None if the target items are strings.

items

[object]

r/w

list of target items (strings or data structures).

prefix

str

r/w

the last prefix passed to g_completion_complete() or GLib.Completion.complete_utf8().

strncmp_func

GLib.CompletionStrncmpFunc

r/w

The function to use when comparing strings. Use g_completion_set_compare() to modify this function.

Methods

clear_items ()

complete_utf8 (prefix, new_prefix)

free ()

Details

class GLib.Completion

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 [func`GLib`.Completion.new]. Target items are added and removed with [method`GLib`.Completion.add_items], [method`GLib`.Completion.remove_items] and [method`GLib`.Completion.clear_items]. A completion attempt is requested with [method`GLib`.Completion.complete] or [method`GLib`.Completion.complete_utf8]. When no longer needed, the GCompletion is freed with [method`GLib`.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 [type`GLib`.CompletionFunc] in [func`GLib`.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 [type`GLib`.CompletionStrncmpFunc] in [method`GLib`.Completion.set_compare].

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

Deprecated since version 2.26: Rarely used API

clear_items()[source]

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

Deprecated since version 2.26: Rarely used API

complete_utf8(prefix, new_prefix)[source]
Parameters:
  • prefix (str) – the prefix string, typically used by the user, which is compared with each of the items

  • new_prefix (str) – 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.

Returns:

the list of items whose strings begin with prefix. This should not be changed.

Return type:

[str]

Attempts to complete the string prefix using the GLib.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.

New in version 2.4.

Deprecated since version 2.26: Rarely used API

free()[source]

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

Deprecated since version 2.26: Rarely used API