2
我希望能够在第一调用一个简单的脚本来启用或我的上网本禁用外部显示器。我使用XFCE作为桌面运行Fedora 17。我看到我应该可以使用python和python-dbus来反复启用和关闭活动。我的问题是,我无法弄清楚如何发出一个信号让新的设置激活。不幸的是,Python不是我经常使用的语言。我有到位的代码是:发射信号使用Python-DBUS
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
我花了一点时间寻找,我没有找到许多蟒蛇的例子做任何接近这个。提前致谢。