]> git.sesse.net Git - vlc/blob - bindings/python/vlcdebug.py
python bindings: formatted to VLC coding style
[vlc] / bindings / python / vlcdebug.py
1 """Wrapper around vlc module in order to ease the use of vlc.Object
2 class (completion in ipython, access variable as attributes, etc).
3 """
4 import vlc
5
6 class VLCObject(object):
7     def __init__(self, id):
8         object.__setattr__(self, '_o', vlc.Object(id))
9
10     def find(self, typ):
11         t=self._o.find_object(typ)
12         if t is not None:
13             return VLCObject(t.info()['object-id'])
14         else:
15             return None
16
17     def __str__(self):
18         i=self._o.info()
19         return "VLCObject %d (%s) : %s" % (i['object-id'],
20                                            i['object-type'],
21                                            i['object-name'])
22
23     def tree(self, prefix=" "):
24         """Displays the children as a tree."""
25         print prefix, self
26         for i in self._o.children():
27             t=VLCObject(i)
28             t.tree(prefix=prefix + " ")
29         return
30
31     def __getattribute__(self, attr):
32         #print "Getting %s" % attr
33         if attr == '__members__':
34             o=object.__getattribute__(self, '_o')
35             l=dir(o)
36             l.extend([ n.replace('-','_') for n in o.list() ])
37             return l
38         try:
39             return object.__getattribute__ (self, attr)
40         except AttributeError, e:
41             try:
42                 return self._o.__getattribute__ (attr)
43             except AttributeError, e:
44                 attr=attr.replace('_', '-')
45                 if attr in self._o.list():
46                     return self._o.get(attr)
47                 else:
48                     raise e
49
50     def __setattr__(self, name, value):
51         n=name.replace('_', '-')
52         if n in self._o.list():
53             self._o.set(n, value)
54         else:
55             object.__setattr__(self, name, value)
56
57 #mc=vlc.MediaControl()
58 #mc.playlist_add_item('/tmp/k.mpg')
59 #mc.start(0)
60
61 def test():
62     global mc,o
63     mc=vlc.MediaControl()
64     mc.playlist_add_item('/tmp/k.mpg')
65     mc.start(0)
66     o=VLCObject(0)