1 """Wrapper around vlc module in order to ease the use of vlc.Object
2 class (completion in ipython, access variable as attributes, etc).
9 class VLCObject(object):
10 def __init__(self, id):
11 object.__setattr__(self, '_o', vlcinternal.Object(id))
14 """Returns a VLCObject for the given child.
16 See vlc.Object.find_object.__doc__ for the different values of typ.
18 t=self._o.find_object(typ)
20 return VLCObject(t.info()['object-id'])
25 """Returns a string representation of the object.
28 return "VLCObject %d (%s) : %s" % (i['object-id'],
32 def tree(self, prefix=" "):
33 """Displays all children as a tree of VLCObject
35 res=prefix + str(self) + "\n"
36 for i in self._o.children():
38 res += t.tree(prefix=prefix + " ")
41 def __getattribute__(self, attr):
42 """Converts attribute access to access to variables.
44 if attr == '__members__':
45 # Return the list of variables
46 o=object.__getattribute__(self, '_o')
48 l.extend([ n.replace('-','_') for n in o.list() ])
51 return object.__getattribute__ (self, attr)
52 except AttributeError, e:
54 return self._o.__getattribute__ (attr)
55 except AttributeError, e:
56 attr=attr.replace('_', '-')
57 if attr in self._o.list():
58 return self._o.get(attr)
62 def __setattr__(self, name, value):
63 """Handle attribute assignment.
65 n=name.replace('_', '-')
66 if n in self._o.list():
69 object.__setattr__(self, name, value)
71 def test(f='/tmp/k.mpg'):
74 mc.playlist_add_item(f)