Gio.SimpleAction

g GObject.GInterface GObject.GInterface Gio.Action Gio.Action GObject.GInterface->Gio.Action GObject.Object GObject.Object Gio.SimpleAction Gio.SimpleAction GObject.Object->Gio.SimpleAction Gio.Action->Gio.SimpleAction

Subclasses:None

Methods

Inherited:GObject.Object (37), Gio.Action (11)
Structs:GObject.ObjectClass (5)
class new (name, parameter_type)
class new_stateful (name, parameter_type, state)
  set_enabled (enabled)
  set_state (value)
  set_state_hint (state_hint)

Virtual Methods

Inherited:GObject.Object (7), Gio.Action (8)

Properties

Inherited:Gio.Action (5)

Signals

Inherited:GObject.Object (1)
Name Short Description
activate Indicates that the action was just activated.
change-state Indicates that the action just received a request to change its state.

Fields

Inherited:GObject.Object (1)

Class Details

class Gio.SimpleAction(**kwargs)
Bases:GObject.Object, Gio.Action
Abstract:No

A Gio.SimpleAction is the obvious simple implementation of the Gio.Action interface. This is the easiest way to create an action for purposes of adding it to a Gio.SimpleActionGroup.

See also #GtkAction.

classmethod new(name, parameter_type)[source]
Parameters:
Returns:

a new Gio.SimpleAction

Return type:

Gio.SimpleAction

Creates a new action.

The created action is stateless. See Gio.SimpleAction.new_stateful() to create an action that has state.

New in version 2.28.

classmethod new_stateful(name, parameter_type, state)[source]
Parameters:
Returns:

a new Gio.SimpleAction

Return type:

Gio.SimpleAction

Creates a new stateful action.

All future state values must have the same GLib.VariantType as the initial state.

If the state GLib.Variant is floating, it is consumed.

New in version 2.28.

set_enabled(enabled)[source]
Parameters:enabled (bool) – whether the action is enabled

Sets the action as enabled or not.

An action must be enabled in order to be activated or in order to have its state changed from outside callers.

This should only be called by the implementor of the action. Users of the action should not attempt to modify its enabled flag.

New in version 2.28.

set_state(value)[source]
Parameters:value (GLib.Variant) – the new GLib.Variant for the state

Sets the state of the action.

This directly updates the ‘state’ property to the given value.

This should only be called by the implementor of the action. Users of the action should not attempt to directly modify the ‘state’ property. Instead, they should call Gio.Action.change_state() to request the change.

If the value GLib.Variant is floating, it is consumed.

New in version 2.30.

set_state_hint(state_hint)[source]
Parameters:state_hint (GLib.Variant or None) – a GLib.Variant representing the state hint

Sets the state hint for the action.

See Gio.Action.get_state_hint() for more information about action state hints.

New in version 2.44.

Signal Details

Gio.SimpleAction.signals.activate(simple_action, parameter)
Signal Name:

activate

Flags:

RUN_LAST, MUST_COLLECT

Parameters:

Indicates that the action was just activated.

parameter will always be of the expected type, i.e. the parameter type specified when the action was created. If an incorrect type is given when activating the action, this signal is not emitted.

Since GLib 2.40, if no handler is connected to this signal then the default behaviour for boolean-stated actions with a None parameter type is to toggle them via the Gio.SimpleAction ::change-state signal. For stateful actions where the state type is equal to the parameter type, the default is to forward them directly to Gio.SimpleAction ::change-state. This should allow almost all users of Gio.SimpleAction to connect only one handler or the other.

New in version 2.28.

Gio.SimpleAction.signals.change_state(simple_action, value)
Signal Name:

change-state

Flags:

RUN_LAST, MUST_COLLECT

Parameters:

Indicates that the action just received a request to change its state.

value will always be of the correct state type, i.e. the type of the initial state passed to Gio.SimpleAction.new_stateful(). If an incorrect type is given when requesting to change the state, this signal is not emitted.

If no handler is connected to this signal then the default behaviour is to call Gio.SimpleAction.set_state() to set the state to the requested value. If you connect a signal handler then no default action is taken. If the state should change then you must call Gio.SimpleAction.set_state() from the handler.

An example of a ‘change-state’ handler:

static void
change_volume_state (GSimpleAction *action,
                     GVariant      *value,
                     gpointer       user_data)
{
  gint requested;

  requested = g_variant_get_int32 (value);

  // Volume only goes from 0 to 10
  if (0 <= requested && requested <= 10)
    g_simple_action_set_state (action, value);
}

The handler need not set the state to the requested value. It could set it to any value at all, or take some other action.

New in version 2.30.