ciryon has asked for the wisdom of the Perl Monks concerning the following question:

Hi all!

I'm writing a Perl/Gtk program that basically works this way:

  • 1. The user clicks a "Get" button
  • 2. An external pogram is launched that (hopefully) writes a text file in /tmp
  • 3. The textfile is displayed in a textbox

    This is working perfectly. What I want to do now is to add a statusbar that says "Please select an option" when the program is launched and changes to "Please wait..." when the "Get" button is clicked. My current problem is that the "Please wait..." message isn't displayed until the wait is over. :-(

    Part of the code looks like:

    $statusbar = new Gtk::Statusbar(); $vbox->pack_start( $statusbar, $true, $true, 0 ); $statusbar->push( $context_id, "Please select an option" ); $statusbar->show();
    and the callback for the clicked button:
    sub GetButtonClicked { my $infostring = "Please wait..."; $statusbar->push( $context_id, $infostring); $statusbar->show(); ContactFromDevice(); LoadFileToText(); }
    Very grateful for some help.
  • Replies are listed 'Best First'.
    Re: Statusbar in Perl/Gtk
    by traveler (Parson) on Nov 14, 2001 at 21:15 UTC
      Without seeing all the code, I suspect that the problem is that you are not running the main gtk loop while the work is being done. Thus, gtk cannot make any changes to the screen. Try adding this loop after the $statusbar->show();:
      while (Gtk->events_pending) { Gtk->main_iteration; }
      You may also want to use that code insideContactFromDevice and LoadFileToText if you want the GUI to be responsive while those routines are running (if they run more than a second or so, say).

      HTH, --traveler