-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Window does not get focus on OS X with Python 3 #203
Comments
Original comment by Nick Monkman (Bitbucket: nmonkman, GitHub: nmonkman): Just wanted to mention that I ran into this issue as well. I got around it by installing the MacPorts version (py27-game) which is an earlier version (1.9.1_8). It only addressed the keyboard input issue...I have not tried the mouse yet. |
Original comment by hwmrocker (Bitbucket: hwmrocker, GitHub: hwmrocker): I have the same issue. I couldnt build the 1.9.1 release, i tried a lot of versions between 1.9.1 and the most recent version in the repo but I found no version that worked. The latest version that compiled was 3019:252da58b4 i used: I cannot use a different python version because my project depends on asyncio. It works perfectly under linux, this is probably a OS X specific issue. Please tell me what i could do to help. |
Original comment by Arve Seljebu (Bitbucket: arve0, GitHub: arve0): After some debugging, I found that I was only affected by this if inside a virtualenv. Installing pygame systemwide works fine on OS X 10.10.3 with python3, both from python.org or homebrew. If one can cope without all the SDL-features, one can get pygame working inside virtualenv by using pygame_sdl2. More detail is found in this thread: |
Original comment by Rob Collins (Bitbucket: agiledata, GitHub: agiledata): We have found a workaround, described in this thread. It means substituting the system Framework Python for the virtualenv one that can't handle windowing properly on a Mac. |
Original comment by Thomas Kluyver (Bitbucket: takluyver, GitHub: takluyver): Thanks @arve0 and @agiledata for investigating this. Is there any hope of fixing it within pygame? I'm not familiar with OSX, but it seems weird that a Python virtualenv can affect window management. If we don't know of a fix, is there a way we can detect it and warn/error about it? |
Original comment by René Dudfield (Bitbucket: illume, GitHub: illume): This is likely to do with which SDL was used inside different python environments. We likely need to redo the way this is handled on OSX. Since installing system wide Frameworks is really not a good idea in modern OSX (and probably never was). |
Original comment by Matthew Brett (Bitbucket: matthewbrett, GitHub: matthewbrett): I think this is the same issue as noticed by matplotlib : http://matplotlib.org/faq/virtualenv_faq.html#osx The problem is to do with the difference between framework and not-framework builds on OSX. |
Original comment by Thomas Kluyver (Bitbucket: takluyver, GitHub: takluyver): That's good to know. If it is the same and mpl hasn't fixed it, I suspect there's not much we can do other than documenting workarounds. The docs you linked to suggest that |
Original comment by Matthew Brett (Bitbucket: matthewbrett, GitHub: matthewbrett): Yes it does:
|
Original comment by Aleksandr Motsjonov (Bitbucket: soswow, GitHub: soswow): I have Python 3.5 conda environment. Installed pygame:
When run aliens (or anything else) console says:
And nothing opens up. When swipe see all the windows: I've also tried 1.9.2b12 version. didn't help. |
Original comment by Aleksandr Motsjonov (Bitbucket: soswow, GitHub: soswow): @takluyver yes, window is created, but when I select it I see it for a split-second and then I see my console again. So, no, I can't move a car. |
Original comment by Aleksandr Motsjonov (Bitbucket: soswow, GitHub: soswow): I've tried different example now. Since aliens closes itself too quickly. With other example I was able to get focus. Here is how:
|
Original comment by Chris Dugan (Bitbucket: duganc, GitHub: duganc): I tried @matthewbrett 's solution (adjusted for my game since the github download link doesn't work anymore) and OSX still doesn't give me focus of the window. Is there a documented best workaround yet for this? |
That workaround doesn't works everytime, venvdotapp works if i code something myself and import it in code, but it don't work if i want to try examples. Can we expect fix in soon future releases? Or we should wait for 2.0? |
AFAIK, we don't know how to fix it. Glyph understands it better than any of us appear to, and venvdotapp is his fix. @illume found that it seemed to work with SDL 2, so if that's consistent, pygame 2.0 ought to resolve it. |
I committed a fix in #415. If you Compile from source you can try it out.
Otherwise, it should be in pygame 1.9.4. |
Thanks @illume , I underestimated how much you knew about this. :-) |
I think you estimated it about right ;) |
Thanks a lot for work, @illume! But i think i should wait for 1.9.4, because after i installed it from source as you mentioned, it says that i am on 1.9.4.dev0. But my pygame window still can't get focus. |
@ExarKunFan sorry, I just merged the PR with the fix in. Would you mind trying it again? You'll probably need the -U upgrade flag for pip.
|
@illume Nice! Now it works like a charm! Thanks a lot! |
Thanks a lot @ExarKunFan for writing back. |
Sorry for the long delay; venvdotapp had a few bugs in it and I did a new release a little while ago which should have fixed many of them. Please go ahead and report bugs on it if you find more! |
For some reasons, the command OSX Sierra 10.12.5
|
I also have this problem. Installed pygame in an existing Anaconda virtual environment with Python 3.4 on Mac OS X 10.13.3:
(Cannot focus on pygame window. Keyboard input goes to terminal.) But using |
I also just struggled with this problem: mouse clicks going to pygame, but keypresses and mouse motion going to the window behind:
Based on my research, the way to solve this problem since 10.6 is to change the app [NSApp setActivationPolicy: NSApplicationActivationPolicyRegular] As explained in that doc the default policy for unbundled apps is Edit: If you install from AppKit import NSApplication
NSApplication.sharedApplication().setActivationPolicy_(0) ...which shows the app in the dock, puts the window in the foreground when it opens and fixes the input problems. (original workaround using ctypes to do the same thing) from ctypes import cdll, c_int, c_void_p, c_char_p
from ctypes.util import find_library
objc = cdll.LoadLibrary(find_library("objc"))
AppKit = cdll.LoadLibrary(find_library("AppKit"))
assert objc
assert AppKit
getClass = objc.objc_getRequiredClass
getClass.restype = c_void_p
getClass.argtypes = (c_char_p,)
registerName = objc.sel_registerName
registerName.restype = c_void_p
registerName.argtypes = (c_char_p,)
msgSend = objc.objc_msgSend
msgSend.restype = c_void_p
msgSend.argtypes = (c_void_p, c_void_p)
NSAutoreleasePool = getClass(b"NSAutoreleasePool")
pool = msgSend(NSAutoreleasePool, registerName(b"alloc"))
pool = msgSend(pool, registerName(b"init"))
assert pool
NSApplication = getClass(b"NSApplication")
app = msgSend(NSApplication, registerName(b"sharedApplication"))
assert app
msgSend.restype = c_int
msgSend.argtypes = (c_void_p, c_void_p, c_int)
# request regular activation
rc = msgSend(app, registerName(b"setActivationPolicy:"), 0)
assert rc
msgSend.argtypes = (c_void_p, c_void_p)
msgSend(pool, registerName(b"release")) |
Hellos, Note: this issue is closed, and has been fixed in git. You can either install via source, or wait for the 1.9.4 release. https://www.pygame.org/wiki/MacCompile#Installing%20from%20source%20with%20homebrew |
@ReblochonMasque Seems the full stack trace isn't there, so I can't see what the error was for you unfortunately. |
FYI:
Error: sdl not installed These need to be installed
to be able to do
For some reason pip was not able to execute the command before I installed these. I found the information here |
Hey there EDIT INITIAL POST
|
Originally reported by: Ian McCowan (Bitbucket: valrus, GitHub: valrus)
A pygame window created using the code below on OS X using the latest pygame source:
does not receive any keyboard input. It is not possible to trigger the "got here" message nor cause it to terminate using Escape; instead all keypresses show up in the terminal window from which the script was run. This happens even though the window appears to have focus.
Additionally, based on the mouse event handling, the window exhibits some combination of the incorrect mouse behavior described in these two issues:
#79/pygame-incompatible-with-osx-lion-trackpad
#163/no-mouse-move-events-unless-mouse-button
viz. all subsequent clicks register with the same position as the first one, and the only way to update its position is to click and drag to a new location.
The text was updated successfully, but these errors were encountered: