#!/usr/bin/perl use strict; use warnings; use Tk; use Time::HiRes qw(usleep); our $DEBUG = 0; foreach my $ARG (@ARGV) {print "'$ARG'\n" if $DEBUG}; my %variable; my $disappear; my $id = $ARGV[0];; my $title = $ARGV[1]; my $params = $ARGV[2]; my @ini_parameters = split ";", $params; foreach my $string (@ini_parameters) { # get all variables and their values $string =~ /(.*)=(.*)/; $variable{$1} = $2; print "variable:'$1' - value:'$2'\n" if $DEBUG; } my ( $label, $host, $bannerspeed ); our( $font, $fontsize, $fonttype, $fgcolor, $bgcolor ); if ( $variable{'title'} ) { $title = $variable{'title'} } else { $title = "Message:" }; if ( $variable{'label'} ) { $label = $variable{'label'} } else { $label = "no label defined" }; if ( $variable{'font'} ) { $font = $variable{'font'} } else { $font = "Arial" }; if ( $variable{'fontsize'} ) { $fontsize = $variable{'fontsize'} } else { $fontsize = "30" }; if ( $variable{'fonttype'} ) { $fonttype = $variable{'fonttype'} } else { $fonttype = "bold" }; if ( $variable{'fgcolor'} ) { $fgcolor = $variable{'fgcolor'} } else { $fgcolor = "black" }; if ( $variable{'bgcolor'} ) { $bgcolor = $variable{'bgcolor'} } else { $bgcolor = "red" }; if ( $variable{'host'} ) { $host = $variable{'host'} } else { $host = "localhost" }; if ( $variable{'bannerspeed'} ) { $bannerspeed = $variable{'bannerspeed'} } else { $bannerspeed = "1" }; our $fonts = $font." ".$fontsize." ".$fonttype; $fonts =~ s/^\s+//; $fonts =~ s/\s+$//; our $mw = MainWindow->new; $mw->title($title); # calculate max windows size my ($max_window_width,$max_window_height)=$mw->maxsize(); our $window_size_x = $max_window_width; our $window_size_y = $fontsize+20; our $window_position_x = 0; our $window_position_y = $id * ($window_size_y + 34); my $text_position_x = 0; my $text_position_y = 0; # Mainwindow: sizex/y, positionx/y $mw->geometry($window_size_x."x".$window_size_y."+".$window_position_x."+".$window_position_y); banner(" " x $max_window_width, $text_position_x, $text_position_y); # open windows first time to set background color #prevents mw from closing #$mw->protocol('WM_DELETE_WINDOW' => sub { Funct(); exit;} ); my $label_length = length($label); my ($pre_label, $post_label, $new_label, $min_x, $starttime); $min_x = (($label_length + 30) * (-1)) * ($fontsize / 2); # message went of screen on left side #$pre_label = " " x $loop; $post_label = " " x $bannerspeed; $new_label = $label.$post_label; for (my $loop = $max_window_width; $loop >= $min_x; $loop = $loop - $bannerspeed) { if ( $loop == $max_window_width ) { $starttime = time }; # print "'$new_label', '$loop', '$text_position_y'\n" if $DEBUG; banner($new_label, $loop, $text_position_y); if ( $loop <= $min_x ) { my $duration = time - $starttime; $starttime = time; print "duration:'$duration' - length:'",length($new_label),"'\n"; $loop = $max_window_width; }; usleep(5); } #automatic close after time $mw->after(1000, sub { $mw->destroy; }); #MainLoop; exit; ################################################### ################################################### ################################################### sub banner { my $label = shift; my $text_position_x = shift; my $text_position_y = shift; $mw->Label( -fg=> $fgcolor, -bg => $bgcolor, -text => $label, -font => $fonts) -> place (-x => $text_position_x, -y => $text_position_y); $mw->update; }