RYX
July 30th, 2007, 04:49 PM
This is a small example of accessing compiz over dbus. I wrote it a while ago and just stepped across it on my hdd. Maybe it is of help to someone.
#!/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 (Rico Pfaus) 2007 - can be used freely (as in free beer)
#
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')
:)
#!/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 (Rico Pfaus) 2007 - can be used freely (as in free beer)
#
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')
:)