Skip to content

Commit c69dd8c

Browse files
committed
Added progress bar example
1 parent ab12bdc commit c69dd8c

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

8a-Display-Progress-bar.pl

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#! /usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
use diagnostics;
6+
use feature ':5.14';
7+
use Gtk3 '-init';
8+
use Glib qw/TRUE FALSE/;
9+
10+
my $window = Gtk3::Window->new('toplevel');
11+
$window->set_title("Progress Bar");
12+
$window->set_position("mouse");
13+
$window->set_default_size(250, 100);
14+
$window->set_border_width(5);
15+
$window->signal_connect (delete_event => sub { Gtk3->main_quit });
16+
17+
my $vbox = Gtk3::Box->new("vertical", 5);
18+
$window->add($vbox);
19+
20+
my $progress = Gtk3::ProgressBar->new;
21+
$progress->set_orientation("horizontal");
22+
$progress->set_inverted(FALSE);
23+
$progress->set_text(undef);
24+
$progress->set_show_text(FALSE);
25+
$vbox->add($progress);
26+
27+
my $hbox = Gtk3::Box->new("horizontal", 2);
28+
$vbox->add($hbox);
29+
30+
my $toggle1 = Gtk3::ToggleButton->new_with_label('Text');
31+
my $toggle2 = Gtk3::ToggleButton->new_with_label('Percent');
32+
my $toggle3 = Gtk3::ToggleButton->new_with_label('Invert');
33+
$hbox->pack_start($toggle1, TRUE, TRUE, 0);
34+
$hbox->pack_start($toggle2, TRUE, TRUE, 0);
35+
$hbox->pack_start($toggle3, TRUE, TRUE, 0);
36+
37+
$toggle1->signal_connect ( toggled => \&showtext );
38+
$toggle2->signal_connect ( toggled => \&showpercent );
39+
$toggle3->signal_connect ( toggled => \&invert );
40+
41+
my $increment = 0.01;
42+
my $timer = Glib::Timeout->add (50, \&update);
43+
44+
$window->show_all;
45+
Gtk3->main;
46+
47+
sub showtext {
48+
my ($widget, $data) = @_;
49+
my $text = undef;
50+
if ( $widget->get_active ) {
51+
$text = "some text";
52+
}
53+
$progress->set_text( $text );
54+
$progress->set_show_text( $widget->get_active );
55+
}
56+
57+
sub showpercent {
58+
my ($widget, $data) = @_;
59+
my $show = $widget->get_active;
60+
$progress->set_text( undef );
61+
$progress->set_show_text( $show );
62+
}
63+
64+
sub invert {
65+
my ($widget, $data) = @_;
66+
$progress->set_inverted( $widget->get_active );
67+
}
68+
69+
sub update {
70+
if ( $progress->get_fraction >= 1 ) {
71+
$increment = -0.01;
72+
}
73+
if ( $progress->get_fraction <= 0 ) {
74+
$increment = 0.01;
75+
}
76+
$progress->set_fraction( $progress->get_fraction + $increment );
77+
return TRUE;
78+
}

0 commit comments

Comments
 (0)