]> git.sesse.net Git - vlc/blob - bindings/python-ctypes/override.py
python-ctypes: improve documentation generation
[vlc] / bindings / python-ctypes / override.py
1 class Instance:
2     """Create a new Instance instance.
3
4     It may take as parameter either:
5       - a string
6       - a list of strings as first parameters
7       - the parameters given as the constructor parameters (must be strings)
8       - a MediaControl instance
9     """
10     def __new__(cls, *p):
11         if p and p[0] == 0:
12             return None
13         elif p and isinstance(p[0], (int, long)):
14             # instance creation from ctypes
15             o=object.__new__(cls)
16             o._as_parameter_=ctypes.c_void_p(p[0])
17             return o
18         elif len(p) == 1 and isinstance(p[0], basestring):
19             # Only 1 string parameter: should be a parameter line
20             p=p[0].split(' ')
21         elif len(p) == 1 and isinstance(p[0], (tuple, list)):
22             p=p[0]
23
24         if p and isinstance(p[0], MediaControl):
25             return p[0].get_instance()
26         else:
27             e=VLCException()
28             return libvlc_new(len(p), p, e)
29
30     def media_player_new(self, uri=None):
31         """Create a new Media Player object.
32
33         @param uri: an optional URI to play in the player.
34         """
35         e=VLCException()
36         p=libvlc_media_player_new(self, e)
37         if uri:
38             p.set_media(self.media_new(uri))
39         p._instance=self
40         return p
41
42     def media_list_player_new(self):
43         """Create an empty Media Player object
44         """
45         e=VLCException()
46         p=libvlc_media_list_player_new(self, e)
47         p._instance=self
48         return p
49
50 class MediaControl:
51     """Create a new MediaControl instance
52
53     It may take as parameter either:
54       - a string
55       - a list of strings as first parameters
56       - the parameters given as the constructor parameters (must be strings)
57       - a vlc.Instance
58     """
59     def __new__(cls, *p):
60         if p and p[0] == 0:
61             return None
62         elif p and isinstance(p[0], (int, long)):
63             # instance creation from ctypes
64             o=object.__new__(cls)
65             o._as_parameter_=ctypes.c_void_p(p[0])
66             return o
67         elif len(p) == 1 and isinstance(p[0], basestring):
68             # Only 1 string parameter: should be a parameter line
69             p=p[0].split(' ')
70         elif len(p) == 1 and isinstance(p[0], (tuple, list)):
71             p=p[0]
72
73         if p and isinstance(p[0], Instance):
74             e=MediaControlException()
75             return mediacontrol_new_from_instance(p[0])
76         else:
77             e=MediaControlException()
78             return mediacontrol_new(len(p), p, e)
79
80 class MediaPlayer:
81     """Create a new MediaPlayer instance.
82
83     It may take as parameter either:
84       - a string (media URI). In this case, a vlc.Instance will be created.
85       - a vlc.Instance
86     """
87     def __new__(cls, *p):
88         if p and p[0] == 0:
89             return None
90         elif p and isinstance(p[0], (int, long)):
91             # instance creation from ctypes
92             o=object.__new__(cls)
93             o._as_parameter_=ctypes.c_void_p(p[0])
94             return o
95
96         if p and isinstance(p[0], Instance):
97             return p[0].media_player_new()
98         else:
99             i=Instance()
100             o=i.media_player_new()
101             if p:
102                 o.set_media(i.media_new(p[0]))
103             return o
104
105     def get_instance(self):
106         """Return the associated vlc.Instance.
107         """
108         return self._instance
109
110 class MediaListPlayer:
111     """Create a new MediaPlayer instance.
112
113     It may take as parameter either:
114       - a vlc.Instance
115       - nothing
116     """
117     def __new__(cls, *p):
118         if p and p[0] == 0:
119             return None
120         elif p and isinstance(p[0], (int, long)):
121             # instance creation from ctypes
122             o=object.__new__(cls)
123             o._as_parameter_=ctypes.c_void_p(p[0])
124             return o
125         elif len(p) == 1 and isinstance(p[0], (tuple, list)):
126             p=p[0]
127
128         if p and isinstance(p[0], Instance):
129             return p[0].media_list_player_new()
130         else:
131             i=Instance()
132             o=i.media_list_player_new()
133             return o
134
135     def get_instance(self):
136         """Return the associated vlc.Instance.
137         """
138         return self._instance
139
140 class LogIterator:
141     def __iter__(self):
142         return self