Python dbus无法找到org。(gnome | freedesktop).ScreenSaver

时间:2010-12-14 18:12:29

标签: python gnome dbus

我正在尝试使用python与dbus和屏幕保护程序进行交互,但无论如何它都不会这样做。 Perl似乎没问题,但是我写的是python,而不是perl(还)

Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
>>> bus = dbus.SystemBus()
>>> ofn = 'org.freedesktop.ScreenSaver'
>>> bus.get_object(ofn, "/org/freedesktop/ScreenSaver")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 244, in get_object
    follow_name_owner_changes=follow_name_owner_changes)
  File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 241, in __init__
    self._named_service = conn.activate_name_owner(bus_name)
  File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 183, in activate_name_owner
    self.start_service_by_name(bus_name)
  File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 281, in start_service_by_name
    'su', (bus_name, flags)))
  File "/usr/lib/pymodules/python2.6/dbus/connection.py", line 620, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.ScreenSaver was not provided by any .service files
>>> 

以下是我在perl的其他地方看到的内容:

my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='SessionIdleChanged'\"";

open (IN, "$cmd |");

while (<IN>) {
if (m/^\s+boolean true/) {
  #print something
} elsif (m/^\s+boolean false/) {
  #print something else
}
}

1 个答案:

答案 0 :(得分:4)

In [36]: import dbus

In [37]: bus = dbus.SessionBus()

In [38]: bus.get_object('org.gnome.ScreenSaver','/org/gnome/ScreenSaver')
Out[38]: <ProxyObject wrapping <dbus._dbus.SessionBus (session) at 0xa41e38c> :1.24 /org/gnome/ScreenSaver at 0xa4a3b0c>