1 """Wrapper around vlc module in order to ease the use of vlc.Object
2 class (completion in ipython, access variable as attributes, etc).
6 class VLCObject(object):
7 def __init__(self, id):
8 object.__setattr__(self, '_o', vlc.Object(id))
11 """Returns a VLCObject for the given child.
13 See vlc.Object.find_object.__doc__ for the different values of typ.
15 t=self._o.find_object(typ)
17 return VLCObject(t.info()['object-id'])
22 """Returns a string representation of the object.
25 return "VLCObject %d (%s) : %s" % (i['object-id'],
29 def tree(self, prefix=" "):
30 """Displays all children as a tree of VLCObject
32 res=prefix + str(self) + "\n"
33 for i in self._o.children():
35 res += t.tree(prefix=prefix + " ")
38 def __getattribute__(self, attr):
39 """Converts attribute access to access to variables.
41 if attr == '__members__':
42 # Return the list of variables
43 o=object.__getattribute__(self, '_o')
45 l.extend([ n.replace('-','_') for n in o.list() ])
48 return object.__getattribute__ (self, attr)
49 except AttributeError, e:
51 return self._o.__getattribute__ (attr)
52 except AttributeError, e:
53 attr=attr.replace('_', '-')
54 if attr in self._o.list():
55 return self._o.get(attr)
59 def __setattr__(self, name, value):
60 """Handle attribute assignment.
62 n=name.replace('_', '-')
63 if n in self._o.list():
66 object.__setattr__(self, name, value)
68 def test(f='/tmp/k.mpg'):
71 mc.playlist_add_item(f)