鞋子中的点击事件
单击插槽时,我更改插槽的内容以提供用户反馈,然后调用一些需要几秒钟才能运行的代码。 然而,对槽的更改只有在“缓慢”过程完成后才会呈现。 有什么方法可以强制在“缓慢”代码运行之前进行渲染。
在下面的示例中,用户永远不会看到“正在处理,请稍候...”
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这有点黑客,但您可以将实际逻辑移至单独的函数中,如下所示:
并使用计时器在单独的线程中运行它:
It's kinda hackish, but you can move the actual logic into a separate function like this:
And use
timer
to run it in a separate thread:谢谢。 这真是一种享受。 我还使用 Threads 制定了一个解决方案:
两种解决方案似乎都按预期工作。
Thank you. That works a treat. I've also worked out a solution using Threads :
Both solutions seem to work as expected.