views:

688

answers:

1

I have created a brand new project in XCode and have the following in my AppDelegate.py file:

from Foundation import *
from AppKit import *

class MyApplicationAppDelegate(NSObject):
    def applicationDidFinishLaunching_(self, sender):
     NSLog("Application did finish launching.")

     statusItem = NSStatusBar.systemStatusBar().statusItemWithLength_(NSVariableStatusItemLength)
     statusItem.setTitle_(u"12%")
     statusItem.setHighlightMode_(TRUE)
     statusItem.setEnabled_(TRUE)

However, when I launch the application no status bar item shows up. All the other code in main.py and main.m is default.

+3  A: 

I had to do this to make it work:

  1. Open MainMenu.xib. Make sure the class of the app delegate is MyApplicationAppDelegate. I'm not sure if you will have to do this, but I did. It was wrong and so the app delegate never got called in the first place.

  2. Add statusItem.retain() because it gets autoreleased right away.

Chris Lundie
It was the statusItem.retain() that did it. Thanks!
DavidM
Interesting, because the PyObjC documentation says that one does not need to do manual memory management at all. When do you release statusItem?
Yi