【问题标题】:Progress bar in Ruby/Green Shoes红宝石/绿鞋中的进度条
【发布时间】:2013-12-26 15:13:16
【问题描述】:

我正在尝试让进度条在 Ruby 中与 Green Shoes 一起工作。我的问题是我正在创建的栏的进度没有显示。我的栏的状态要么在开始和执行代码期间为空,要么在结束时为满。

这是我的代码结构:

Shoes.app do
  button("Run") do
    progress_bar = progress left: 10, top: 10, width: 235
    backup_exe = File.open(File.dirname(__FILE__) + "/backuplist.txt","r+")
    count = 0
    File.open(backup_exe) {|f| count = f.read.count("\n")}
    counter = 0
    count = count.to_f
    puts count
    animate do |counter|                
    backup_exe.each  do |line|
        counter=counter+1
        progress_bar.fraction = ((counter/count)*10).round / 10.0
        puts progress_bar.fraction
            sleep(2)
        end
    end
  end
end

提前感谢您的帮助!

【问题讨论】:

  • puts count 的输出是什么?
  • width: 235 对我来说听起来很奇怪。看起来你混淆了width,这是“条形范围”,它是水平尺寸。试试progress_bar = progress width: 1.0
  • 嗯,我明白了……但它仍然没有这样做。酒吧要么满了,要么空着!
  • 你肯定算错了fraction。尝试打印出所有值并确保它们是∈[0,1]。不幸的是,由于缺少开发环境,我无法重现该案例。
  • 不,我查过了,我在区间内。

标签: ruby progress-bar shoes


【解决方案1】:

解决了!我需要将填充分数的值放入新线程中。 感谢 mudasobwa 的投入!

【讨论】:

    猜你喜欢
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多