[Pythonmac-SIG] Trouble with NSWindowController

Valentino Volonghi dialtone at gmail.com
Sun Apr 10 07:23:04 CEST 2011


I'm using Mac OSX 1.6.8 with XCode4, built-in python and PyObjC and I'm trying to use NSWindowController.

My application is an agent application (no dock, no menu, only a statusbar item with menu).

When somebody presses "preferences" from the menu I bring up a preferences window located in a separate nib file named "Preferences.xib".

At the bottom of this email is the code I'm referring to.

My problem is that NSWindowController.window() always returns None.
Regardless if in InterfaceBuilder I've setup an object that points to PrefsController with the proper outlets and such.

self.window seems to be a native_selector and the call to it succeeds because isWindowLoaded works as expected and showWindow actually displays the window.

I thought it could be a problem with ownership but self.owner() is actually self.

Is there something I'm missing? I've read a couple of examples but they don't seem to be doing anything special about this, it just works.

In the delegate I have:

import preferences

class binderAppDelegate(NSObject):
    preferences = None

    def awakeFromNib(self):
        # snip some code
        self.preferences = preferences.PrefsController("Preferences")

    def openPreferences_(self, sender):
        NSLog("openPreferences was called.")

And preferences.py is this:

from Cocoa import *

class PrefsController(NSWindowController):
    def __new__(cls, nibFile):
        return cls.alloc().initWithWindowNibName_(nibFile)

    def display(self):
        NSLog("display got called %s" % (self.isWindowLoaded(),))
        window = self.window()
        NSLog("display got called %s" % (self.isWindowLoaded(),))

Valentino Volonghi aka Dialtone
Now Running MacOSX 10.6

More information about the Pythonmac-SIG mailing list