Forum: Ruby-Gnome 2 Gtk::ProgressBar and long process

Posted by Gnioot Gnioot (gnioot)
on 2010-01-12 22:52
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.

+
Posted by Simon Arnaud (Guest)
on 2010-01-13 16:36
(Received via mailing list)
2010/1/12 Gnioot Gnioot <ruby-forum-incoming@andreas-s.net>:
>      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
Posted by Gnioot Gnioot (gnioot)
on 2010-01-13 18:44
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.

Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.