[MacRuby-devel] Checkbox state

Marinus van der Lugt lugt at xs4all.nl
Wed Jul 8 09:56:55 PDT 2009


Thanks John,

Yes the simple example works OK.
My controller looks like this:


class DisclaimerController < NSWindowController

    attr_accessor :showAgain

    def exitButtonAction(sender)
       NSLog("Disclaimer Window: exit button clicked")
    end

    def startButtonAction(sender)
       NSLog("Disclaimer Window: start button clicked")
    end

    def toggleShowAgainAction(sender)
       NSLog("Disclaimer Window: toggle checkbox clicked")
       p @showAgain.state
       p @showAgain.title
       active = (@showAgain.state == NSOnState)
       if (active) then
          NSLog("Disclaimer Window: toggle switched to Selected")
       else
          NSLog("Disclaimer Window: toggle switched to Unselected")
       end
    end

end


And the output looks like this:


2009-07-08 18:47:08.324 xxxx[610:10b] Disclaimer NIB loaded
2009-07-08 18:47:10.658 xxxx[610:10b] Disclaimer Window: toggle  
checkbox clicked
0
"Do not show this warning again."
2009-07-08 18:47:10.659 xxxx[610:10b] Disclaimer Window: toggle  
switched to Unselected
2009-07-08 18:47:11.570 xxxx[610:10b] Disclaimer Window: toggle  
checkbox clicked
0
"Do not show this warning again."
2009-07-08 18:47:11.571 xxxx[610:10b] Disclaimer Window: toggle  
switched to Unselected
2009-07-08 18:47:12.690 xxxx[610:10b] Disclaimer Window: toggle  
checkbox clicked


As you can see the "toggleShowAgainAction" is activated, and the  
checkbox is linked to "showAgain".
PS: The checkbox has the title "Do not show this warning again."

(Sometimes I wish I had chosen a different profession, VBG!)

Regards,
Rien.



On Jul 8, 2009, at 3:28, John Shea wrote:

> Hi Marinus / Rien,
>
> I just did a quick test, given a nib with window and a controller  
> ruby file.
>
> 1. I dragged a checkbox NSButton onto the window
> 2. i created an attr_accessor :check in my controller
> 3. I created a method called test_check in my controller:
>
>  def test_check(sender)
>    p @check.state
>  end
>
> 4. I linked @check and the test_check method to the checkbox
>
> And when i click on an off the checkbox the state toggles between 0  
> and 1.
>
> So I do not think it is an issue MacRuby - could you try something  
> simple like the above?
>
> How were you polling the check box state? That is: which method is  
> status = @myCheckbox.state in?
> Perhaps this method is not being called.
>
> Cheers,
> John
>
>
> On Jul 8, 2009, at 15:06 , Marinus van der Lugt wrote:
>
>> Hi All,
>>
>> First post, so a little bit about me: I am a SW engineer and have  
>> been one
>> for over 20 years, increadible as that may sound. I have programmed  
>> on the
>> Mac before in Ada95, Obj-C and Java (but I have had a pause of  
>> about 5
>> years from the Mac). Now that MacRuby seems to gain some foothold  
>> I'd like
>> to get back to the mac and make the jump from Obj-C to MacRuby.
>>
>> I work in Xcode, and have just started a new MacRuby Core-Data  
>> Application.
>>
>> The first goings look good, but in implementing my first window  
>> controller
>> I ran into a (little?) problem: I cannot get the state of a checkbox:
>>
>> status = @myCheckbox.state
>>
>> always returns a Fixnum with value 0. regardless of the visual
>> representation of the checkbox (i.e. selected or not)
>>
>> The checkbox should be mapped correctly because:
>>
>> myTitle = @myCheckbox.title
>>
>> does indeed give me the title I set in the IB.
>> I checked the archives but did not find any discussions about this.
>> There was something about checkboxes and hotcocoa, but I do not use  
>> hotcocoa.
>>
>> The best solution would be a simple stupid mistake on my part :-)
>>
>> Any takers?
>>
>> Regards,
>> Rien.
>>
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20090708/c3cfb997/attachment.html>


More information about the MacRuby-devel mailing list