On Mon, Nov 21, 2011 at 7:39 PM, Tristam MacDonald <[email protected]>wrote:

> I can't seem to get pypy to pickup keyboard events - the pyglet window
> isn't managing to take focus away from the terminal window. The fix for
> this is to run from within an App bundle (or pretend to, as the system
> 'pythonw' does), but that part of my original Cocoa port doesn't seem to
> have survived the development process.
>

Aha! I finally found the post-Snow Leopard solution to this problem, in the
form of the little-known [NSApplication setActivationPolicy:
NSApplicationActivationPolicyRegular<http://developer.apple.com/library/mac/documentation/AppKit/Reference/NSRunningApplication_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSApplicationActivationPolicyRegular>]
method.

This method is unavailable pre-Snow Leopard. Is a Cocoa backend pre-Snow
Leopard possible or desirable? Do we need to special case this for older OS
versions?

Simplistic patch against the evilphillip-cocoa-ctypes repository is as
follows:

========================================================
diff -r acee3bdb3b9d pyglet/app/cocoa.py
--- a/pyglet/app/cocoa.py Mon Nov 21 19:28:22 2011 -0500
+++ b/pyglet/app/cocoa.py Tue Nov 22 01:05:16 2011 -0500
@@ -76,6 +76,7 @@
         # Create an autorelease pool for menu creation and finishLaunching
         self.pool = alloc_init('NSAutoreleasePool')
         create_menu()
+        send_message(self.NSApp, 'setActivationPolicy:', 0)
         send_message(self.NSApp, 'finishLaunching')
         send_message(self.NSApp, 'activateIgnoringOtherApps:', True)
         #send_message(self.pool, 'drain')
========================================================

-- 
Tristam MacDonald
System Administrator, Suffolk University Math & CS Department
http://swiftcoder.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to