rubyshoes

How can I bind function with object in Ruby Shoes GUI?


How can I call addition only when I press enter and @e_ln1 is in focus? If I click enter while @e_ln2 is in focus, addition in @e_ln1 is also performed but I don't want it.

Shoes.app do

    @e_ln1 = edit_line(width: 150, height: 20)
    @e_ln2 = edit_line(width: 150, height: 20, left: 0, top: 60)

   keypress do |k|
        if k == "\n" 
            @e_ln1.text = @e_ln1.text.to_i + 1
        end
    end

end

Solution

  • in Shoes3.3.1 there is a finish event on edit_line

    Shoes.app do
        @e_ln1 = edit_line(width: 150, height: 25)
        @e_ln2 = edit_line(width: 150, height: 25, left: 0, top: 60)
    
        @e_ln1.finish = proc { @e_ln1.text = @e_ln1.text.to_i + 1 }
    end
    

    just hit enter in the edit_line of interest to trigger it