Re: [Pyobjc-dev] applicationShouldOpenUntitledFile_
Brought to you by:
ronaldoussoren
From: Mitch C. <mit...@ea...> - 2003-02-02 07:20:45
|
On Saturday, February 1, 2003, at 11:00 PM, bb...@ma... wrote: > On Saturday, Feb 1, 2003, at 23:34 US/Eastern, Mitch Chapman wrote: >> I'm not sure if this is a bug or if I've screwed up my installation. >> >> Using the CVS PyObjC (updated about 1930 MST today), with its >> slightly-modified project templates (see below) installed under >> ~/Developer, >> I created a new Cocoa-Python Document-based application. Then in >> MyAppDelegate.py I changed the return value from YES to NO. When the >> application started it opened an Untitled document, despite the >> changed >> return value. >> >> I'm having similar problems convincing the application that >> openFile_ofType_ >> is successful -- I keep getting "Can't open file <pathname>" dialogs. >> >> Thanks for any hints. Please be gentle with the clue stick :) > > Very easy fix and not at all obvious. The problem is that there is no > way for the bridge to know that your implementation of the method > should return BOOL. So, you either have to tell the bridge that your > method returns a BOOL through the use of the objc.selector() function > or, better yet, declare that your class implements the informal > NSApplication delegate protocol. > > That is, change your class declaration to something like... > > class MyAppDelegate(NSObject, NSApplicationDelegate): > .... > [...] > It also works with the AutoBaseClass mechanism. > Hm... I think the project template already did this for me. (BTW thanks for including the project templates -- way cool.) Here's the relevant code, showing the class declaration provided by the template: # create ObjC classes as defined in MainMenu.nib NibClassBuilder.extractClasses("MainMenu") class MyAppDelegate(AutoBaseClass, NSApplicationDelegate): def applicationShouldOpenUntitledFile_(self, sender): # return NO if you don't want untitled document to be opened on app launch NSLog("applicationShouldOpenUntitledFile_") return NO The log message is showing up in the PB Run window, right about the time the unwanted Untitled document appears. Just for grins I tried replacing 'AutoBaseClass' with 'NSObject', but the result was the same. The declaration for the selector in AppKit/__init__.py looks okay, but I'm new at reading Objective-C method signatures. -- Mitch |