]> git.sesse.net Git - vlc/blobdiff - bindings/python-ctypes/header.py
python-ctypes: improve enum conversion
[vlc] / bindings / python-ctypes / header.py
index fcaaaae74d1889a35c8ef2d51c6887634a0daaf0..cc951192fa3eb2e55c6c27ce9c77b1f13e32612c 100755 (executable)
@@ -76,6 +76,16 @@ elif sys.platform == 'darwin':
     # FIXME: should find a means to configure path
     dll=ctypes.CDLL('/Applications/VLC.app/Contents/MacOS/lib/libvlc.2.dylib')
 
+#
+# Generated enum types.
+#
+
+# GENERATED_ENUMS
+
+#
+# End of generated enum types.
+#
+
 class ListPOINTER(object):
     '''Just like a POINTER but accept a list of ctype as an argument.
     '''
@@ -157,24 +167,35 @@ class LogMessage(ctypes.Structure):
 
 class MediaControlPosition(ctypes.Structure):
     _fields_= [
-                ('origin', ctypes.c_int),
-                ('key', ctypes.c_int),
+                ('origin', PositionOrigin),
+                ('key', PositionKey),
                 ('value', ctypes.c_longlong),
                 ]
 
+    def __init__(self, value=0, origin=None, key=None):
+        # We override the __init__ method so that instanciating the
+        # class with an int as parameter will create the appropriate
+        # default position (absolute position, media time, with the
+        # int as value).
+        self.value=value
+        if origin is None:
+            origin=PositionOrigin.AbsolutePosition
+        if key is None:
+            key=PositionKey.MediaTime
+        self.origin=origin
+        self.key=key
+
     def __str__(self):
         return "MediaControlPosition %ld (%s, %s)" % (
             self.value,
-            str(PositionOrigin(self.origin)),
-            str(PositionKey(self.key))
+            str(self.origin),
+            str(self.key)
             )
 
     @staticmethod
     def from_param(arg):
         if isinstance(arg, (int, long)):
-            p=MediaControlPosition()
-            p.value=arg
-            p.key=2
+            p=MediaControlPosition(arg)
             return p
         else:
             return arg
@@ -192,15 +213,15 @@ class MediaControlException(ctypes.Structure):
 
 class MediaControlStreamInformation(ctypes.Structure):
     _fields_= [
-                ('status', ctypes.c_int),
+                ('status', PlayerStatus),
                 ('url', ctypes.c_char_p),
                 ('position', ctypes.c_longlong),
                 ('length', ctypes.c_longlong),
                 ]
 
     def __str__(self):
-        return "%s (%s) : %ld / %ld" % (self.url,
-                                        str(PlayerStatus(self.status)),
+        return "%s (%s) : %ld / %ld" % (self.url or "<No defined URL>",
+                                        str(self.status),
                                         self.position,
                                         self.length)