PDA

View Full Version : python-compizutil 0.0.1- a compiz utility library for python


RYX
April 26th, 2007, 07:47 PM
Hello everybody!

This is the first version of the compizutil-library for python - it greatly simplifies accessing compiz over an unlimited number of different backends and offers a higher-level interface for working with compiz, its plugins and its options - in an OOP-like way. The package also contains a useful tool called 'compiztool' which allows editing compiz's basic configuration and settings from the commandline. The compiztool is also an example for how to use the compizutil-library.

A quote from the README:This library is aimed at providing classes and objects that simplify
working with compiz over various backends. The Compiz-class itself
provides a nice, higher-level, object-oriented interface to compiz,
while entirely hiding the abstracted communication-backends.
The average user (i.e. python-coder) may most likely want to work
with the simplified frontend-classes like Compiz, CompizPlugin
or the CompizOption-subclasses. However - more advanced users are
still free to directly access the backend to get to a lower level.
You can directly access the Backend Compiz.backend and use its
common functions.
The docs/examples-directory contains some examples of how to use the
compizutil-library. The bin/compiztool is a tiny "real-world" tool that
gets installed globally and can be quite handy for testing and/or playing.

DOWNLOAD: http://www.ryxperience.com/compiz/compizutil/python-compizutil-0.0.1.tar.gz

(NOTE: This has only been tested on python2.5 and you will need the latest dbus-bindings for python, in Feisty everything should be installed by default)

See the README for some additional info. See the docs/examples-dir for some example-scripts that explain most aspects of compizutil. There is only a dbus-backend yet, so maybe someone likes to write an ini- or gconf-backend?

Some examples:

Get all active plugins from compiz and output each plugins' shortDesc:plugins = Compiz.get_active_plugins()
for plugin in plugins:
print plugin.shortDesc

Get single option from a plugin and get its value:plugin = Compiz.get_plugin('decoration')
if plugin and plugin.is_active():
opt = plugin.get_option('shadow_color')
if opt:
print opt.get_value()

(De-)Activate a plugin:Compiz.deactivate_plugin('cube')
Compiz.activate_plugin('plane')

Get single option from a plugin and set its value:plugin = Compiz.get_plugin('decoration')
if plugin and plugin.is_active():
opt = plugin.get_option('shadow_color')
if opt:
opt.set_value('#ff0000ff')

I'd be happy about any comments, suggestions and bug-reports. This lib should go into our git-repo as soon as possible so many people can start working on (and with) it.

:)

Vasek
April 27th, 2007, 02:09 PM
Get single option from a plugin and get its value:plugin = Compiz.get_plugin('decoration')
if plugin and plugin.is_active():
opt = plugin.get_option('shadow_color')
if opt:
print opt.get_value()
Hi, RYX :)

I haven't had opportunity to see this in action yet, but it looks great!

I have just a small note right now: wouldn't you consider using the Python's exception system for the options? Checking the result of every operation makes the code a bit ugly... I understand this approach is the best for get_plugin, but not knowing what options a loaded plugin provides (= wanting a nonexistent one) is quite a serious error, isn't it?

RYX
April 30th, 2007, 01:33 PM
Hi, RYX :)

I haven't had opportunity to see this in action yet, but it looks great!

I have just a small note right now: wouldn't you consider using the Python's exception system for the options? Checking the result of every operation makes the code a bit ugly... I understand this approach is the best for get_plugin, but not knowing what options a loaded plugin provides (= wanting a nonexistent one) is quite a serious error, isn't it?
Hi Vasek :) ...

Thanks for your answer and I think you're right, the lib should make more use of exceptions. It is just more the way a higher-level binding should behave ...

I'd be happy if you could have some closer look at the examples and the code in general once you find the time. You know how it is - four eyes see more than two :D ... (This lib could also become quite handy for compiz-related screenlets ...)

Sorcerer
April 30th, 2007, 02:25 PM
I'm getting a DBus error:
compiz_call(core/allscreens/hsize, getMetadata): Error: org.freedesktop.DBus.Error.UnknownMethod: Method "getMetadata" with signature "" on interface "org.freedesktop.compiz" doesn't exist
dbus plugin is loaded, using Compiz 0.5.0. Dbus-viewer doesn't show anything under org.freedesktop.compiz

RYX
April 30th, 2007, 05:34 PM
The message is a bit misleading, the key doesn't exist ... Hsize/Vsize is a per-screen setting, it is in "core/screen0/vsize". There are still some debug-messages dumped out which may cause more confusion then they solve ...

:)