Skip to content

GLib.OptionGroup

record (struct)

A GOptionGroup struct defines the options in a single group. The struct has only private fields and should not be directly accessed.

All options in a group share the same translation function. Libraries which need to parse commandline options are expected to provide a function for getting a GOptionGroup holding their options, which the application can then add to its OptionContext.

Constructors

new

@classmethod
def new(cls, name: str, description: str, help_description: str, user_data: int | None = ..., destroy: DestroyNotify | None = ...) -> OptionGroup

Creates a new OptionGroup.

description is typically used to provide a title for the group. If so, it is recommended that it’s written in title case, and has a trailing colon so that it matches the style of built-in GLib group titles such as ‘Application Options:’.

Parameters:

  • name — the name for the option group, this is used to provide help for the options in this group with --help-``name
  • description — a description for this group to be shown in --help. This string is translated using the translation domain or translation function of the group
  • help_description — a description for the --help-``name option. This string is translated using the translation domain or translation function of the group
  • user_data — user data that will be passed to the pre- and post-parse hooks, the error hook and to callbacks of OptionArg.CALLBACK options, or None
  • destroy — a function that will be called to free user_data, or None

Methods

add_entries

def add_entries(self, entries: list[OptionEntry]) -> None

Adds the options specified in entries to group.

Parameters:

  • entries — a None-terminated array of GOptionEntrys

free

def free(self) -> None

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

Frees a OptionGroup. Note that you must not free groups which have been added to a OptionContext.

ref

def ref(self) -> OptionGroup

Increments the reference count of group by one.

set_translate_func

def set_translate_func(self, func: TranslateFunc | None = ...) -> None

Sets the function which is used to translate user-visible strings, for --help output. Different groups can use different GTranslateFuncs. If func is None, strings are not translated.

If you are using gettext(), you only need to set the translation domain, see OptionGroup.set_translation_domain.

Parameters:

  • func — the GTranslateFunc, or None

set_translation_domain

def set_translation_domain(self, domain: str) -> None

A convenience function to use gettext() for translating user-visible strings.

Parameters:

  • domain — the domain to use

unref

def unref(self) -> None

Decrements the reference count of group by one. If the reference count drops to 0, the group will be freed. and all memory allocated by the group is released.