G

Perl Simple Threaded Splash Screen

public
glenn Jun 14, 2024 Never 85
Clone
Perl Perl Simple Threaded Splash Screen 104 lines (81 loc) | 2.67 KB
1
use strict;
2
use warnings;
3
use threads;
4
use threads::shared;
5
6
use Tk;
7
use Tk::Photo;
8
use Tk::PNG;
9
use Tk::JPEG;
10
use Tk::ProgressBar;
11
12
# Shared global variable
13
our $global_event_splash_screen :shared = "NOT_ACTIVE";
14
15
sub thread_splash_image {
16
my $w_width = 35;
17
my $w_height = 1;
18
19
my $highlightcolor = "black";
20
21
my $widget_bg_color = '#EEEEEE';
22
my $widget_fg_color = '#000000';
23
24
my $mw_row_ctr = 0;
25
my $mw_col_ctr = 0;
26
27
my $title = "";
28
my $rev = "";
29
my $mw = MainWindow->new (-title => "$title $rev");
30
31
# to center
32
my $xpos;
33
my $ypos;
34
$xpos = int(($mw->screenwidth - $mw->width ) / 2);
35
$ypos = int(($mw->screenheight - $mw->height) / 2);
36
$mw-> geometry ( '+'.$xpos.'+'.$ypos );
37
38
my $main_frame = $mw ->Frame(-background => "white") ->pack(-side => 'top', -fill => 'x', -expand => 1, -anchor => 'center');
39
40
my $script_window = $main_frame ->Frame(-background => $widget_bg_color, -highlightthickness => 0, -highlightbackground => 'black', )
41
->pack(-side => 'top', -fill => 'x', -anchor => 'center', -expand => 1, );
42
$script_window -> toplevel();
43
44
my $image_main = "C:/bin/perl/image/main.png";
45
if (!-e $image_main){
46
print "image [$image_main] does not exist\n";
47
exit 1;
48
}
49
my $tk_main = $mw->Photo(-file => $image_main);
50
my $font1 = $script_window ->fontCreate(-family => "Corrier", -size=> 8, -weight => 'bold' );
51
52
$script_window ->Label(
53
-font => $font1,
54
-image => $tk_main,
55
-wraplength => 430,
56
-state => "normal",
57
-relief => 'flat',
58
-highlightthickness => 0,
59
-takefocus => 0,
60
-foreground => $widget_fg_color,
61
-disabledforeground => $widget_fg_color,
62
-background => $widget_bg_color,
63
-justify => 'center',
64
-padx => 0,
65
-pady => 0,
66
-anchor => 'e',
67
)
68
-> grid(-row => $mw_row_ctr, -column => $mw_col_ctr, -columnspan => 3, -rowspan => 1, -ipadx => 1, -ipady => 1, -sticky => 'e',
69
);
70
71
$mw_row_ctr++;
72
$mw_col_ctr = 0;
73
74
$global_event_splash_screen = "ACTIVE";
75
76
while($global_event_splash_screen ne "RELEASE"){
77
$mw->update();
78
}
79
80
$mw->destroy();
81
undef $mw;
82
print "end thread_splash_image\n";
83
}
84
85
# Create threads
86
my $thread_splash_image = threads->create(\&thread_splash_image);
87
88
89
# Your Body
90
while($global_event_splash_screen ne "ACTIVE"){}
91
print "splash screen is now [$global_event_splash_screen]\n";
92
93
# Wait for the threads to complete
94
# $thread_splash_image->join();
95
96
# Initialize something
97
for (my $loop = 1; $loop <= 3; $loop++) {
98
99
# Do something
100
print "loop $loop\n";
101
sleep(1);
102
103
}
104
$global_event_splash_screen = "RELEASE";