Click Event in Shoes

When I click on a slot, I change the contents of the slot to provide feedback to the user, and then call the code, which takes a few seconds. However, changes to the slot are not displayed until the "slow" process is completed. Is there a way I can make the rendering happen before the "slow" code is executed.

In the following example, the user never sees "Processing, please wait ..."

class MyTest < Shoes

  url '/', :index
  url '/result', :result

  def index
    stack do
      my_button=flow do
        image './assets/trees.jpg'
        para 'Process Image'
      end
      my_button.click do
        my_button.contents[0].hide
        my_button.contents[1].text="Processing, please wait ..."
        sleep(4) # Simulate slow process

        visit '/result'
      end
    end
  end
  def result
    stack do
      para "Finished processing"
    end
  end
end

Shoes.app

Looking through the source code for Shoes in ruby.c or canvas.c, there are links to redrawing or paint. Can they be called out of shoes?

Thank you in advance

+3
source share
2 answers

, :

def doStuff()
  sleep(4) # Simulate slow process

  visit '/result'
end

timer :

my_button.click do 
  my_button.contents[0].hide
  my_button.contents[1].text="Processing, please wait ..."

  timer(0) { doStuff() }
end
+2

. . Threads:

      def doStuff
         sleep(4) # Simulate slow process
         visit '/result'
      end

      .
      .
      .

      my_button=stack do 
         image  "button_image.jpg"
          para  "Press me"
      end
      my_button.click do
          Thread.new do
             doStuff
          end
           my_button.contents[0].hide
          my_button.contents[1].text = "Processing, please wait ..."
      end

.

+2

Source: https://habr.com/ru/post/1705170/


All Articles