我正在尝试创建一个
Gio.SimpleAction
并连接到其
change-state
信号,用于在状态发生更改时采取特定操作,但我未能想出有效代码。
下面是一个我尝试过(并期望成功)但没有成功的例子:
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
运行此代码的输出为:
False
True
0
正如我们所看到的,状态确实发生了更改,但没有发出更改状态!
此代码示例是否有问题?如何正确检测
Gio。简化操作
?