Gtk::ProgressBar and long process

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.

2010/1/12 Gnioot G. [email protected]:

   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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs