Reputation: 61
Once a button is created in Shoes, is it possible to change the text? I've tried modifying the :text key in the button [email protected] confirms the text is changed--but the button still shows the original text.
Upvotes: 3
Views: 807
Reputation: 19
I found a way of simulating changing the text of a button by replacing it with a new button with the same action as the old.
The button is first removed from its container (a stack or a flow) and then a new one is added. This new button will appear at the end of the container, so it may be necessary to have a stack or flow just for this button.
# Display 2 buttons, A and B. Initially button A has text "a".
# Pressing the top button, A, just shows the value of @ch (which is
# the text of the button) on the console.
# Pressing the second button appears to change the text of button A.
# It actually replaces it with a new button with the same action as the old.
Shoes.app do
def button_a_function
info("click! #{@ch}")
end
@ch = "a"
@the_flow = flow do
para "Button A, whose to be changed"
@b1 = button @ch do
button_a_function
end
end
flow do
para "Button B"
@b2 = button("Change it") {
@ch.succ!
@b1.remove
@b1 = @the_flow.button (@ch) {
button_a_function
}
}
end
end
Upvotes: 0
Reputation: 42192
A very old question, but there is a solution. You didn't mention your shoes color, so i use green. Green Shoes is based on GTK2, so you can use the methods of GTK2 if you extract the GTK2 object like this.
require 'green_shoes'
Shoes.app do
@btn = button('old text ') {|btn|alert('Hello, World!')}
button('Change!') {|btn|@btn.real.set_label("new")}
end
Upvotes: 0
Reputation: 23880
I haven't figured out how to change the text on the existing button. I suspect it just isn't supported as of yet. You could create a new button and replace the old one. Unfortunately, at least on Windows, removing a button mucks up all the click events. I haven't tried it on another platform, but maybe it'll work. Try something like this:
Shoes.app do
para 'This is some text.'
@btn = button 'a' do |btn|
alert 'Hello, World!'
end
para 'Blah blah blah'
button 'Change!' do |btn|
old = @btn
new_style = old.style.dup
txt = new_style[:text].next!
old.parent.before(old) do
@btn = button txt, new_style
end
old.remove #This messes up the click events on Windows.
end
end
Upvotes: 2