[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

RubyCocoa Sheets - help anyone?

Tim Perrett

5/5/2007 1:47:00 PM

Hey Guys

Just wondered if somone could help me with using modal sheets in
RubyCocoa - I think I am nearly there but its one method paramater that
is sucuppering me.... In the apple tutorial here is the code:


- (void)showCustomSheet: (NSWindow *)window

// User has asked to see the custom display. Display it.
{
if (!myCustomSheet)
//Check the myCustomSheet instance variable to make sure the custom
sheet does not already exist.
[NSBundle loadNibNamed: @"MyCustomSheet" owner: self];

[NSApp beginSheet: myCustomSheet
modalForWindow: window
modalDelegate: self
didEndSelector:
@selector(didEndSheet:returnCode:contextInfo:)
contextInfo: nil];

// Sheet is up here.
// Return processing to the event loop
}



So I have translated this into

def showConnectionSheet(window)
NSBundle.loadNibNamed_owner('Connection', self)
NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo(@connection,
self.window, nil, nil, nil)
end


But its the didEndSelector paramater that I do not know what to put in?
Can anyone help me?

Cheers

Tim

--
Posted via http://www.ruby-....

32 Answers

Jacob Burkhart

5/5/2007 3:02:00 PM

0

try NSSelectorFromString

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSSelector...

On 5/5/07, Tim Perrett <freestyle_kayaker@hotmail.com> wrote:
> Hey Guys
>
> Just wondered if somone could help me with using modal sheets in
> RubyCocoa - I think I am nearly there but its one method paramater that
> is sucuppering me.... In the apple tutorial here is the code:
>
>
> - (void)showCustomSheet: (NSWindow *)window
>
> // User has asked to see the custom display. Display it.
> {
> if (!myCustomSheet)
> //Check the myCustomSheet instance variable to make sure the custom
> sheet does not already exist.
> [NSBundle loadNibNamed: @"MyCustomSheet" owner: self];
>
> [NSApp beginSheet: myCustomSheet
> modalForWindow: window
> modalDelegate: self
> didEndSelector:
> @selector(didEndSheet:returnCode:contextInfo:)
> contextInfo: nil];
>
> // Sheet is up here.
> // Return processing to the event loop
> }
>
>
>
> So I have translated this into
>
> def showConnectionSheet(window)
> NSBundle.loadNibNamed_owner('Connection', self)
> NSApp.beginSheet_modalForWindow_modalDelegate_didEndSelector_contextInfo(@connection,
> self.window, nil, nil, nil)
> end
>
>
> But its the didEndSelector paramater that I do not know what to put in?
> Can anyone help me?
>
> Cheers
>
> Tim
>
> --
> Posted via http://www.ruby-....
>
>

Tim Perrett

5/5/2007 3:42:00 PM

0

Jacob Burkhart wrote:
> try NSSelectorFromString
>
> http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSSelector...

Hey Jacob

Excuse my ignorence but I am not sure how that would help me? I dont
actually understand what the
@selector(didEndSheet:returnCode:contextInfo:) code is actually doing -
could you perhaps explain? If I can understand what it does i should be
able to translate it hopefully.

Cheers

Tim

--
Posted via http://www.ruby-....

Logan Capaldo

5/5/2007 3:56:00 PM

0

On 5/5/07, Tim Perrett <freestyle_kayaker@hotmail.com> wrote:
> Jacob Burkhart wrote:
> > try NSSelectorFromString
> >
> > http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSSelector...
>
> Hey Jacob
>
> Excuse my ignorence but I am not sure how that would help me? I dont
> actually understand what the
> @selector(didEndSheet:returnCode:contextInfo:) code is actually doing -
> could you perhaps explain? If I can understand what it does i should be
> able to translate it hopefully.
>
@selector is a way of reifying a method name. it's a bit like using
:a_method_name in ruby or method(:method_name). Basically the sheet
wants the name of a method to run when the sheet is done interacting
with the user.
> Cheers
>
> Tim
>
> --
> Posted via http://www.ruby-....
>
>

John Joyce

5/5/2007 3:59:00 PM

0


On May 6, 2007, at 12:41 AM, Tim Perrett wrote:

> Jacob Burkhart wrote:
>> try NSSelectorFromString
>>
>> http://developer.apple.com/documentation/Cocoa/...
>> Foundation/Miscellaneous/Foundation_Functions/Reference/
>> reference.html#//apple_ref/c/func/NSSelectorFromString
>
> Hey Jacob
>
> Excuse my ignorence but I am not sure how that would help me? I dont
> actually understand what the
> @selector(didEndSheet:returnCode:contextInfo:) code is actually
> doing -
> could you perhaps explain? If I can understand what it does i
> should be
> able to translate it hopefully.
>
> Cheers
>
> Tim
>
> --
> Posted via http://www.ruby-....
>
For Cocoa info you might try the CocoaDev list.
http://lists...
RubyCocoa is Ruby, but the references on Cocoa are all in Objective-C
and yes they can be a bit vague. It's a huge framework.

Tim Perrett

5/5/2007 4:25:00 PM

0

Ok cool, that makes sense, so I would need to define a sheet method that
runs just before the sheet is going to close? Its a callback for the
sheet effectivly then.

I have tried instansiating both NSSelector and NSSelectorFromString, but
no luck. I have tried instansiating them in a number of ways:

NSSelectorFromString.alloc.init('connectionSheetDidEnd')
NSSelector('connectionSheetDidEnd').alloc.init

and so on...

It complains it does not like the NSSelectorFromString and thinks it is
an uninitilized constant?

Cheers

Tim

--
Posted via http://www.ruby-....

Logan Capaldo

5/5/2007 5:53:00 PM

0

On 5/5/07, Tim Perrett <freestyle_kayaker@hotmail.com> wrote:
> Ok cool, that makes sense, so I would need to define a sheet method that
> runs just before the sheet is going to close? Its a callback for the
> sheet effectivly then.
>
> I have tried instansiating both NSSelector and NSSelectorFromString, but
> no luck. I have tried instansiating them in a number of ways:
>
> NSSelectorFromString.alloc.init('connectionSheetDidEnd')
> NSSelector('connectionSheetDidEnd').alloc.init
>
> and so on...
>
> It complains it does not like the NSSelectorFromString and thinks it is
> an uninitilized constant?
>
IIRC NSSelectorFromString is a good old fashioned C function, not a
class. *checks to be sure*
Yep: http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSSelector...

> Cheers
>
> Tim
>
> --
> Posted via http://www.ruby-....
>
>

Tim Perrett

5/5/2007 6:20:00 PM

0

>>
> IIRC NSSelectorFromString is a good old fashioned C function, not a
> class. *checks to be sure*
> Yep:

So if its a C function, what does that mean for me using RubyCocoa? its
in the foundation framework so i would have thought I could use it with
the ruby bridge?

Thanks

Tim

--
Posted via http://www.ruby-....

John Joyce

5/5/2007 6:35:00 PM

0


On May 6, 2007, at 3:20 AM, Tim Perrett wrote:

>>>
>> IIRC NSSelectorFromString is a good old fashioned C function, not a
>> class. *checks to be sure*
>> Yep:
>
> So if its a C function, what does that mean for me using RubyCocoa?
> its
> in the foundation framework so i would have thought I could use it
> with
> the ruby bridge?
>
> Thanks
>
> Tim
>
> --
> Posted via http://www.ruby-....
>
That's not necessarily a problem.
Remember that Cocoa's main language is Objective-C which is a strict
super-set of C. Valid C is valid Objective-C.
RubyCocoa is a bridge to Cocoa.
I haven't used it myself. Cocoa is so big already with lots of vague
docs. It's going to be tough but fun going with RubyCocoa perhaps.
You might want to get the Hillegass book on Cocoa first if you
haven't got it already. If you know what's going on in Cocoa with Obj-
C, then Ruby Cocoa will be a lot easier.

Sherm Pendley

5/5/2007 9:00:00 PM

0

Tim Perrett <freestyle_kayaker@hotmail.com> writes:

>>>
>> IIRC NSSelectorFromString is a good old fashioned C function, not a
>> class. *checks to be sure*
>> Yep:
>
> So if its a C function, what does that mean for me using RubyCocoa? its
> in the foundation framework so i would have thought I could use it with
> the ruby bridge?

Okay, two things of note here:

First, it's quite possible that you could pass a plain string, and RubyCocoa
will call NSSelectorFromString() for you. I'm not a RubyCocoa pro by any
stretch, but that's how my CamelBones Perl/Cocoa bridge works; selectors are
just plain old strings in Perl.

Second, you'll need to pass the *full* name of the selector, not just the
part before the first argument - i.e. "didEndSheet:returnCode:contextInfo:".

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://...
Cocoa programming in Perl: http://camelbones.sourc...

Tim Perrett

5/6/2007 10:16:00 AM

0

> Second, you'll need to pass the *full* name of the selector, not just
> the
> part before the first argument - i.e.
> "didEndSheet:returnCode:contextInfo:".

So what your saying in effect is that although im writing in Ruby,
because its a bridge I have to pass the whole ObjC method signiture?

so if my method was:

def connectionSheetDidEnd(returnCode, contextInfo)
# code here...
end

I would then have to pass in
'connectionSheetDidEnd:returnCode:contextInfo'? Is that how it works or
am I such a newbie at this i've totally missed the point!? lol

Cheers

Tim

--
Posted via http://www.ruby-....