Ruby Shoes GUI:不断更新段落 [英] Ruby Shoes GUI: Continually Updating Paragraphs
问题描述
Ruby 的 Shoes GUI 工具包似乎是将 GUI 添加到我的各种脚本中的一种非常好的和简单的方法,但是在我的头撞到它之后,我似乎无法通过循环不断更新一个段落.
这是我的最小代码来显示我正在尝试做的事情:
Shoes.app 做堆栈做@exit = 按钮退出"@log = stack { para日志记录在这里......"}@exit.click { 退出 }结尾循环做睡觉 1内容 = `ls`@log.append { 段内容}结尾结尾
但这只会永远阻塞并且我的 GUI 永远不会出现,直到我杀死 ruby 进程,那时我的所有信息都会出现.
我尝试将内容"检查循环并附加到一个单独的类中,在它自己的堆栈"或流"循环中,尝试根据块重定向"标头将@log 传递给单独的类的方法在鞋子规则 (http://shoesrb.com/manual/Rules.html) 中,仍然在尝试了我能想到的一切之后,没有任何乐趣.任何想法如何让这个工作?我想我只是没有完全掌握 Shoes 如何设置 GUI.
如果您希望列出目录中的所有文件并每秒刷新列表,那么我认为这就是您要查找的内容:
>
Shoes.app 做堆栈做@btn_exit = button("Exit") {exit}@log = para "日志记录在这里......"结尾每 1 次@log.text = Dir.entries('C:/Test').select{|file|file != "."*file.length}.join("\n")结尾结尾
The Shoes GUI kit for Ruby seems like a really nice and easy way to add a GUI to my various scripts, but after banging my head against it, I can't seem to make a paragraph be continually updated with a loop.
Here's my minimal code to show what I'm trying to do:
Shoes.app do
stack do
@exit = button "Exit"
@log = stack { para "Logging goes here..." }
@exit.click { exit }
end
loop do
sleep 1
contents = `ls`
@log.append { para contents }
end
end
But this just blocks forever and my GUI never shows up until I kill the ruby process, at which time all my info appears.
I've tried putting the "contents" checking loop and append in a separate class, in its own "stack" or "flow" loop, tried passing @log to a separate class's method as per the "Block Redirection" header in the Shoes Rules (http://shoesrb.com/manual/Rules.html), still no joy after trying everything I can think of. Any ideas how I can get this working? I'm thinking I just don't have a complete grasp on how Shoes sets up the GUI.
If you're looking to list all files in a directory and refresh the list every second, then I think this is what you're looking for:
Shoes.app do
stack do
@btn_exit = button("Exit") {exit}
@log = para "Logging goes here..."
end
every 1 do
@log.text = Dir.entries('C:/Test').select{|file| file != "."*file.length}.join("\n")
end
end
这篇关于Ruby Shoes GUI:不断更新段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!