Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here it is with the GTK2 code for displaying the progress bars.</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; my $window = Gtk2::Window-&gt;new('toplevel'); $window-&gt;set_resizable(TRUE); $window-&gt;set_title("command runner"); my $vbox = Gtk2::VBox-&gt;new(FALSE, 5); $vbox-&gt;set_border_width(10); $window-&gt;add($vbox); $vbox-&gt;show; # Create a centering alignment object; my $align = Gtk2::Alignment-&gt;new(0.5, 0.5, 0, 0); $vbox-&gt;pack_start($align, FALSE, FALSE, 5); $align-&gt;show; # Create the Gtk2::ProgressBar and attach it to the window reference. my $pbar = Gtk2::ProgressBar-&gt;new; $window-&gt;{pbar} = $pbar; $align-&gt;add($pbar); $pbar-&gt;show; # Add a button to exit the program. my $runbutton = Gtk2::Button-&gt;new("Run"); $runbutton-&gt;signal_connect_swapped(clicked =&gt; \&amp;runCommands, $window); $vbox-&gt;pack_start($runbutton, FALSE, FALSE, 0); # This makes it so the button is the default. $runbutton-&gt;can_default(TRUE); # This grabs this button to be the default button. Simply hitting the "Enter" # key will cause this button to activate. $runbutton-&gt;grab_default; $runbutton-&gt;show; # Add a button to exit the program. my $closebutton = Gtk2::Button-&gt;new("Close"); $closebutton-&gt;signal_connect_swapped(clicked =&gt; sub { $_[0]-&gt;destroy;Gtk2-&gt;main_quit; }, $window); $vbox-&gt;pack_start($closebutton, FALSE, FALSE, 0); $closebutton-&gt;show; $window-&gt;show; Gtk2-&gt;main; sub pbar_increment { my ($pbar, $amount) = @_; # Calculate the value of the progress bar using the # value range set in the adjustment object my $new_val = $pbar-&gt;get_fraction() + $amount; $new_val = 0.0 if $new_val &gt; 1.0; # Set the new value $pbar-&gt;set_fraction($new_val); } sub runCommands { use IO::Select; my $s = IO::Select-&gt;new(); for (1..2) { open my $fh, '-|', './test.sh'; $s-&gt;add($fh); } while (my @readers = $s-&gt;can_read()) { for my $fh (@readers) { if (eof $fh) { $s-&gt;remove($fh); next; } my $l = &lt;$fh&gt;; print $l; pbar_increment($pbar, .25) if $l =~ /output/; } } } </code></pre> <p>see <a href="http://gtk2-perl.sourceforge.net/doc/gtk2-perl-tut/sec-ProgressBars.html" rel="nofollow noreferrer">the perl GTK2 docs</a> for more info</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload