1from Cocoa import *
2
3from MyWindowController import *
4
5class AppDelegate (NSObject):
6    myWindowController = objc.ivar()
7
8    @objc.IBAction
9    def newDocument_(self, sender):
10        if self.myWindowController is None:
11            self.myWindowController = MyWindowController.alloc().initWithWindowNibName_("TestWindow")
12
13        self.myWindowController.showWindow_(self)
14
15
16    def applicationDidFinishLaunching_(self, notification):
17        self.newDocument_(self)
18
19    def validateMenuItem_(self, theMenuItem):
20        enable = self.respondsToSelector_(theMenuItem.action())
21
22        # disable "New" if the window is already up
23        if theMenuItem.action() == 'newDocument:':
24            if self.myWindowController.window().isKeyWindow():
25                enable = False
26
27        return enable
28