From: Dave H. <gr...@gr...> - 2006-01-20 20:49:56
|
I'm creating a handy way of doing alert sheets for a program, so that they'd work something like this: class Main < OSX::NSObject ib_outlet :window, def applicationDidFinishLaunching(something) myAlert = AlertMessage.alloc.init.display(@window, 'Quit already?', "This program just launched! Do you want to quit already?","OK","Cancel") if myAlert then @window.close end end Assume that the window's connected to "window" in InterfaceBuilder, et cetera. Unfortunately, there's one critical piece missing, and I'm mystified on how to get this part to work. The following code will run.... require 'osx/cocoa' class AlertMessage < OSX::NSObject include OSX def display(theWindow, messageTitle, messageText, defaultOption, altOption) p "Alert: " + messageTitle theAlert = NSAlert.alloc.init theAlert.addButtonWithTitle(defaultOption) theAlert.addButtonWithTitle(altOption) if altOption theAlert.setMessageText(messageTitle) theAlert.setInformativeText(messageText) someAnswer = theAlert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextIn fo(theWindow, self, 'alertDidEnd_returnCode_contextInfo', nil) p "Answer" p someAnswer return @theResponse end def alertDidEnd_returnCode_contextInfo(theAlert) return end end Unfortunately, I can't do anything but one-button messages, because I can't get the return code back from the NSAlert. The call to 'beginSheetModalForWindow...' looks like this in Objective-C: beginSheetModalForWindow:[someWindow window] modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil How exactly can I get a parameterized selector into this thing? In other words, how do I do @selector(alertDidEnd:returnCode:contextInfo:) in RubyCocoa? |
From: Jonathan P. <jp...@dc...> - 2006-01-20 21:12:09
|
On 20 Jan 2006, at 20:49, Dave Howell wrote: > def alertDidEnd_returnCode_contextInfo(theAlert) > return > end > > Unfortunately, I can't do anything but one-button messages, because > I can't get the return code back from the NSAlert. The call to > 'beginSheetModalForWindow...' looks like this in Objective-C: > > beginSheetModalForWindow:[someWindow window] > modalDelegate:self > didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) > contextInfo:nil > > How exactly can I get a parameterized selector into this thing? In > other words, how do I do > @selector(alertDidEnd:returnCode:contextInfo:) > in RubyCocoa? Is your callback method being called? Your ruby method: def alertDidEnd_returnCode_contextInfo(theAlert) doesn't have the right signature, because it's supposed to take three arguments: def alertDidEnd_returnCode_contextInfo(theAlert,code,context) Does using the 'code' argument there work? I think you can also use symbols for selectors (instead of strings) e.g., :alertDidEnd_returnCode_contextInfo. Don't think it makes any difference, just a matter of choice. Hope that helps, Jonathan |
From: Dave H. <gr...@gr...> - 2006-01-20 22:08:55
|
On Jan 20, 2006, at 13:11, Jonathan Paisley wrote: > On 20 Jan 2006, at 20:49, Dave Howell wrote: > >> def alertDidEnd_returnCode_contextInfo(theAlert) >> return >> end >> >> Unfortunately, I can't do anything but one-button messages, because I >> can't get the return code back from the NSAlert. The call to >> 'beginSheetModalForWindow...' looks like this in Objective-C: >> >> beginSheetModalForWindow:[someWindow window] >> modalDelegate:self >> didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) >> contextInfo:nil >> >> How exactly can I get a parameterized selector into this thing? In >> other words, how do I do >> @selector(alertDidEnd:returnCode:contextInfo:) >> in RubyCocoa? > > Is your callback method being called? Your ruby method: > > def alertDidEnd_returnCode_contextInfo(theAlert) > > doesn't have the right signature, because it's supposed to take three > arguments: > > def alertDidEnd_returnCode_contextInfo(theAlert,code,context) Not according to RubyCocoa. Like I said, the code as listed works "correctly." If I change my callback method to def alertDidEnd_returnCode_contextInfo(theAlert, returnCode, contextInfo) then the entire app blows apart: rb_main.rb:22: [BUG] Bus Error Any attempt to add a second parameter to the callback method causes that result. > Does using the 'code' argument there work? > > I think you can also use symbols for selectors (instead of strings) > e.g., :alertDidEnd_returnCode_contextInfo. Don't think it makes any > difference, just a matter of choice. Well, it's a string because I was trying to get the parameters to pass properly, like 'alertDidEnd_returnCode_contextInfo:returnCode:contextInfo" or "@selector(alertDidEnd:returnCode:contextInfo" But all such guesses failed one way or the other. |
From: Dave H. <gr...@gr...> - 2006-01-20 23:39:19
|
Whaddyaknow. I just ran across the same problem in a different context. @myTableView.setDoubleAction(no_known_way_to_set_this) setDoubleAction also requires a "selector", just like beginSheetModalForWindow. :/ |
From: Neil S. <ne...@ha...> - 2006-01-21 00:04:23
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dave Howell wrote: > Well, it's a string because I was trying to get the parameters to pass > properly, like > 'alertDidEnd_returnCode_contextInfo:returnCode:contextInfo" You want something like this def alertDidEnd_returnCode_contextInfo(alert, code, info) ... end ... selector = 'alertDidEnd:returnCode:contextInfo:' Note the colon at the end. - -- Neil Stevens - ne...@ha... "There is nothing patriotic about hating your country, or pretending that you can love your country but despise your government." -- William Jefferson Clinton -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) iD8DBQFD0XqKf7mnligQOmERAheqAJsFtqHcVSK2RjHPOrWdr36p9mdCLgCghyV8 0sktiNi2WkueAieNGL04Q+4= =2PGI -----END PGP SIGNATURE----- |
From: Dave H. <gr...@gr...> - 2006-01-21 10:24:45
|
On Jan 20, 2006, at 16:04, Neil Stevens wrote: > > You want something like this > > def alertDidEnd_returnCode_contextInfo(alert, code, info) > ... > end > > ... > selector = 'alertDidEnd:returnCode:contextInfo:' > > Note the colon at the end. And that was exactly the missing piece. Thanks! |