2

I want to be able to at first call a simple script to enable or disable an external monitor from my netbook. I am running Fedora 17 with XFCE as my desktop. I see that I should be able to use python and python-dbus to flip toggle active on and off. My problem is that I can't figure out how to emit a signal to get the new setting to go active. Unfortunately Python is not a language that I use often. The code that I have in place is:

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')

It is failing and kicking out:

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

I spent a bit of time searching and I am not finding many python examples doing anything close to this. Thanks in advance.

risaacson
  • 33
  • 5

1 Answers1

0

PropertyChanged is a signal, not a method. The services you are communicating with are responsible for emitting signals. In this case, the PropertyChanged should fire implicitly, whenever the value of the property on the respective objects or interfaces have changed.

This should happen implicitly when you call remote_interface.SetProperty(...), and you should not need to explicitly "call" the signal like a method.

If you are interested in receiving the signals, you will need to set up a glib main loop and call connect_to_signal on your proxy object, passing it a callback method to invoke.

fmoo
  • 769
  • 5
  • 11