librelist archives

« back to archive

Code does not wait for button to be pressed

Code does not wait for button to be pressed

From:
Roald
Date:
2013-07-11 @ 01:06
This does not seem to work. It presents me with both the buttons at the 
very start of the application. It should draw the other button only 
after the first button has been pressed.
However all the other lines within the /btn = button("OK") /block waits 
for the button to be clicked and thus works correctly.
What's going on?
What am I doing wrong here?

    Shoes.app do
       firstStack = stack(:margin => 6) do
         @greeting = para "A simple ToDo app for you!"
         @askName = para "What's your name, bud?"
         @name = edit_line
         btn = button("OK").click do
                 @userName = @name.text.capitalize /# Because the
    edit_line is going to be removed in the next line/
                 @askName.remove; @name.remove; btn.remove
                 @greeting.replace "A simple ToDo app for #{@userName}!"
                 $showMainWindow = true /# This line loads at the
    beginning  without the button being clicked/
             end
         end

         if $showMainWindow == true /  # For some reason ( if
    $showMainWindow ) does not work, any ideas why?/
    /# Creating a new stack to s//how a new window//! With a button,
    which is a success/
             secondStack = stack(:margin => 6) do
                 clickMe = button("OK").click { alert "Yes! This is
    working." }
    /# I want to have the second part of my app here/
             end
         end

    end   # Shoes.app


Thanks,
Roald



Re: [shoes] Code does not wait for button to be pressed

From:
ashbb
Date:
2013-07-11 @ 12:43
Hi Roald,

> For some reason ( if $showMainWindow ) does not work, any ideas why?
In order to work the if statement as you expect, you have to add a loop to
check it repeatedly.

Try out the following.

      a = animate do
        if $showMainWindow == true
          secondStack = stack(:margin => 6) do
            clickMe = button("OK").click { alert "Yes! This is working." }
          end
          a.stop
        end
      end

BTW, if it's okay to revise your code more Shoes-ish style, how about this
one? ;-)

Shoes.app do
  greeting = para "A simple ToDo app for you!", margin: 6
  slot = stack margin: 6 do
    para "What's your name, bud?"
    name = edit_line
    button "OK" do
      new_name = name.text.capitalize
      slot.clear do
        greeting.text = "A simple ToDo app for #{new_name}!"
        button("OK"){ alert "Yes! This is working." }
      end
    end
  end
end

Cheers,
ashbb