我希望首先能够调用一个简单的脚本来启用或禁用我的上网本中的外部显示器。我正在使用XFCE作为我的桌面运行Fedora 17。我知道我应该能够使用python和python-dbus来打开和关闭活动。我的问题是,我不知道如何发出信号来激活新的设置。不幸的是,Python不是我经常使用的语言。我准备好的代码是:
import dbus
item = 'org.xfce.Xfconf'
path = '/org/xfce/Xfconf'
channel = 'displays'
base = '/'
setting = '/Default/VGA1/Active'
bus = dbus.SessionBus()
remote_object = bus.get_object(item, path)
remote_interface = dbus.Interface(remote_object, "org.xfce.Xfconf")
if remote_interface.GetProperty(channel, setting):
remote_interface.SetProperty(channel, setting, '0')
remote_object.PropertyChanged(channel, setting, '0')
else:
remote_interface.SetProperty(channel, setting, '1')
remote_object.PropertyChanged(channel, setting, '0')它正在失败并被踢出去:
Traceback (most recent call last): File "./vgaToggle", line 31, in <module>
remote_object.PropertyChanged(channel, setting, '0')
File "/usr/lib/python2.7/site-packages/dbus/proxies.py", line 140, in __call__
**keywords)
File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 630, in call_blocking
message, timeout) dbus.exceptions.DBusException:
org.freedesktop.DBus.Error.UnknownMethod: Method "PropertyChanged"
with signature "sss" on interface "(null)" doesn't exist我花了一些时间搜索,但我没有找到很多与此类似的python示例。提前谢谢。
发布于 2012-11-11 14:58:25
PropertyChanged是一个信号,而不是一个方法。您与之通信的服务负责发出信号。在这种情况下,只要相应对象或接口上的属性值发生更改,PropertyChanged就应该隐式触发。
这应该在调用remote_interface.SetProperty(...)时隐式地发生,并且不需要像方法一样显式地“调用”信号。
如果您对接收信号感兴趣,则需要设置一个glib主循环,并在代理对象上调用connect_to_signal,向其传递一个回调方法以供调用。
https://stackoverflow.com/questions/13057051
复制相似问题