Gio.SimpleAction¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
- Inherited:
Signals¶
- Inherited:
Name |
Short Description |
---|---|
Indicates that the action was just activated. |
|
Indicates that the action just received a request to change its state. |
Fields¶
- Inherited:
Class Details¶
- class Gio.SimpleAction(**kwargs)¶
- Bases:
- Abstract:
No
A
GSimpleAction
is the obvious simple implementation of the [iface`Gio`.Action] interface. This is the easiest way to create an action for purposes of adding it to a [class`Gio`.SimpleActionGroup].- classmethod new(name, parameter_type)[source]¶
- Parameters:
name (
str
) – the name of the actionparameter_type (
GLib.VariantType
orNone
) – the type of parameter that will be passed to handlers for theGio.SimpleAction
::activate
signal, orNone
for no parameter
- Returns:
a new
Gio.SimpleAction
- Return type:
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:
name (
str
) – the name of the actionparameter_type (
GLib.VariantType
orNone
) – the type of the parameter that will be passed to handlers for theGio.SimpleAction
::activate
signal, orNone
for no parameterstate (
GLib.Variant
) – the initial state of the action
- Returns:
a new
Gio.SimpleAction
- Return type:
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 newGLib.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
orNone
) – aGLib.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:
- Parameters:
simple_action (
Gio.SimpleAction
) – The object which received the signalparameter (
GLib.Variant
orNone
) – the parameter to the activation, orNone
if it has no parameter
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 theGio.SimpleAction
::change-state
signal. For stateful actions where the state type is equal to the parameter type, the default is to forward them directly toGio.SimpleAction
::change-state
. This should allow almost all users ofGio.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:
- Parameters:
simple_action (
Gio.SimpleAction
) – The object which received the signalvalue (
GLib.Variant
orNone
) – the requested value for the state
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 callGio.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.