ActionMap

Added in version 2.32.

class ActionMap(*args, **kwargs)

Implementations: Application, SimpleActionGroup

GActionMap is an interface for action containers.

The GActionMap interface is implemented by ActionGroup implementations that operate by containing a number of named Action instances, such as SimpleActionGroup.

One useful application of this interface is to map the names of actions from various action groups to unique, prefixed names (e.g. by prepending “app.” or “win.”). This is the motivation for the ‘Map’ part of the interface name.

Methods

class ActionMap
add_action(action: Action) None

Adds an action to the action_map.

If the action map already contains an action with the same name as action then the old action is dropped from the action map.

The action map takes its own reference on action.

Added in version 2.32.

Parameters:

action – a Action

add_action_entries(entries, user_data=None)

The add_action_entries() method is a convenience function for creating multiple Gio.SimpleAction instances and adding them to a Gio.ActionMap. Each action is constructed as per one entry.

Parameters:
  • entries (list) –

    List of entry tuples for add_action() method. The entry tuple can vary in size with the following information:

    • The name of the action. Must be specified.

    • The callback to connect to the “activate” signal of the action. Since GLib 2.40, this can be None for stateful actions, in which case the default handler is used. For boolean-stated actions with no parameter, this is a toggle. For other state types (and parameter type equal to the state type) this will be a function that just calls change_state (which you should provide).

    • The type of the parameter that must be passed to the activate function for this action, given as a single GLib.Variant type string (or None for no parameter)

    • The initial state for this action, given in GLib.Variant text format. The state is parsed with no extra type information, so type tags must be added to the string if they are necessary. Stateless actions should give None here.

    • The callback to connect to the “change-state” signal of the action. All stateful actions should provide a handler here; stateless actions should not.

  • user_data – The user data for signal connections, or None

Added in version 2.32.

lookup_action(action_name: str) Action | None

Looks up the action with the name action_name in action_map.

If no such action exists, returns None.

Added in version 2.32.

Parameters:

action_name – the name of an action

remove_action(action_name: str) None

Removes the named action from the action map.

If no action of this name is in the map then nothing happens.

Added in version 2.32.

Parameters:

action_name – the name of the action

remove_action_entries(entries: Sequence[ActionEntry]) None

Remove actions from a ActionMap. This is meant as the reverse of add_action_entries().

static const GActionEntry entries[] = {
    { "quit",         activate_quit              },
    { "print-string", activate_print_string, "s" }
};

void
add_actions (GActionMap *map)
{
  g_action_map_add_action_entries (map, entries, G_N_ELEMENTS (entries), NULL);
}

void
remove_actions (GActionMap *map)
{
  g_action_map_remove_action_entries (map, entries, G_N_ELEMENTS (entries));
}

Added in version 2.78.

Parameters:

entries – a pointer to the first item in an array of ActionEntry structs

Virtual Methods

class ActionMap
do_add_action(action: Action) None

Adds an action to the action_map.

If the action map already contains an action with the same name as action then the old action is dropped from the action map.

The action map takes its own reference on action.

Added in version 2.32.

Parameters:

action – a Action

do_lookup_action(action_name: str) Action | None

Looks up the action with the name action_name in action_map.

If no such action exists, returns None.

Added in version 2.32.

Parameters:

action_name – the name of an action

do_remove_action(action_name: str) None

Removes the named action from the action map.

If no action of this name is in the map then nothing happens.

Added in version 2.32.

Parameters:

action_name – the name of the action