gtk3gio

Using Gio.SimpleAction argument in stateless action


The documentation for Gio.SimpleAction.new says that I can specify a name, which is a string, and a parameter type, which is a GLib.VariantType (or None). If I specify a GLib.VariantType for the second argument, how do I specify its value?

I know that I can specify an argument in the connect call for the action, but then the first argument in the handler gets None. It seems as if it could be useful to specify a value for that argument, but I am not seeing how that is done.


Solution

  • You specify it's value in g_action_activate.

    Thus, you do the following, e.g. for boolean:

    vtype = GLib.VariantType.new("b")
    action = Gio.SimpleAction.new("name", vtype)
    # action.connect ("activate", handler, *args)
    value = GLib.Variant.new_boolean (True)
    a.activate(value)