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

Hello Monks,

I'm looking to see if there is any kind of widget out there which is basically like an hourglass type of thing.
What I REALLY wanted to use was the Gtk2::ProgressBar but I don't think I can. What I'm "trying" to do is this...

My MAIN window widget contains a Table, then in the table I have some Buttons, RadioButtons, Entry Widgets, etc...
So when the user clicks MY "Submit" button it captures all the information provided and then executes another Perl
script I have. The Perl script being executed uses the data captured from the Widgets described above as CMD Line Args.
Since the other Perl script being executed creates a TCP socket to send the data to a server, sometimes it can take up
to 15 seconds or so to complete executing.

What I wanted to do ORIGINALLY, was to have a ProgressBar showing the progress of the other script which gets executed. I created
a test script using the ProgressBar and it works great... But here lies my problem! I didn't even think of it until after I created
the test script which uses the ProgressBar (*fraction incremented += .1 on each click of a button), that I can't simply send
the command below:
$progress_bar->set_fraction($fraction);
... in order to move along the ProgressBar so the user knows how far along it is... Would this be possible at all? Because I was thinking
that since I'm executing my secondary script using the system() command, that my Gtk2 script will just halt until the system command
returns. So I realized I wouldn't know what the script was doing until it returned from the system() command.... Is that correct to assume? Or
is there some other way to achieve that?

So since I can't tell what's going on in the script that executes from the Gtk2 script, I was thinking instead of a ProgressBar I would simply
use something that's like an HourGlass... OR I know I've seen some things where it looks like a circle with arms coming out of it and as it
"plays/runs" it looks like its spinning... Not sure if I explained that correctly but basically it works like an Hourglass type of thing...


Anybody have any idea if there is anything like that in Perl::Gtk2?
I looked over all the Widgets I could find but maybe I missed something...

Any thoughts or suggestions would be GREATLY appreciated!


Thanks in Advance,
Matt

Replies are listed 'Best First'.
Re: Perl::Gtk2, Looking for a Widget Similar to HourGlass
by roboticus (Chancellor) on Jul 18, 2013 at 19:11 UTC

    mmartin:

    Rather than a widget, I'm thinking you can just set your mouse pointer to the default "waiting" pointer. I've not used Perl::Gtk2, so I don't know how to do that, but when I googled Gtk2 I found that it definitely has the ability. I'm guessing some digging into the documentation can give you an example.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Hey roboticus, thanks for the reply!

      That's another good idea. Now that you mention it I definitely do remember seeing something like "mouse pointer manipulation" at
      some point during my Googling of Gtk2 demos and tutorials and what not... Nice!

      I may not ONLY do the pointer thing, but I will definitely use that in the script along with whatever else I come up with for this!


      Thanks Again,
      Matt

