OptionGroup#

class OptionGroup(**kwargs)#

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#

class OptionGroup
classmethod new(name: str, description: str, help_description: str, user_data: Any = None, destroy: Callable[[Any], None] | None = 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:’.

Added in version 2.6.

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 CALLBACK options, or None

  • destroy – a function that will be called to free user_data, or None

Methods#

class OptionGroup
add_entries(entries: list[OptionEntry]) None#

Adds the options specified in entries to group.

Added in version 2.6.

Parameters:

entries – a None-terminated array of OptionEntry

free() None#

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

Added in version 2.6.

Deprecated since version 2.44: Use unref() instead.

set_translate_func(func: Callable[[str, Any], str] | None = None, data: Any = None) None#

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

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

Added in version 2.6.

Parameters:
  • func – the TranslateFunc, or None

  • data – user data to pass to func, or None

set_translation_domain(domain: str) None#

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

Added in version 2.6.

Parameters:

domain – the domain to use