[Pythonmac-SIG] Opening a Cocoa window from a Python C extension
Michiel Jan Laurens de Hoon
mdehoon at ims.u-tokyo.ac.jp
Tue Feb 10 03:37:29 EST 2004
I am porting PyGist (a scientific plotting package for Python, mainly
written in C) to Mac OS X. PyGist was originally written for Linux/Unix
machines and was recently ported to Windows. For the Mac OS X port, I am
using Cocoa to create the graphics windows and calls to CoreGraphics for
the actual drawing. The graphics work fine, but there is still a problem
with Cocoa windows created from a Python C extension module.
I create my window with
window = [ [NSWindow alloc]
initWithContentRect: rect
styleMask: style
backing: NSBackingStoreBuffered
defer: NO];
and try to show the window with
[window orderFront: nil];
The window is displayed and everything seems to be working fine;
graphics are also drawn correctly. The window becomes the key window if
I click in it, however the previous key window also stays key, so I end
up with two key windows at the same time. In addition, cursor events are
not handled correctly (which I need for zooming and reading out
coordinate values).
I wrote a little test program to find out what is happening. It turns
out that the test program works correctly if it is located in a
directory test.app/Contents/MacOS/test. However, if I move the "test"
program to a different directory it shows the same problem as a window
created in the Python C extension, even though the test.app directory is
otherwise empty.
The problem may therefore be that the window that I am trying to open
should be somehow linked to the Terminal.app from which I am running
Python in order for it to be recognized as a bona fide window. Does
anybody know the right way to do this?
Many thanks in advance,
Michiel de Hoon, U Tokyo.
More information about the Pythonmac-SIG
mailing list