Hi Andy,
On Apr 15, 2011, at 8:37 AM, adwelly wrote:
> I am trying to get wxPython 2.9.1 Cocoa and VLC, via vlc.py to play
> together nicely. I've managed to do this with wxPython 2.8 under
> windows and linux
> but ran into a problem with 2.8 on a Mac.
> The issue is that once a nice UI has been set up with wxPython, vlc
> has to be informed where to start rendering its video. On windows
> under wxPython 2.8
> you get the HWND associated with a wx.Panel with wx.Panel.GetHandle(),
> you can then inform vlc with a call to vlc.MediaPlayer.set_hwnd().
> On linux using X the process is similar. Call wx.Panel.GetHandle() and
> vlc.MediaPlayer.set_xwindow().
> Under wx 2.8 the problem arises that although vlc.MediaPlayer has a
> set_nsobject() function, wx is built for carbon not cocoa so there is
> no nsobject to be had.
> I've now installed wx 2.9.1 for cocoa and python 2.7.1 It builds an
> excellent Cocoa UI and most aspects seem to work. However, I now need
> to get the ns object associated with the panel, and in fact what I'm
> actually looking for is an NS object that meets the export
> addVoutSubview protocol. That's what vlc is expecting and
> unfortunately I can't change it.
> The actual error I'm getting is:
> -[wxNSView addVoutSubview:]: unrecognized selector sent to instance
> 0x3662c0
> so I guess the wxNSView object that represents a panel can't currently
> have video subviews associated with it. Is there any way around
> this ?
Well, this is quite a pickle. :( You *might* be able to do some really black magic using PyObjC to solve this issue by dynamically adding those methods to your wxPanel's underlying NSView. It would go something like this:
import objc
from AppKit import *
def addVoutSubview_(self, subview):
subview.setFrame_(self.bounds)
self.addSubview_(subview)
view.setAutoresizingMask_(NSViewHeightSizable | NSViewWidthSizable)
def removeVoutSubview_(self, subview):
subview.removeFromSuperview()
objc.classAddMethods(NSView, addVoutSubview)
objc.classAddMethods(NSView, removeVoutSubview)
Note that this is all untested pseudocode, so no guarantees. If all goes well, then after this code is run, try the set_nsobject() function again and it should work. Hooray for Objective C having some of the dynamic dispatch of languages like Python. :)
In any case, I'd file a bug in the wx trac about not being able to create a wxWindow from a native handle cross-platform. It should definitely be possible, and it would make situations like this much easier. Then you could just create an NSView subclass in PyObjC, add those methods to it, and do wx.Window(myNSView) or some such to create the wx.Window. Resorting to black magic like this (which actually adds those methods to *all* NSViews) is, I think, far from ideal, and this would not have worked at all had we been dealing with C / C++.
Regards,
Kevin