[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Gtk::ProgressBar set_fraction doesn't work

Patrick Plattes

12/3/2006 10:52:00 AM

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 + " = "
+ bar.fraction.to_s
end
end

dialog.destroy
end

5 Answers

Paul Lutus

12/3/2006 11:31:00 AM

0

Patrick Plattes 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.

--
Paul Lutus
http://www.ara...

Kouhei Sutou

12/3/2006 12:20:00 PM

0

Patrick Plattes

12/3/2006 11:19:00 PM

0

Paul Lutus 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/f...]

I don't see how i can call g_main_context_iteration in ruby. Any idea?

Thanks,
Patrick

Kouhei Sutou

12/4/2006 12:47:00 AM

0

Hi,

2006/12/4, Patrick Plattes <patrick@erdbeere.net>:
> Paul Lutus 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.
> >
>
> "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.
>
> 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,
--
kou

Patrick Plattes

12/4/2006 8:31:00 AM

0

Kouhei Sutou schrieb:

> while Gtk.events_pending?
> Gtk.main_iteration
> end

It works very well, thanks!

Patrick