from objc import YES, NO, IBOutlet, IBAction
from Foundation import *
from AppKit import *
'''
a great deal of work is done in the nib/xib file.
it has the window and button and the menu that is set as
the status item. each menu item is wired either to a method
below or one in the first responder.
'''
class xAppDelegate(NSObject):
statusBar = None # holds our NSStatusBar
mStatusMenu = None # we store our status bar menu item here
mbImage = None # the image that will be our initial status item
redImage = None # an alternate status item
statusSub = objc.IBOutlet() # the menu that will be attached to the status bar item
prefsWindow = objc.IBOutlet() # the mock "prefs" window
button = objc.IBOutlet() # button in the mock "prefs" window that will turn status item red
# show "preferences" - called from menu item
@IBAction
def editPreferences_(self, sender):
self.prefsWindow.makeKeyAndOrderFront_(sender)
NSLog("Editing Preferences")
# returns our status bar icon to the starting image
@IBAction
def makeItNormal_(self, sender):
self.mStatusMenu.setImage_(self.mbImage)
NSLog("making it normal")
# turns our status bar icon to all red - called from button press
@IBAction
def makeItRed_(self, sender):
self.mStatusMenu.setImage_(self.redImage)
NSLog("making it normal")
# when we load the nib, get the images as well
def awakeFromNib(self):
self.mbImage = NSImage.imageNamed_("image.jpg")
self.redImage = NSImage.imageNamed_("red.jpg")
# we wired up the "Quit" item in our status bar menu to "terminate:" in the first responder
# this gets called when we really are going down
def applicationWillTerminate_(self, notification):
NSLog("We're going down")
# when the app instantiates our class, set the menu bar
def applicationDidFinishLaunching_(self, sender):
statusBar = NSStatusBar.systemStatusBar() # grabs the system status bar
# we may change the status bar item to a larger image, so variable length
self.mStatusMenu = statusBar.statusItemWithLength_(NSVariableStatusItemLength)
self.mStatusMenu.setImage_(self.mbImage) # set the initial image
self.mStatusMenu.setHighlightMode_(True) # we want visual feedback when clicked
#self.mStatusMenu.setTitle_("Status Menu") # if you uncomment this, you get a "word" menu vs image menu
self.mStatusMenu.setMenu_(self.statusSub) # sets the menu from the NIB
The source code is commented fairly well, but upon launch, the awakeFromNib and applicationDidFinishLaunching methods will be called and you should be able to follow what is happening. As the code states, a great deal of work is done in the nib/xib file where everything is wired up:

