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.
19 from rox
.options
import OptionGroup
, Option
20 from rox
import OptionsBox
, g
26 dbus_ok
=(dbus
.version
>=(0, 42, 0))
31 bus
= dbus
.Bus(dbus
.Bus
.TYPE_SESSION
)
35 session_service
= "net.sf.rox.Session"
36 control_object
= '/Session'
37 control_interface
= 'net.sf.rox.Session.Control'
38 settings_interface
= 'net.sf.rox.Session.Settings'
39 settings_object
= '/Settings'
41 def _dbus_get_proxy(bus
, service_name
, object_name
, interface_name
):
42 """For internal use. Do not call this, call get_proxy() instead."""
44 service
= bus
.get_service(service_name
)
45 obj
= service
.get_object(object_name
, interface_name
)
47 except AttributeError:
48 obj
= bus
.get_object(service_name
, object_name
)
49 iface
= dbus
.Interface(obj
, interface_name
)
54 """For internal use."""
55 def __init__(self
, method
):
58 def __call__(self
, *params
):
59 client
=self
.method(*params
)
60 return client
.get_response()
63 """For internal use."""
64 def __init__(self
, obj
):
67 def __getattr__(self
, method
):
68 invoke
=self
.obj
.__getattr
__(method
)
69 return _caller(invoke
)
71 def _xxmlrpc_get_proxy(service_name
, object_name
, interface_name
):
72 """For internal use. Do not call this, call get_proxy() instead."""
73 proxy
=rox
.xxmlrpc
.XXMLProxy(service_name
)
74 return _RPCProxy(proxy
.get_object(object_name
))
76 def get_proxy(service_name
, object_name
, interface_name
):
77 """Get a proxy object for the required service, object path and interface.
78 This selects an appropriate transport for you, either DBus or XMLRPC."""
80 return _dbus_get_proxy(bus
, service_name
, object_name
, interface_name
)
81 return _xxmlrpc_get_proxy(service_name
, object_name
, interface_name
)
84 """Return a proxy object for the ROX-Session settings interface"""
85 return get_proxy(session_service
, control_object
,
89 """Return a proxy object for the ROX-Session control interface"""
90 return get_proxy(session_service
, settings_object
,
94 """Return True if ROX-Session is detected as running"""
96 proxy
=_xxmlrpc_get_proxy(session_service
, control_object
,
98 return proxy
is not None
100 proxy
= get_proxy('org.freedesktop.DBus', '/org/freedesktop/DBus',
101 'org.freedesktop.DBus')
106 services
= proxy
.ListServices()
108 services
= proxy
.ListNames()
110 return session_service
in services
113 if __name__
=='__main__':
114 print 'Session running? %s' % running()
115 settings
=get_settings()
116 #print 'settings=', settings
118 print '%s = %s' % (v
, settings
.GetSetting(v
))
119 #x=settings.GetSetting(v)
124 print '%s = %s' % (v
, settings
.GetSetting(v
))
125 control
=get_session()
126 control
.ShowMessages()