PDA

View Full Version : [Python] Accessing compiz-options through dbus


RYX
March 1st, 2007, 12:37 AM
I am trying to get all options of a plugin with a dbus-call but somehow I always get an empty list ...

#!/usr/bin/env python

# A little test of getting compiz-options from python ...
#
# (by RYX) - can be used freely

import dbus

# init service/interface
COMPIZ_DBUS_SERVICE = 'org.freedesktop.compiz'
COMPIZ_DBUS_INTERFACE = 'org.freedesktop.compiz'

# get session bus
bus = dbus.SessionBus()

# utility function to call methods in compiz
def compiz_call_method(obj_path, func_name, *args):
"""Call method in obj_path in compiz-service over dbus."""
tmp_obj = bus.get_object(COMPIZ_DBUS_SERVICE, obj_path)
tmp_iface = dbus.Interface(tmp_obj, COMPIZ_DBUS_INTERFACE)
func = getattr(tmp_iface, func_name)
if func:
return func(*args)
return None

# test getting various things
#print compiz_call_method('/org/freedesktop/compiz', 'getPlugins')
#print compiz_call_method('/org/freedesktop/compiz', 'getPluginMetadata', 'cube')
#print compiz_call_method('/org/freedesktop/compiz/core/allscreens', 'list')
print compiz_call_method('/org/freedesktop/compiz/cube/allscreens', 'list')


The commented calls work fine. Getting list of plugins is no problem, getting core options works, getting metadata works - only plugin-options are empty. Does anyone know how to retrieve the list of options for a plugin? Or am I doing it wrong?

(I thought the plugins would offer some type of dbus-interface, but they don't, am I right? Just method-calls ...)

Thanks in advance.

:)

RAOF
March 1st, 2007, 12:46 AM
Amaranth's new introspectable DBUS plugin will probably not immediately help you, but will herald an era of changing the Compiz DBUS API, hopefully to something a little more sane :)

RYX
March 1st, 2007, 02:33 AM
I got it working. Don't know what I did wrong before.

#!/usr/bin/env python

# A little test of connecting compiz from python over dbus ...
# Should be a good base for creating a simple settings-manager in python.
#
# (by RYX) - can be used freely

import dbus

# init service/interface
COMPIZ_DBUS_SERVICE = 'org.freedesktop.compiz'
COMPIZ_DBUS_INTERFACE = 'org.freedesktop.compiz'
COMPIZ_DBUS_OBJECT = '/org/freedesktop/compiz'

# get session bus
bus = dbus.SessionBus()

# utility function to call methods in compiz
def compiz_call(obj_path, func_name, *args):
"""Call method in obj_path in compiz-service over dbus. The compiz-object's
path does not need to be passed."""
path = COMPIZ_DBUS_OBJECT
if obj_path:
path += '/' + obj_path
obj = bus.get_object(COMPIZ_DBUS_SERVICE, path)
iface = dbus.Interface(obj, COMPIZ_DBUS_INTERFACE)
func = getattr(iface, func_name)
if func:
try:
return func(*args)
except Exception, ex:
print "compiz_call(): Dbus-error: " + str(ex)
return None

# test getting various things
# get list of plugins
print "/org/freedesktop/compiz.getPlugins:"
print compiz_call('', 'getPlugins')

# get metadata for a specific plugin
print "\n/org/freedesktop/compiz.getPluginMetadata('cube'):"
print compiz_call('', 'getPluginMetadata', 'cube')

# get all core-options that apply to all screens
print "\n/org/freedesktop/compiz/core/allscreens.list:"
print compiz_call('core/allscreens', 'list')

# get metadata for a specific option
print "\n/org/freedesktop/compiz/core/screen0/lighting.getMetadata:"
print compiz_call('core/screen0/lighting', 'getMetadata')

# get the value of an option
print "\n/org/freedesktop/compiz/core/screen0/lighting.get:"
print compiz_call('core/screen0/lighting', 'get')

# get all options for a plugin
print "\n/org/freedesktop/compiz/decoration/allscreens.list:"
print compiz_call('decoration/allscreens', 'list')

# get the value of a plugin's option
print "\n/org/freedesktop/compiz/decoration/allscreens/shadow_color.get:"
print compiz_call('decoration/allscreens/shadow_color', 'get')



Thanks anyway, RAOF :) The new dbus-plugin will surely make things better but for a settings-manager the current one seems to be enough.

:)

Amaranth
March 1st, 2007, 04:40 AM
My introspection work does not change the API but I plan to post some API change patches after the introspection one gets included.