shoes / shoes-deprecated

Former repo for Shoes... see README for up to date locations!
http://shoesrb.com/
Other
1.15k stars 167 forks source link

Automatically initializing a Radio Button requires a timer (?) #167

Open JayTeeSF opened 12 years ago

JayTeeSF commented 12 years ago

Caveat: I've only been using Shoes for a few hours. But after a quick scan of the docs & source code I think this is a bug.

FYI: I'm using shoes policeman (0.r1739) [universal.x86_64-darwin11.1.0 Ruby1.9.1] ...on mac osx 10.6.8

The following fails: Shoes.app do radio_one = radio("group"); para "one" radio_two = radio("group"); para "two"

initialize the button(s):

radio_two.checked = false # just to be sure radio_one.checked = true

alert(radio_one.checked? ? "ok" : "failed") # fails end

By adding a button and manually clicking-it I got the radio button to update:

.... button = button("initialize radio buttons") do radio_one.checked = true alert(radio_one.checked? ? "ok" : "failed") # works end ....

So my current work-around is to use a timer:

.... timer(1) do radio_one.checked = true info(radio_one.checked? ? "ok" : "failed") # works end ....

steveklabnik commented 12 years ago

This is certainly strange behavior.

Can anyone else confirm on other platforms?

ccoupe commented 12 years ago

if you change the radio groups to symbols (from the manual)

radio_one = radio :group; para "one" radio_two = radio :group; para "two"

it works as expected. You version didn't put them in the same group.

JayTeeSF commented 12 years ago

nope; strings and symbols behave the same way (at least on my mbp running osx 10.6.8)

ccoupe commented 12 years ago

Hmm. I'm using Linux and modified your example slightly:

Shoes.app do radio_one = radio :group; para "one" radio_two = radio :group; para "two"

initialize the button(s):

radio_two.checked = false # just to be sure

radio_one.checked = true button "quit" do alert(radio_one.checked? ? "ok" : "failed") # fails exit end end

JayTeeSF commented 12 years ago

When I run shoes on ccoupe.rb it still fails initialize radio_one.

↪ cat ccoupe.rb Shoes.app do radio_one = radio :group; para "one" radio_two = radio :group; para "two"

initialize the button(s):

radio_two.checked = false # just to be sure

radio_one.checked = true button "quit" do alert(radio_one.checked? ? "ok" : "failed") # fails exit end end

ccoupe commented 12 years ago

We have a difference between Linux (correct) and OSX (apparently incorrect) and it seems to be the radio_one.checked = that fails on OSX. In ruby.c the function is 'shoes_check_set_checked_m'. On Gtk systems the code in the #ifdef is executed. For Windows and OSX it call 'shoes_check_set_check' (without the trail '-m') which will get you to cocoa.m and that as far as I can help.

JayTeeSF commented 12 years ago

thanks! ...I guess the next-step is to contrast that code with the code-path that executes when radio_one.checked= gets called from within the timer-block

ccoupe commented 12 years ago

Minor correction to my code reading. Linux/GTK manages it's radio grouped buttons. Windows and OSX have to "fake it" by running through the list of radio buttons in the group. That could explain why Jay's code needed the :symbol method on Linux instead of a string parameter. It's not timer that make things work, per se. I suspect that there have been changes in OSX widget handling timing by Apple OS upgrades. The Shoes method of radio and groups creation is not the typical Apple method (as I remember it from old). The group and the button is added w/o text until the para call which has to involve some deferred processing or callback.

ccoupe commented 12 years ago

Comparing native/gtk.c function 'shoes_native_radio' with the same function in cocoa.m and windows.c suggests that the group arg appears to me to be unused in OSX and Windows. That would be a serious bug.

ccoupe commented 12 years ago

Confirmed the problem on XP (SP2) and the misbehavior is interesting.

Revised test: Shoes.app do radio_one = radio :group; para "one" radio_two = radio :group; para "two" radio_one.checked = true button "verify" do alert(radio_one.checked? ? "ok" : "failed") # fails end end

When that script runs in XP, NO Buttons are visually selected. That's another bug for XP. When one button is pushed then the group visually sort of acts normally. Looks like _why never finished the Windows and OSX code for radios.

ashbb commented 12 years ago

Hi JayTeeSF and folks,

I confirmed the issue on my Windows 7 with Shoes 3.

Try out the following. I think it may be an alternative solution.

Shoes.app do
  radio_one = radio("group", checked: true); para "one"
  radio_two = radio("group"); para "two"
  start do
    alert(radio_one.checked? ? "ok" : "failed")
  end
end

ashbb

JayTeeSF commented 12 years ago

Nice; I switched from using a timer to a start block (in my original code) and it works. It's a much nicer work-around (IMO).

steveklabnik commented 12 years ago

Yep, and this shouldn't be too terrible to fix, either.