# Gtk::ProgressBar and long process

**URL:** <https://www.ruby-forum.com/t/gtk-progressbar-and-long-process/181508>\
**Category:** Ruby-Gnome 2\
**Created:** [January 12, 2010, 10:52pm UTC](https://www.ruby-forum.com/t/gtk-progressbar-and-long-process/181508 "2010-01-12T22:52:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnioot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/77aa72/32.png) [@gnioot](https://www.ruby-forum.com/u/gnioot)\
**Post date:** [January 12, 2010, 10:52pm UTC](https://www.ruby-forum.com/t/gtk-progressbar-and-long-process/181508/1 "2010-01-12T22:52:11Z")

</div>

Hello,

I just want to update a progress bar during processing a long task.  
I’m using glade gtk and ruby, my english is so bad that a code sample  
will be, may be, clearer…

Class MainClass

[…]Definition of initialyse method and other thing like that: all  
works fine[…]

def on\_button1\_clicked(widget)  
gpxFileSelectDialog = GladeXML.new(GUI\_PATH, “gpx\_select”,  
“gpsDialog”, nil, GladeXML::FILE)  
filter = Gtk::FileFilter.new  
filter.name = “fichier GPX”  
filter.add\_pattern(’\*.[gG][pP][xX]’)  
gpxFileSelectDialog[‘gpx\_select’].add\_filter( filter )  
if gpxFileSelectDialog[‘gpx\_select’].run == Gtk::Dialog::RESPONSE\_OK  
@gpxFile = gpxFileSelectDialog[‘gpx\_select’].filename  
gpxFileSelectDialog[‘gpx\_select’].destroy()  
id = @widgetTree[‘statusbar1’].get\_context\_id(‘gpx\_file\_choosed’)  
begin  
@progressBar.fraction=0.0  
@progressBar.text=’’  
@progressBar.ellipsize=2

# My progress bar don’t pulse :’(

```
    timer=Gtk::timeout_add(100) {@progressBar.pulse;true}
    # Une trace est un tableau de point, les points sont toujours

```

dans l’ordre chronologique  
th=Thread.new{ @trace = Trace.new(@gpxFile) }  
rescue RuntimeError =\> reason  
@progressBar.text=reason # Thread is aborted for some reason  
puts “Houston we’ve got a problem”  
ensure  
Gtk::timeout\_remove(timer) # and remove the callback  
@progressBar.fraction=1.0  
@progressBar.text=“Completed”  
end  
@widgetTree[‘statusbar1’].push(id,“gpx file = #{@gpxFile}”)  
else  
gpxFileSelectDialog[‘gpx\_select’].destroy()  
end  
end

[…]

end

# Main program

if **FILE** == $0  
GUI\_PATH = “/My/path/to/my/file.glade”  
GUI\_MAIN\_WINDOW = “mainWindow”  
MainClass.new(GUI\_PATH, GUI\_MAIN\_WINDOW)  
Gtk.main  
end

My question is why the Gtk main Thread don’t draw the pulse of the  
progress bar. The gpxFileSelectDialog window self close correctly, but  
after the main window seam to be frozen…  
I googled, even in C and python, looking for things which can unfroze  
me, but, 404 i’m not found.  
The Trace Class, juste open a XML file, parse it (using REXML) and puts  
some information into an array.

If you could give me directions to dig, i will be very happy.

-

---

<div class="post-metadata">

**Author:** ![gnioot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/77aa72/32.png) [@gnioot](https://www.ruby-forum.com/u/gnioot)\
**Post date:** [January 13, 2010, 4:36pm UTC](https://www.ruby-forum.com/t/gtk-progressbar-and-long-process/181508/2 "2010-01-13T16:36:54Z")

</div>

2010/1/12 Gnioot G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Â Â Â begin  
> Â Â Â Â @progressBar.fraction=0.0  
> Â Â Â Â @progressBar.text=‘’  
> Â Â Â Â @progressBar.ellipsize=2  
> Â # My progress bar don’t pulse 😢  
> Â Â Â Â timer=Gtk::timeout\_add(100) {@progressBar.pulse;true}

Just a wild guess. Try to initialize pulse\_step.

@progressBar.pulse\_step = 0.1

Simon

---

<div class="post-metadata">

**Author:** ![gnioot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/77aa72/32.png) [@gnioot](https://www.ruby-forum.com/u/gnioot)\
**Post date:** [January 13, 2010, 6:44pm UTC](https://www.ruby-forum.com/t/gtk-progressbar-and-long-process/181508/3 "2010-01-13T18:44:17Z")

</div>

You are right Simon, many thanks for that observetaion, I have made so  
much test and codes modifications that I forgot to initialize this in  
the last release…  
So it done:

```
    @progressBar.fraction=0.0
    @progressBar.text=''
    @progressBar.ellipsize=2
    @progressBar.pulse_step=0.1
    timer=Gtk::timeout_add(100) {@progressBar.pulse;true}
    th=Thread.new{ @trace = Trace.new(@gpxFile) }

```

but the behavior is always the same: the main window is frozen during  
the thread. I search again.
