[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Gtk::ProgressBar set_fraction doesn't work

richard.j.dale@gmail.com

12/4/2006 10:58:00 AM


Paul Lutus wrote:

> 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 can't help with the original GTK question. But in QtRuby you would
use a Qt::Timer that allows you to specify a ruby method as a 'slot' to
be called periodically. In the slot called by Qt::Timer, download a
single file, update the progress bar and return. That way control can
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.

-- Richard

2 Answers

Paul Lutus

12/4/2006 5:39:00 PM

0

richard.j.dale@gmail.com wrote:

>
> Paul Lutus wrote:
>
>> 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 can't help with the original GTK question. But in QtRuby you would
> use a Qt::Timer that allows you to specify a ruby method as a 'slot' to
> be called periodically. In the slot called by Qt::Timer, download a
> single file, update the progress bar and return. That way control can
> 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.

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

richard.j.dale@gmail.com

12/4/2006 6:26:00 PM

0


Paul Lutus wrote:
> richard.j.dale@gmail.com wrote:
>
> >
> > Paul Lutus wrote:
> >
> >> 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 can't help with the original GTK question. But in QtRuby you would
> > use a Qt::Timer that allows you to specify a ruby method as a 'slot' to
> > be called periodically. In the slot called by Qt::Timer, download a
> > single file, update the progress bar and return. That way control can
> > 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.
To do that you would need to create a socket, and then use a
Qt::SocketNotifier of Type Read to monitor it. The SocketNotifier emits
a signal 'activated(int)' when there is something to read on the
socket. So in the slot connected to the activated signal, you would
read from the socket, update the progress bar according to the bytes
read and return.

-- Richard