开发者

Python dbus can't find org.(gnome|freedesktop).ScreenSaver

I'm trying to get python to interact with dbus and screensaver however it flatly refuses to do so no matter what. Perl seems to do alright with it but I write python, not perl (yet)

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

Here's what I've seen in other places in 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
}
}


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