1 """Contact ROX-Session via the DBus or XMLRPC interface. Using get_session()
2 will return a proxy object on which you can make remote calls to control
3 the session. Similarly get_settings() will return an object to control
7 settings = session.get_settings()
8 type, value = settings.GetSetting('Gtk/KeyThemeName')
10 # No ROX-Session available, do something else
12 In addition the Setting class is provided which derives from rox.options.Option
13 but has two important differences: it is not saved to the options file and
14 it is synchronized with a value of the same name in the ROX-Session settings.
23 dbus_ok
=(dbus
.version
>=(0, 42, 0))
28 bus
= dbus
.Bus(dbus
.Bus
.TYPE_SESSION
)
32 session_service
= "net.sf.rox.Session"
33 control_object
= '/Session'
34 control_interface
= 'net.sf.rox.Session.Control'
35 settings_interface
= 'net.sf.rox.Session.Settings'
36 settings_object
= '/Settings'
38 def _dbus_get_proxy(bus
, service_name
, object_name
, interface_name
):
39 """For internal use. Do not call this, call get_proxy() instead."""
41 service
= bus
.get_service(service_name
)
42 obj
= service
.get_object(object_name
, interface_name
)
44 except AttributeError:
45 obj
= bus
.get_object(service_name
, object_name
)
46 iface
= dbus
.Interface(obj
, interface_name
)
51 """For internal use."""
52 def __init__(self
, method
):
55 def __call__(self
, *params
):
56 client
=self
.method(*params
)
57 return client
.get_response()
60 """For internal use."""
61 def __init__(self
, obj
):
64 def __getattr__(self
, method
):
65 invoke
=self
.obj
.__getattr
__(method
)
66 return _caller(invoke
)
68 def _xxmlrpc_get_proxy(service_name
, object_name
, interface_name
):
69 """For internal use. Do not call this, call get_proxy() instead."""
70 proxy
=rox
.xxmlrpc
.XXMLProxy(service_name
)
71 return _RPCProxy(proxy
.get_object(object_name
))
73 def get_proxy(service_name
, object_name
, interface_name
):
74 """Get a proxy object for the required service, object path and interface.
75 This selects an appropriate transport for you, either DBus or XMLRPC."""
77 return _dbus_get_proxy(bus
, service_name
, object_name
, interface_name
)
78 return _xxmlrpc_get_proxy(service_name
, object_name
, interface_name
)
81 """Return a proxy object for the ROX-Session settings interface"""
82 return get_proxy(session_service
, control_object
,
86 """Return a proxy object for the ROX-Session control interface"""
87 return get_proxy(session_service
, settings_object
,
91 """Return True if ROX-Session is detected as running"""
92 if not dbus_ok
or not bus
:
93 proxy
=_xxmlrpc_get_proxy(session_service
, control_object
,
95 return proxy
is not None
97 proxy
= get_proxy('org.freedesktop.DBus', '/org/freedesktop/DBus',
98 'org.freedesktop.DBus')
103 services
= proxy
.ListServices()
105 services
= proxy
.ListNames()
107 return session_service
in services
109 if bus
and not running():
113 if __name__
=='__main__':
114 print 'Session running? %s' % running()
115 settings
=get_settings()
119 v
=settings
.GetSetting(name
)
120 print '%s = %s' % (name
, v
)
121 except Exception, exc
:
122 print "Can't get %s: %s" % (name
, exc
)
124 test_get('Gtk/KeyThemeName')
125 test_get('Net/ThemeName')
127 control
=get_session()
128 control
.ShowMessages()