Thread: [Pyobjc-dev] Returning BOOLs to Cocoa
Brought to you by:
ronaldoussoren
From: Bob S. <rsw...@tr...> - 2003-07-22 16:31:41
|
I seem to be missing something about BOOLs returned from python members called for Cocoa delegates. :-( I implemented a Cocoa delegate for my window to support windowShouldClose_( ) since I need to do some checking of user input before I allow the window to close. However, no matter what I return, the window always closes. Originally, I just used: return 0 but I also tried: return objc.NO I added a print statement for when the code returns objc.NO and it printed: returning FALSE What is the proper value to return so that Cocoa knows I don't want it to go on? Thanks! Bob Swerdlow COO Transpose rsw...@tr... 207-781-8284 http://www.transpose.com ---------------------------------- Fight Spam! Add this link to your signature (as I did): http://wecanstopspam.org Click through to find out more. ---------------------------------- |
From: Ronald O. <ous...@ci...> - 2003-07-22 17:57:42
|
On Tuesday, 22 July, 2003, at 18:31, Bob Swerdlow wrote: > I seem to be missing something about BOOLs returned from python members > called for Cocoa delegates. :-( > > I implemented a Cocoa delegate for my window to support > windowShouldClose_( ) since I need to do some checking of user input > before > I allow the window to close. However, no matter what I return, the > window > always closes. > > Originally, I just used: > return 0 > but I also tried: > return objc.NO > > I added a print statement for when the code returns objc.NO and it > printed: > returning FALSE > > What is the proper value to return so that Cocoa knows I don't want it > to go > on? Returninging 0, False or objc.NO should work. Are you using PyObjC 1.0b1? If you're using the 0.9 release, you have to tell the bridge that you intent implement a window delegate. I added 'self.tableView.window().addDelegate_(self)' in 'awakeFromNib' and the following method to the TableView example and that works as expected. def windowShouldClose_(self, sender): """ Window won't close """ print "Should Close?" return 0 Ronald |
From: Bob S. <rsw...@tr...> - 2003-07-22 18:38:25
|
Ronald - We are using 0.9 and hope to release soon, so I haven't wanted to upgrade to 1.0b1 just yet. However, when I add the call as you describe, Python tells me "No attribute addDelegate_". Is there some module I need to include? Thanks for your help. - Bob ----- Original Message ----- From: "Ronald Oussoren" <ous...@ci...> To: "Bob Swerdlow" <rsw...@tr...> Cc: <pyo...@li...> Sent: Tuesday, July 22, 2003 1:56 PM Subject: Re: [Pyobjc-dev] Returning BOOLs to Cocoa > > On Tuesday, 22 July, 2003, at 18:31, Bob Swerdlow wrote: > > > I seem to be missing something about BOOLs returned from python members > > called for Cocoa delegates. :-( > > > > I implemented a Cocoa delegate for my window to support > > windowShouldClose_( ) since I need to do some checking of user input > > before > > I allow the window to close. However, no matter what I return, the > > window > > always closes. > > > > Originally, I just used: > > return 0 > > but I also tried: > > return objc.NO > > > > I added a print statement for when the code returns objc.NO and it > > printed: > > returning FALSE > > > > What is the proper value to return so that Cocoa knows I don't want it > > to go > > on? > > Returninging 0, False or objc.NO should work. Are you using PyObjC > 1.0b1? If you're using the 0.9 release, you have to tell the bridge > that you intent implement a window delegate. > > I added 'self.tableView.window().addDelegate_(self)' in 'awakeFromNib' > and the following method to the TableView example and that works as > expected. > > def windowShouldClose_(self, sender): > """ Window won't close """ > print "Should Close?" > return 0 > > > Ronald > > > > ------------------------------------------------------- > This SF.net email is sponsored by: VM Ware > With VMware you can run multiple operating systems on a single machine. > WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the > same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > > |
From: Ronald O. <ous...@ci...> - 2003-07-22 19:42:12
|
On Tuesday, 22 July, 2003, at 20:38, Bob Swerdlow wrote: > Ronald - > > We are using 0.9 and hope to release soon, so I haven't wanted to > upgrade to > 1.0b1 just yet. However, when I add the call as you describe, Python > tells > me "No attribute addDelegate_". Is there some module I need to > include? The method is called setDelegate_, sorry about that. The other thing you'll have to do is multiple inherit the delegate from NSWindowDelegate (should be in AppKit), e.g. 'class MyClass (AutoBaseClass, NSWindowDelegate)'. PyObjC 0.9 was the last release where this was necessary. We then came to our senses and automaticly detected which protocols you're implementing :-) Ronald |
From: Bob S. <rsw...@tr...> - 2003-07-22 21:27:38
|
I hate to be a pain, but AppKit does not seem to include "NSWIndowDelegate" - get an ImportError: cannot find name NSWindowDelegate. I can call setDelegate_ without the multiple inheritence and there is no error, but the delegate functions don't respond. :-( ----- Original Message ----- From: "Ronald Oussoren" <ous...@ci...> To: "Bob Swerdlow" <rsw...@tr...> Cc: <pyo...@li...> Sent: Tuesday, July 22, 2003 3:41 PM Subject: Re: [Pyobjc-dev] Returning BOOLs to Cocoa > > On Tuesday, 22 July, 2003, at 20:38, Bob Swerdlow wrote: > > > Ronald - > > > > We are using 0.9 and hope to release soon, so I haven't wanted to > > upgrade to > > 1.0b1 just yet. However, when I add the call as you describe, Python > > tells > > me "No attribute addDelegate_". Is there some module I need to > > include? > > The method is called setDelegate_, sorry about that. The other thing > you'll > have to do is multiple inherit the delegate from NSWindowDelegate > (should be in AppKit), e.g. 'class MyClass (AutoBaseClass, > NSWindowDelegate)'. > > PyObjC 0.9 was the last release where this was necessary. We then came > to > our senses and automaticly detected which protocols you're implementing > :-) > > Ronald > > > > ------------------------------------------------------- > This SF.net email is sponsored by: VM Ware > With VMware you can run multiple operating systems on a single machine. > WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the > same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > > |
From: Ronald O. <ous...@ci...> - 2003-07-23 05:45:01
|
On Tuesday, 22 July, 2003, at 23:27, Bob Swerdlow wrote: > I hate to be a pain, but AppKit does not seem to include > "NSWIndowDelegate" - get an ImportError: cannot find name > NSWindowDelegate. > I can call setDelegate_ without the multiple inheritence and there is > no > error, but the delegate functions don't respond. :-( I should have checked this in a 0.9 tree, 0.9 doesn't even include a definition of this protocol. That leaves us one alternative: even more explicit markup. Add 'windowShouldClose_ = objc.selector(windowShouldClose_, signature="c@:@")' just below the definition of the method. This will tell the bridge that this method returns a boolean instead of an object. class MyDelegate (AutoBaseClass): # .... def windowShouldClose_(self, sender): return 0 windowShouldClose = objc.selector(windowShouldClose, signature="c@:@") Another thing that will probably work: return None if the window shouldn't close and any other value if it should. Ronald > > > ----- Original Message ----- > From: "Ronald Oussoren" <ous...@ci...> > To: "Bob Swerdlow" <rsw...@tr...> > Cc: <pyo...@li...> > Sent: Tuesday, July 22, 2003 3:41 PM > Subject: Re: [Pyobjc-dev] Returning BOOLs to Cocoa > > >> >> On Tuesday, 22 July, 2003, at 20:38, Bob Swerdlow wrote: >> >>> Ronald - >>> >>> We are using 0.9 and hope to release soon, so I haven't wanted to >>> upgrade to >>> 1.0b1 just yet. However, when I add the call as you describe, Python >>> tells >>> me "No attribute addDelegate_". Is there some module I need to >>> include? >> >> The method is called setDelegate_, sorry about that. The other thing >> you'll >> have to do is multiple inherit the delegate from NSWindowDelegate >> (should be in AppKit), e.g. 'class MyClass (AutoBaseClass, >> NSWindowDelegate)'. >> >> PyObjC 0.9 was the last release where this was necessary. We then came >> to >> our senses and automaticly detected which protocols you're >> implementing >> :-) >> >> Ronald >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: VM Ware >> With VMware you can run multiple operating systems on a single >> machine. >> WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at >> the >> same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 >> _______________________________________________ >> Pyobjc-dev mailing list >> Pyo...@li... >> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >> >> > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: VM Ware > With VMware you can run multiple operating systems on a single machine. > WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the > same time. Free trial click here: http://www.vmware.com/wl/offer/345/0 > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > |