There’s surely an easy answer to this. How do you update a progress bar
during a lengthy calculation? The examples that come with FXRuby only
have a process bar updated while the app is idle.
The complete code is below. Just run it an type Ctrl-S. Nothing is
saved, it’s just a loop. The progress bar isn’t updated until the loop
is done. I tried wrapping the loop in a thread, and I tried calling
#update. I’m using FXRuby 1.0.13 and fox 1.0.11 and ruby 1.6.7.
#!/usr/bin/env ruby
require "fox"
include Fox
class ViewWindow < FXMainWindow
include Responder
def initialize(app)
super(app, “test”, nil, nil, DECOR_ALL, 0, 0, 0, 0)
menubar = FXMenubar.new(self,
LAYOUT_SIDE_TOP|LAYOUT_FILL_X|FRAME_RAISED)
@progress_target = FXDataTarget.new(0)
@progress_bar = FXProgressBar.new(self, @progress_target,
FXDataTarget::ID_VALUE, LAYOUT_FILL_X|PROGRESSBAR_PERCENTAGE)
filemenu = FXMenuPane.new(self)
FXMenuTitle.new(menubar, "&File", nil, filemenu)
FXMenuCommand.new(filemenu, "&Save...\tCtl-S\tSave file.", nil).
connect(SEL_COMMAND, method(:onCmdSave))
FXMenuCommand.new(filemenu, "&Quit\tCtl-Q").
connect(SEL_COMMAND) {getApp().exit(0)}
end
def onCmdSave(sender, sel, ptr)
Thread.new do
20.times {|i|
sleep(0.1)
@progress_target.value = i
}
end
return 1
end
def create
position(0, 0, 200, 100)
super
show
end
end
app = FXApp.new(“App”, “Foo”)
app.init(ARGV)
window = ViewWindow.new(app)
app.create
app.run