# Gauge use

**URL:** <https://www.ruby-forum.com/t/gauge-use/167099>\
**Category:** wxRuby\
**Created:** [May 4, 2009, 1:22am UTC](https://www.ruby-forum.com/t/gauge-use/167099 "2009-05-04T01:22:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 4, 2009, 1:22am UTC](https://www.ruby-forum.com/t/gauge-use/167099/1 "2009-05-04T01:22:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 4, 2009, 3:12am UTC](https://www.ruby-forum.com/t/gauge-use/167099/2 "2009-05-04T03:12:24Z")

</div>

It would be helpful, if you provided a minimalistic version of your  
program,  
demonstrating the problem, so that we can properly diagnose it.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 4, 2009, 5:01pm UTC](https://www.ruby-forum.com/t/gauge-use/167099/3 "2009-05-04T17:01:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 4, 2009, 8:47pm UTC](https://www.ruby-forum.com/t/gauge-use/167099/4 "2009-05-04T20:47:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 4, 2009, 9:41pm UTC](https://www.ruby-forum.com/t/gauge-use/167099/5 "2009-05-04T21:41:33Z")

</div>

Perfect! It works now. Thanks 🙂
