Re: [Gtk-osx-users] Notes on handling Apple events with gtk_osxapplication and PyGTK



On Aug 25, 2010, at 7:42 PM, Richard Procter wrote:

> Hi everyone,
> 
> I thought I'd share my experiences in listening for OS X events with  
> PyGTK and gtk_osxapplication.
> 
> - When OS X starts a new application process in response to the user  
> clicking on an associated document file,
>   there is a race condition when listening for 'Open Documents' events.
> 
>   My application had been calling OSXApplication.ready() just before  
> gtk.main(), having set up its menus, etc.
>   However my callback on the OSXApplication::NSApplicationOpenFile  
> signal was not invoked unless I shifted this
>   call right up to the start of my main python file. I thought this  
> might mess with the menubar synching but it
>   seems to work ok.
> 
> - If there are multiple instances of the process, only the oldest  
> remaining version emits the
>   OSXApplication::NSApplicationOpenFile signal, irrespective of the  
> signal handler boolean return value.
> 
> cheers,
> Richard.
> 
> I was testing this via
> 
> #!/bin/python
> import gtk_osxapplication
> macapp = gtk_osxapplication.OSXApplication()
> 
> def foo(*args):
>     print "Callback!", args
>     return True
> 
> h = macapp.connect("NSApplicationOpenFile", foo)
> macapp.ready()
> 
> [...]
> 
> Versions: ige-mac-integration version 0.9.4, python 2.5.2, OS X  
> 10.5.3, PyGTK 2.16.0, GTK 2.18.8.
> 


That doesn't sound like a race condition (which usually means that two threads are writing to a shared resource that lacks mutex or semaphore protection). Rather, it sounds like the notification handler isn't turned on until NSApplication::FinshedLaunching is called, and that OSX doesn't queue the notification until then. I'll have to dig into that a bit, but ISTM the event loop is going to be required for properly handling the notification. 

I don't understand what you mean by "multiple instances of the process". That's not possible. Do you mean that if you have multiple copies of the program running, only the first-launched gets the notification? That's the way OSX works. It expects there to be only one running instance of a program, which may have open multiple documents. 

Regards,
John Ralls





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]