:right-sidebar: True SimpleAction =================================================================== .. currentmodule:: gi.repository.Gio .. class:: SimpleAction(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Gio.Action` A ``GSimpleAction`` is the obvious simple implementation of the :obj:`~gi.repository.Gio.Action` interface. This is the easiest way to create an action for purposes of adding it to a :obj:`~gi.repository.Gio.SimpleActionGroup`. Constructors ------------ .. rst-class:: interim-class .. class:: SimpleAction :no-index: .. classmethod:: new(name: str, parameter_type: ~gi.repository.GLib.VariantType | None = None) -> ~gi.repository.Gio.SimpleAction Creates a new action. The created action is stateless. See :func:`~gi.repository.Gio.SimpleAction.new_stateful` to create an action that has state. .. versionadded:: 2.28 :param name: the name of the action :param parameter_type: the type of parameter that will be passed to handlers for the :obj:`~gi.repository.Gio.SimpleAction`::activate signal, or :const:`None` for no parameter .. classmethod:: new_stateful(name: str, parameter_type: ~gi.repository.GLib.VariantType | None, state: ~gi.repository.GLib.Variant) -> ~gi.repository.Gio.SimpleAction Creates a new stateful action. All future state values must have the same :obj:`~gi.repository.GLib.VariantType` as the initial ``state``. If the ``state`` :obj:`~gi.repository.GLib.Variant` is floating, it is consumed. .. versionadded:: 2.28 :param name: the name of the action :param parameter_type: the type of the parameter that will be passed to handlers for the :obj:`~gi.repository.Gio.SimpleAction`::activate signal, or :const:`None` for no parameter :param state: the initial state of the action Methods ------- .. rst-class:: interim-class .. class:: SimpleAction :no-index: .. method:: 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. .. versionadded:: 2.28 :param enabled: whether the action is enabled .. method:: set_state(value: ~gi.repository.GLib.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 :func:`~gi.repository.Gio.Action.change_state` to request the change. If the ``value`` GVariant is floating, it is consumed. .. versionadded:: 2.30 :param value: the new :obj:`~gi.repository.GLib.Variant` for the state .. method:: set_state_hint(state_hint: ~gi.repository.GLib.Variant | None = None) -> None Sets the state hint for the action. See :func:`~gi.repository.Gio.Action.get_state_hint` for more information about action state hints. .. versionadded:: 2.44 :param state_hint: a :obj:`~gi.repository.GLib.Variant` representing the state hint Properties ---------- .. rst-class:: interim-class .. class:: SimpleAction :no-index: .. attribute:: props.enabled :type: bool If ``action`` is currently enabled. If the action is disabled then calls to :func:`~gi.repository.Gio.Action.activate` and :func:`~gi.repository.Gio.Action.change_state` have no effect. .. versionadded:: 2.28 .. attribute:: props.name :type: str The name of the action. This is mostly meaningful for identifying the action once it has been added to a :obj:`~gi.repository.Gio.SimpleActionGroup`. .. versionadded:: 2.28 .. attribute:: props.parameter_type :type: ~gi.repository.GLib.VariantType The type of the parameter that must be given when activating the action. .. versionadded:: 2.28 .. attribute:: props.state :type: ~gi.repository.GLib.Variant The state of the action, or :const:`None` if the action is stateless. .. versionadded:: 2.28 .. attribute:: props.state_type :type: ~gi.repository.GLib.VariantType The :obj:`~gi.repository.GLib.VariantType` of the state that the action has, or :const:`None` if the action is stateless. .. versionadded:: 2.28 Signals ------- .. rst-class:: interim-class .. class:: SimpleAction.signals :no-index: .. method:: activate(parameter: ~gi.repository.GLib.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 :const:`None` parameter type is to toggle them via the :obj:`~gi.repository.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 :obj:`~gi.repository.Gio.SimpleAction`::change-state. This should allow almost all users of :obj:`~gi.repository.Gio.SimpleAction` to connect only one handler or the other. .. versionadded:: 2.28 :param parameter: the parameter to the activation, or :const:`None` if it has no parameter .. method:: change_state(value: ~gi.repository.GLib.Variant | None = None) -> None 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 :func:`~gi.repository.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 :func:`~gi.repository.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 :func:`~gi.repository.Gio.SimpleAction.set_state` from the handler. An example of a 'change-state' handler: .. code-block:: C :dedent: 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. .. versionadded:: 2.30 :param value: the requested value for the state