"""Wrapper around vlc module in order to ease the use of vlc.Object
class (completion in ipython, access variable as attributes, etc).
"""
import vlc

class VLCObject(object):
    def __init__(self, id):
        object.__setattr__(self, '_o', vlc.Object(id))

    def find(self, typ):
        t=self._o.find_object(typ)
        if t is not None:
            return VLCObject(t.info()['object-id'])
        else:
            return None

    def __str__(self):
        i=self._o.info()
        return "VLCObject %d (%s) : %s" % (i['object-id'],
                                           i['object-type'],
                                           i['object-name'])

    def tree(self, prefix=" "):
        """Displays the children as a tree."""
        print prefix, self
        for i in self._o.children():
            t=VLCObject(i)
            t.tree(prefix=prefix + " ")
        return

    def __getattribute__(self, attr):
        #print "Getting %s" % attr
        if attr == '__members__':
            o=object.__getattribute__(self, '_o')
            l=dir(o)
            l.extend([ n.replace('-','_') for n in o.list() ])
            return l
        try:
            return object.__getattribute__ (self, attr)
        except AttributeError, e:
            try:
                return self._o.__getattribute__ (attr)
            except AttributeError, e:
                attr=attr.replace('_', '-')
                if attr in self._o.list():
                    return self._o.get(attr)
                else:
                    raise e

    def __setattr__(self, name, value):
        n=name.replace('_', '-')
        if n in self._o.list():
            self._o.set(n, value)
        else:
            object.__setattr__(self, name, value)

#mc=vlc.MediaControl()
#mc.playlist_add_item('/tmp/k.mpg')
#mc.start(0)

def test():
    global mc,o
    mc=vlc.MediaControl()
    mc.playlist_add_item('/tmp/k.mpg')
    mc.start(0)
    o=VLCObject(0)

@@ -278,16 +278,136 @@
 , typ):%0A
+%09%22%22%22Returns a VLCObject for the given child.%0A%0A%09See vlc.Object.find_object.__doc__ for the different values of typ.%0A%09%22%22%22%0A
         
@@ -573,16 +573,72 @@
 (self):%0A
+%09%22%22%22Returns a string representation of the object.%0A%09%22%22%22%0A
         
@@ -888,19 +888,19 @@
 isplays 
-the
+all
  childre
@@ -910,17 +910,31 @@
 s a tree
-.
+ of VLCObject%0A%09
 %22%22%22%0A    
@@ -1118,76 +1118,136 @@
 r):%0A
-        #print %22Getting %25s%22 %25 attr%0A        if attr == '__members__':
+%09%22%22%22Converts attribute access to access to variables.%0A%09%22%22%22%0A        if attr == '__members__':%0A%09    # Return the list of variables
 %0A   
@@ -1834,16 +1834,54 @@
 value):%0A
+%09%22%22%22Handle attribute assignment.%0A%09%22%22%22%0A
         
@@ -2040,90 +2040,31 @@
 e)%0A%0A
-#mc=vlc.MediaControl()%0A#mc.playlist_add_item('/tmp/k.mpg')%0A#mc.start(0)%0A%0Adef test(
+def test(f='/tmp/k.mpg'
 ):%0A 
@@ -2129,28 +2129,17 @@
 dd_item(
-'/tmp/k.mpg'
+f
 )%0A    mc
@@ -2156,19 +2156,57 @@
     
-o=VLCObject(0)
+mc.pause(0)%0A    o=VLCObject(0)%0A    v=o.find('vout')%0A
 %0A

add documentation