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