Hello
You may explore the following sample code in pyobjc as a proof of concept.
Closing window 2 will open window 1 and closing window 1 will open window 2. Closing window 3 (status window at bottom) will quit the application.
Briefly tested with pyobjc 2.2b3 and python 2.6.1 under OS X 10.6.8.
#!/usr/bin/python
# coding: utf-8
#
# NSWindow: close to swich window
#
from AppKit import *
class AppDelegate(NSObject):
def init(self):
self = super(AppDelegate, self).init()
self.win1 = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
NSMakeRect(0, 0, 600, 300),
NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask | NSResizableWindowMask,
NSBackingStoreBuffered,
False)
self.win1.setLevel_(NSNormalWindowLevel)
self.win1.setTitle_('window 1 (close to open window 2)')
self.win1.center()
self.win1.setDelegate_(self)
self.win2 = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
NSMakeRect(0, 0, 500, 400),
NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask | NSResizableWindowMask,
NSBackingStoreBuffered,
False)
self.win2.setLevel_(NSNormalWindowLevel)
self.win2.setTitle_('window 2 (close to open window 1)')
self.win2.center()
self.win2.setDelegate_(self)
self.win3 = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
NSMakeRect(0, 0, 400, 50),
NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask | NSResizableWindowMask,
NSBackingStoreBuffered,
False)
self.win3.setLevel_(NSStatusWindowLevel)
self.win3.setTitle_('status window (close to quit)')
self.win3.setDelegate_(self)
return self
def applicationDidFinishLaunching_(self, notif):
try:
NSApp.activateIgnoringOtherApps_(True)
self.win2.orderFront_(self)
self.win3.orderFront_(self)
except:
NSApp.terminate_(self)
raise
def applicationShouldTerminate_(self, sender):
return NSTerminateNow
def windowShouldClose_(self, sender):
if sender == self.win1:
sender.orderOut_(self)
self.win2.makeKeyAndOrderFront_(self)
return False
elif sender == self.win2:
sender.orderOut_(self)
self.win1.makeKeyAndOrderFront_(self)
return False
elif sender == self.win3:
NSApp.terminate_(self)
return True
else:
return True
def main():
app = NSApplication.sharedApplication()
delegate = AppDelegate.alloc().init()
app.setDelegate_(delegate)
app.run()
main()
Good luck,
H