Forum: wxRuby Gauge use

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2009-05-04 03:22
(Received via mailing list)
Hi,

I am using the Gauge for the first time, and am confused on it's use.  I
want to use it to measure the progress of copying certain files from one
location to another.  It is inside a Frame.  The problem is, that if I
try
to update the position after Frame.show, the program ends.  Can anyone
link
to an example? (The included bigdemo.rb didn't help, because it uses a
Timer
to change the position)

Thanks,
Jonah
Mario S. (Guest)
on 2009-05-04 05:12
(Received via mailing list)
It would be helpful, if you provided a minimalistic version of your
program,
demonstrating the problem, so that we can properly diagnose it.
Jonah D. (Guest)
on 2009-05-04 19:01
Sorry, never mind.  It was an error in my code.  On a side note, how
does one loop through a process while moving the gauge, without freezing
the program?  If I loop through copying some files, it still moves the
gauge, but has a waiting cursor and is stuck.  Is there a way to make it
do the operation, but not freeze?
Alex F. (Guest)
on 2009-05-04 22:47
(Received via mailing list)
Jonah D. wrote:
> how does one loop through a process while moving the gauge, without freezing
> the program?  If I loop through copying some files, it still moves the
> gauge, but has a waiting cursor and is stuck.  Is there a way to make it
> do the operation, but not freeze?
>

There are several different ways to deal with long-running background
tasks. Probably the easiest one for this situation - where you have a
job that breaks down naturally into smaller pieces (individual files) -
is to use evt_idle. This is called whenever there is processing time
free. It would go something like this:

def initialize
   ...
  evt_idle :on_idle
end

def on_idle
  if have_files_to_copy
    copy_a_file
    update_progress_bar
  end
end

This should allow the task to progress in chunks while keeping the GUI
responsive.

A more general approach to dealing with long-running tasks is to run
them in a background Thread. But this is considerably more complicated
for several reasons - eg you should not make GUI update calls from
subordinate threads. There are previous discussions and samples about
using Threads in wxRuby if that's the way you want to go.

alex
Jonah D. (Guest)
on 2009-05-04 23:41
Perfect!  It works now.  Thanks :)
This topic is locked and can not be replied to.