[vlc-commits] python bindings: override MediaPlayer. set_hwnd so that it is more flexible in argument types

Olivier Aubert git at videolan.org
Fri Apr 29 11:21:56 CEST 2011


vlc/python | branch: master | Olivier Aubert <olivier.aubert at liris.cnrs.fr> | Fri Apr 29 11:20:54 2011 +0200| [fbb35675f7669674150fdc9c616b5a8b4ef14d21] | committer: Olivier Aubert

python bindings: override MediaPlayer.set_hwnd so that it is more flexible in argument types

> http://git.videolan.org/gitweb.cgi/vlc/python.git/?a=commit;h=fbb35675f7669674150fdc9c616b5a8b4ef14d21
---

 generated/vlc.py |   44 +++++++++++++++++++++++++++++++++++---------
 override.py      |   13 +++++++++++++
 2 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/generated/vlc.py b/generated/vlc.py
index 27d6624..355c02d 100755
--- a/generated/vlc.py
+++ b/generated/vlc.py
@@ -39,6 +39,7 @@ C{get_instance} method of L{MediaPlayer} and L{MediaListPlayer}.
 """
 
 import ctypes
+from ctypes.util import find_library
 import os
 import sys
 
@@ -46,7 +47,7 @@ import sys
 from inspect import getargspec
 
 __version__ = "N/A"
-build_date  = "Thu Apr 14 18:33:30 2011"
+build_date  = "Fri Apr 29 10:39:54 2011"
 
  # Used on win32 and MacOS in override.py
 plugin_path = None
@@ -1935,6 +1936,19 @@ class MediaPlayer(_Ctype):
         else:
             raise VLCException('invalid video number (%s)' % (num,))
 
+    def set_hwnd(self, drawable):
+        """Set a Win32/Win64 API window handle (HWND).
+
+        Specify where the media player should render its video
+        output. If LibVLC was built without Win32/Win64 API output
+        support, then this has no effects.
+           
+        @param drawable: windows handle of the drawable.
+        """
+        if not isinstance(drawable, ctypes.c_void_p):
+            drawable = ctypes.c_void_p(int(drawable))
+        libvlc_media_player_set_hwnd(self, drawable)
+            
     def video_get_width(self, num=0):
         """Get the width of a video in pixels.
 
@@ -2117,14 +2131,6 @@ class MediaPlayer(_Ctype):
         '''
         return libvlc_media_player_get_xwindow(self)
 
-    def set_hwnd(self, drawable):
-        '''Set a Win32/Win64 API window handle (HWND) where the media player should
-        render its video output. If LibVLC was built without Win32/Win64 API output
-        support, then this has no effects.
-        @param drawable: windows handle of the drawable.
-        '''
-        return libvlc_media_player_set_hwnd(self, drawable)
-
     def get_hwnd(self):
         '''Get the Windows API window handle (HWND) previously set with
         L{set_hwnd}(). The handle will be returned even if LibVLC
@@ -5893,6 +5899,26 @@ def callbackmethod(callback):
     """Now obsolete @callbackmethod decorator."""
     return callback
 
+# libvlc_free is not present in some versions of libvlc. If it is not
+# in the library, then emulate it by calling libc.free
+if not hasattr(dll, 'libvlc_free'):
+    # need to find the free function in the C runtime. This is
+    # platform specific.
+    # For Linux and MacOSX
+    libc_path = find_library('c')
+    if libc_path:
+        libc = ctypes.CDLL(libc_path)
+        libvlc_free = libc.free        
+    else:
+        # On win32, it is impossible to guess the proper lib to call
+        # (msvcrt, mingw...). Just raise an exception.
+        def libvlc_free(p):
+            raise NotImplementedError('%s: %s without libvlc_free not supported' % (sys.argv[0], sys.platform))
+
+    # ensure argtypes is right, because default type of int won't work
+    # on 64-bit systems
+    libvlc_free.argtypes = [ ctypes.c_void_p ]
+
 # Version functions
 def _dot2int(v):
     '''(INTERNAL) Convert 'i.i.i[.i]' str to int.
diff --git a/override.py b/override.py
index f740d9e..42b3c90 100644
--- a/override.py
+++ b/override.py
@@ -198,6 +198,19 @@ class MediaPlayer:  #PYCHOK expected (comment is lost)
         else:
             raise VLCException('invalid video number (%s)' % (num,))
 
+    def set_hwnd(self, drawable):
+        """Set a Win32/Win64 API window handle (HWND).
+
+        Specify where the media player should render its video
+        output. If LibVLC was built without Win32/Win64 API output
+        support, then this has no effects.
+           
+        @param drawable: windows handle of the drawable.
+        """
+        if not isinstance(drawable, ctypes.c_void_p):
+            drawable = ctypes.c_void_p(int(drawable))
+        libvlc_media_player_set_hwnd(self, drawable)
+            
     def video_get_width(self, num=0):
         """Get the width of a video in pixels.
 



More information about the vlc-commits mailing list