: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 The type of the None singleton. .. versionadded:: 2.28 .. attribute:: props.name :type: str The type of the None singleton. .. versionadded:: 2.28 .. attribute:: props.parameter_type :type: ~gi.repository.GLib.VariantType The type of the None singleton. .. versionadded:: 2.28 .. attribute:: props.state :type: ~gi.repository.GLib.Variant The type of the None singleton. .. versionadded:: 2.28 .. attribute:: props.state_type :type: ~gi.repository.GLib.VariantType The type of the None singleton. .. 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 The type of the None singleton. .. versionadded:: 2.30 :param value: the requested value for the state