SimpleAction#

class SimpleAction(**properties: Any)#

Superclasses: Object

Implemented Interfaces: Action

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

Constructors#

class SimpleAction
classmethod new(name: str, parameter_type: VariantType | None = None) SimpleAction#

Creates a new action.

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

Added in version 2.28.

Parameters:
  • name – the name of the action

  • parameter_type – the type of parameter that will be passed to handlers for the SimpleAction::activate signal, or None for no parameter

classmethod new_stateful(name: str, parameter_type: VariantType | None, state: Variant) SimpleAction#

Creates a new stateful action.

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

If the state Variant is floating, it is consumed.

Added in version 2.28.

Parameters:
  • name – the name of the action

  • parameter_type – the type of the parameter that will be passed to handlers for the SimpleAction::activate signal, or None for no parameter

  • state – the initial state of the action

Methods#

class SimpleAction
set_enabled(enabled: bool) None#

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.

Added in version 2.28.

Parameters:

enabled – whether the action is enabled

set_state(value: Variant) None#

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 change_state() to request the change.

If the value GVariant is floating, it is consumed.

Added in version 2.30.

Parameters:

value – the new Variant for the state

set_state_hint(state_hint: Variant | None = None) None#

Sets the state hint for the action.

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

Added in version 2.44.

Parameters:

state_hint – a Variant representing the state hint

Properties#

class SimpleAction
props.enabled: bool#

The type of the None singleton.

Added in version 2.28.

props.name: str#

The type of the None singleton.

Added in version 2.28.

props.parameter_type: VariantType#

The type of the None singleton.

Added in version 2.28.

props.state: Variant#

The type of the None singleton.

Added in version 2.28.

props.state_type: VariantType#

The type of the None singleton.

Added in version 2.28.

Signals#

class SimpleAction.signals
activate(parameter: Variant | None = None) None#

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 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 SimpleAction::change-state. This should allow almost all users of SimpleAction to connect only one handler or the other.

Added in version 2.28.

Parameters:

parameter – the parameter to the activation, or None if it has no parameter

change_state(value: Variant | None = None) None#

The type of the None singleton.

Added in version 2.30.

Parameters:

value – the requested value for the state