Pull requests

#2 Declined
Repository
tito
Branch
macosx-openfile
Repository
pygame
Branch
default

Add support for MacOSX OpenFile

Author
  1. Mathieu Virbel
Reviewers
Description

On MacOSX, when you try to open a file with an application, the file is not appended to the argv as others platform. The NSApplication delegate have a method named OpenFile, that is called by macosx to open a file in your application.

SDL 1.2 have a trick to append the filename to argv only if the app is not started yet, otherwise, the openfile is refused. With python, sys.argv are already set, and pygame don't even use sdlmain. So using the same approach would just not work.

SDL 1.3 have implemented a new SDLDropEvent, with appropriate structure changes in SDL_Event.

So i'm proposing a similar approach for pygame, using SDL_UserEvent. The usercode is set to 0x1000 (dunno where to put that constant), and the event have a "filename" attribute. You can now do in your main loop:

event = pygame.event.get_event()
if event.type == pygame.USEREVENT and event.code == 0x1000:
    print 'MacOSX want to open', event.filename
  • Learn about pull requests

Comments (0)