Hello,
i have some problems with the Gtk::ProgressBar. I download a file and i
want to show a progressbar. The method below creates a new dialog with a
bar and starts the download for each file. The puts-line work very well
and i can see a dialog, there is no update. Does anybody know whats
going wrong?
Thanks to all the people in this great community,
Patrick
def download_podcasts(liststore_podcasts)
dialog = Gtk::Dialog.new(“Download”,
$main_application_window,
Gtk::Dialog::DESTROY_WITH_PARENT)
bar = Gtk::ProgressBar.new
bar.fraction = 0.0
dialog.vbox.add(bar)
dialog.show_all
liststore_podcasts.each do |model,path,row|
row[3].download do |received, total|
bar.fraction = received.to_f / total.to_f
bar.text = (bar.fraction * 100).to_s + "%"
puts received.to_s + " / " + total.to_s + " = "
end
Patrick P. wrote:
Hello,
i have some problems with the Gtk::ProgressBar. I download a file and i
want to show a progressbar. The method below creates a new dialog with a
bar and starts the download for each file. The puts-line work very well
and i can see a dialog, there is no update. Does anybody know whats
going wrong?
The thread in which your process is running, that would update the
progress
bar, is busy downloading your file, so it cannot update the progressbar
dislay. This is a very common problem, normally solved by creating a
separate thread to perform the download, thus freeing the display thread
to
perform updates. Unfortunately, because of how threads are implemented
in
Ruby, this approach often doesn’t work.
I have not had any success updating progress bars using worker threads
and
the Qt GUI library, you may have a different experience with
GTk:ProgressBar.
Hi,
In [email protected]
“Re: Gtk::ProgressBar set_fraction doesn’t work” on Sun, 3 Dec 2006
20:35:11 +0900,
Paul L. [email protected] wrote:
perform updates. Unfortunately, because of how threads are implemented in
Ruby, this approach often doesn’t work.
I have not had any success updating progress bars using worker threads and
the Qt GUI library, you may have a different experience with
GTk:ProgressBar.
Gtk.idle_add may help you.
Thanks,
Paul L. schrieb:
I have not had any success updating progress bars using worker threads and
the Qt GUI library, you may have a different experience with
GTk:ProgressBar.
I found an interesting link:
"You are probably doing all the changes within a function without
returning control to gtk_main(). This may be the case if you do some
lengthy calculation in your code. Most drawing updates are only placed
on a queue, which is processed within gtk_main(). You can force the
drawing queue to be processed using something like:
while (g_main_context_iteration(NULL, FALSE));
inside you’re function that changes the widget.
What the above snippet does is run all pending events and high priority
idle functions, then return immediately (the drawing is done in a high
priority idle function)." [http://www.gtk.org/faq/#AEN602]
I don’t see how i can call g_main_context_iteration in ruby. Any idea?
Thanks,
Patrick
Kouhei S. schrieb:
while Gtk.events_pending?
Gtk.main_iteration
end
It works very well, thanks!
Patrick
Hi,
2006/12/4, Patrick P. [email protected]:
drawing queue to be processed using something like:
while (g_main_context_iteration(NULL, FALSE));
inside you’re function that changes the widget.
I don’t see how i can call g_main_context_iteration in ruby. Any idea?
while Gtk.events_pending?
Gtk.main_iteration
end
Thanks,
[email protected] wrote:
return to Qt’s main loop, and events can be handled - otherwise the GUI
will just freeze while you do what might be a lengthy download of lots
of podcasts.
Yes, tried that method. Doesn’t work for a single file, the original
objective. The reason AFAICS is the timer can’t easily preempt the file
download while it is under way, and when it can, it produces now
information that the display routines will use to update the display,
but
only after the file download is finished.
Your suggestion works for a task consisting of a series of file
downloads,
and a progress bar that indicates the total progress for all the files,
and
a timer that initiates each new file download at intervals. Yes, that
works.