Re: Perl::Gtk2, Looking for a Widget Similar to HourGlass
by Anonymous Monk on Jul 18, 2013 at 17:07 UTC
      Hey AnonymousMonk, thanks for the reply!

      Humm... I did not think of that, that's a great idea!

      I'm sure I could work something into the script like that... Should have thought to just check up on the "background" process
      using some other means... Awesome!

      I also have another idea, see my new post at the end...

      Thanks Again for the reply, MUCH appreciated!


      Thanks Again,
      Matt

      Hey Monks, finally got a solution to work.

      I decided to go with using the GIF image instead of the ProgressBar and running the Background Job using
      the "Proc::Background" Module.

      The code below is what will happen when you press the "Submit" button in my program. Basically you click
      submit then the function/sub below gets executed. Inside this Function my Pop-Up window gets ran, which contains
      the GIF image I mentioned before. Then the Background Job gets started, and I use a while loop to continuously check
      if the Job is still "alive". Inside that while loop is another while loop that causes Gtk2 to continue processing
      while there are still events to be ran, so that causes the GIF image to continue "spinning". Otherwise, without the
      INNER while loop the GIF image inside the popup would pause/stop completely until the OUTER while loop had finished
      executing because of the "sleep" or "usleep" commands which cause Gtk2 to pause.
      sub submit_function() { print "YOU CLICKED SUBMIT...\n"; print "Run Background Job... And Open 'Loading...' Pop-Up Window\n"; $popup_window->show_all(); my $command = "/path/to/command/test_backgroundProcess.pl"; ### Start running the Background Job: my $proc = Proc::Background->new($command, "5"); my $PID = $proc->pid; my $start_time = $proc->start_time; my $alive = $proc->alive; ### While $alive is NOT '0', then keep checking till it is... # *When $alive is '0', it has finished executing. while($alive ne 0) { $alive = $proc->alive; # This while loop will cause Gtk2 to conti processing events, if # there are events pending... *which there are... while (Gtk2->events_pending) { Gtk2->main_iteration; } Gtk2::Gdk->flush; usleep(1000); } my $end_time = $proc->end_time; print "*Command Completed at $end_time, with PID = $PID\n\n"; # Since the while loop has exited, the BG job has finished running: # so close the pop-up window... $popup_window->hide; # Get the RETCODE from the Background Job using the 'wait' method my $retcode = $proc->wait; $retcode /= 256; print "\t*RETCODE == $retcode\n\n"; ### Check if the RETCODE returned with an Error: if ($retcode ne 0) { print "Error: The Background Job returned with an Error...!\n"; } else { print "Success: The Background Job Completed Successfully...!\n"; } }

      So anyway... Thanks guys for all your help with this... Much Appreciated!


      *EDIT:
      I forgot to mention, the reason I use the usleep() command instead of just "sleep 1;" or something like that is because there would
      be a slight pause in the GIF image on every loop inside the while loop. So by using the usleep command it loops so quickly that you
      cannot notice that it is pausing or not...


      Thanks Again,
      Matt


Re: Perl::Gtk2, Looking for a Widget Similar to HourGlass
by mmartin (Monk) on Jul 18, 2013 at 19:59 UTC
    Ok, so I have another idea instead of the ProgressBar, that maybe someone could help me with.

    So instead of doing a ProgressBar I found some Gifs that work like endless looping progress-bar/spinning wheels, etc...

    So what I think I'll try is to create some kind of container that can hold Widgets, and I'll add the animated Gif image
    along with a Label saying something like "Sending Data....", or soemthing like that, then once the Background process
    completes, I'll close the Container containing the Gif image.

    The part I need some guidance on is finding a Widget I can add a Gtk2::Image to along with a Label. I know the
    Gtk2::Window can hold Widget(s), but was hoping for something more like a Dialog box, or just a smaller window like widget.
    But it seems that the Dialog and MessageDialog cannot get Widgets "added" to them...

    Any ideas for what I CAN use to add Widgets to for this? I assume I could create a 2nd window aside from my MAIN-Parent window
    widget (*parent contains all the stuff I mentioned in my OP), but I have not tried creating more then one Window Widget
    in the same script.

    In the mean time I guess I'll try creating a really small "Window" widget by specifying the height and Width manually to something
    small. Then I guess I'd add something like an HBox that would include the label and GIF...


    If anyone has any ideas for something I can use other then a Gtk2::Window, please feel free...
    Other then that, any ideas, thoughts and/or suggestions would be greatly appreciated!


    Thanks in Advance,
    Matt


Re: Perl::Gtk2, Looking for a Widget Similar to HourGlass
by mmartin (Monk) on Jul 18, 2013 at 20:21 UTC
    Hummm.... Just came across the Gtk-Type Option for Gtk2::Window.

    Looks like it has an option for pop-up...
    I'm going to give that a try and I'll post back whether or not I'll be using this instead.


    Thanks,
    Matt

Re: Perl::Gtk2, Looking for a Widget Similar to HourGlass
by mmartin (Monk) on Jul 18, 2013 at 21:00 UTC
    Hey guys, sorry for the repetitive posts, but I wanted to post an update before I headed out for the day...

    I just got done trying the Gtk2::Window widget and it looks like that should be good enough for what I wanted to do.


    AnonymousMonk,

    I just had a chance to check out the Proc::Background Module. Its cool, if I have some extra time maybe I'll try that
    and I'll be able to resort back to my original idea of using the ProgressBar... Otherwise I'll just go with the Window
    Widget along with an animated Gif and label to sort of "spoof" a ProgressBar. Found lots a free Gifs out there for this
    type of purpose like the spinning wheel animation, and endless "progressbar-like" animations (which look sort of like
    a horizontal Barber's pole)
    ...


    Thanks,
    Matt