I am trying to create a Gio.SimpleAction
and connecting to its change-state
signal, for taking an specific action when the state is changed, but I have failed to come up with a working code.
Here is an example of what I have tried (and expected to work), without success:
from gi.repository import Gio, GLib
call_count = 0
def _state_changed(action, state):
action.set_state(state)
global call_count
call_count += 1
print(state)
a = Gio.SimpleAction.new_stateful('foo', None, GLib.Variant.new_boolean(False))
a.connect('change-state', _state_changed)
print a.get_state().get_boolean()
a.set_state(GLib.Variant.new_boolean(True))
print a.get_state().get_boolean()
print call_count
The output of running this code is:
False
True
0
As we can see, the state is indeed changed, but no change-state was emitted!
Is there something wrong with this code sample? How do I properly detect a state change in a Gio.SimpleAction
?