鞋子中的点击事件

发布于 2024-07-15 07:30:54 字数 756 浏览 6 评论 0原文

单击插槽时,我更改插槽的内容以提供用户反馈,然后调用一些需要几秒钟才能运行的代码。 然而,对槽的更改只有在“缓慢”过程完成后才会呈现。 有什么方法可以强制在“缓慢”代码运行之前进行渲染。

在下面的示例中,用户永远不会看到“正在处理,请稍候...”

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

查看 ruby​​.c 或 canvas.c 中的 Shoes 源代码,可以看到对重绘或绘制画布的引用。 它们可以从鞋子内调用吗?

提前致谢

On clicking a slot , I change the contents of the slot to provide user feed back, then call some code which takes several seconds to run. However the changes to the slot do not render until after the 'slow' process has completed. Is there any way I can force the rendering to happen before the 'slow' code runs.

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 Shoes source code in ruby.c or canvas.c there are references to a repaint or paint canvas. Are they callable from within shoes?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哆兒滾 2024-07-22 07:30:55

这有点黑客,但您可以将实际逻辑移至单独的函数中,如下所示:

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

  visit '/result'
end

并使用计时器在单独的线程中运行它:

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

  timer(0) { doStuff() }
end

It's kinda hackish, but you can move the actual logic into a separate function like this:

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

  visit '/result'
end

And use timer to run it in a separate thread:

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

  timer(0) { doStuff() }
end
披肩女神 2024-07-22 07:30:55

谢谢。 这真是一种享受。 我还使用 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

两种解决方案似乎都按预期工作。

Thank you. That works a treat. I've also worked out a solution using 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

Both solutions seem to work as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文