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
我花了一點時間尋找,我沒有找到許多蟒蛇的例子做任何接近這個。提前致謝。