PPresenter
view release on metacpan or search on metacpan
PPresenter/Show.pm view on Meta::CPAN
my $slides = $show->{slides};
my $current = $show->{current_slide};
if(ref $next_slide ne '' && $next_slide->isa("PPresenter::Slide"))
{ return if "$next_slide" eq "$current";
$next_slide->{previous} = $current;
}
elsif($next_slide eq 'FIRST')
{ $next_slide = $show->find_slide(0);
return unless defined $next_slide;
$next_slide->{previous} = $current || $next_slide;
}
elsif($next_slide eq 'LAST')
{ $next_slide = $show->find_slide($#{$slides});
return unless defined $next_slide;
$next_slide->{previous} = $current;
}
elsif($next_slide eq 'BACK')
{ return if $current->{number}==0;
$next_slide = $show->find_slide($current->{previous} || undef);
return unless defined $next_slide;
$next_slide->{previous} = $current;
}
elsif($next_slide eq 'NEXT')
{ return if $current->{number} == $#$slides;
$next_slide = $show->find_slide($current->{-nextSlide} || $current->{number} +1);
return unless defined $next_slide;
$next_slide->{previous} = $current;
}
elsif($next_slide eq 'NEXT_SELECTED')
{
$next_slide = $show->nextSelected;
return unless defined $next_slide;
$next_slide->{previous} = $current;
}
elsif($next_slide eq 'PREVIOUS')
{ $next_slide = $show->previousSelected;
return unless defined $next_slide;
$next_slide->{forward} = $current;
}
elsif($next_slide eq 'FORWARD')
{ $next_slide = $show->find_slide($current->{forward} || undef);
return unless defined $next_slide;
}
elsif($next_slide eq 'THIS')
{ $next_slide = $current;
}
elsif($next_slide !~ /\D/) # is a number
{ $next_slide = $show->find_slide($next_slide);
}
return unless defined $next_slide;
undef $show->{proceed_after};
print $show->timeStamp,": showing $next_slide->{number} \"$next_slide\".\n";
# Show new slide.
$show->busy(1);
$next_slide->prepare->show;
$show->busy(0);
$show->{current_slide} = $next_slide;
$show->{current_slide_number} = $next_slide->{number};
$show->{control}->update($show, $next_slide)->sync;
$next_slide->startProgram($show);
}
# Some of the information about the show will be copied to the presenter,
# but most not.
# The information stored for each object should contain all necessary
# information to produce the windows, because one must be able to switch
# between slides at random.
sub run()
{
my $show = shift;
die "No options allowed for run()" if @_;
unless(defined $show->{slides})
{ warn "No slides to show.";
return;
}
# Initialize tags.
$show->selectTags($show->{-tags})
if defined $show->{-tags};
# Initialize time.
my $totaltime = $show->{-totaltime};
my $slides = $show->{slides};
my $sumtime = 0;
my $not_active= 0;
foreach (@$slides)
{ if($_->isActive) { $sumtime += $_->requiredTime }
else { $not_active++ }
}
unless(defined $totaltime)
{ print "Total time $sumtime seconds for ",
@$slides-$not_active, " slides.\n";
$show->{-totaltime} = $sumtime;
}
elsif($sumtime > $totaltime)
{ my $load = $sumtime/$totaltime;
warn "Your ", @$slides-$not_active, " slides take $sumtime",
" seconds but you have only $totaltime seconds (",
int($load*100-100), "% too much)\n";
}
elsif($sumtime < $totaltime)
{ my $load = $sumtime/$totaltime;
my $spare = $totaltime - $sumtime;
$spare = $spare > 180
? int($spare/60 + .5)." minutes"
: $spare." seconds";
PPresenter/Show.pm view on Meta::CPAN
print $show->timeStamp, ": show stopped\n";
exit 0;
}
sub start
{ my $show = shift;
# When realization is slow, we have to wait for it.
my $ascreen = $show->{control}->screen;
$ascreen->after(100) until $ascreen->width > 1;
$show->showSlide($show->{-startSlide});
$show->{-starttime} = time;
print $show->timeStamp,": show started\n";
$ascreen->repeat(int ($show->{-clockTics}*1000), [ \&clockTic, $show ] );
}
#
# Tags
#
sub selectTags(@)
{ my $show = shift;
foreach (@_)
{ my $tag;
if(ref $_ eq 'ARRAY') {$show->selectTags(@$_)}
elsif(($tag) = /^\s*\-(\w+)/ ) {$show->clearTag($tag) }
elsif(($tag) = /^\s*\+?(\w+)/) {$show->setTag($tag) }
else {warn "Do not understand tag specification $_.\n"; }
}
}
sub setTag($)
{ my ($show, $tag) = @_;
map {$_->setActive(1) if $_->hasTag($tag)} @{$show->{slides}};
$show->slideSelectionChanged;
}
sub clearTag($)
{ my ($show, $tag) = @_;
map {$_->setActive(0) if $_->hasTag($tag)} @{$show->{slides}};
$show->slideSelectionChanged;
}
sub countSelectedTags()
{ my $show = shift;
my (%count, %set, %clear);
foreach (@{$show->{slides}})
{ if($_->isActive) {map {$set{$_}++; $count{$_}++} $_->tags}
else {map {$clear{$_}++; $count{$_}++} $_->tags}
}
map { [ $_, $count{$_}, $set{$_}||0, $clear{$_}||0 ] }
sort keys %count;
}
sub slideSelectionChanged() {shift->{control}->slideSelectionChanged}
sub busy($) {my ($show, $busy) = @_; $show->{control}->busy($busy)}
#
# TickTac
#
sub clockTic($)
{ my $show = shift;
my $interval = $show->{-clockTics};
my $slide = $show->{current_slide};
if($show->{-halted})
{ $slide->suspended($interval);
return $show;
}
$show->{runtime} += $interval;
$show->{control}->clockTic($interval, $slide);
$show->showSlide('NEXT_SELECTED') if $slide->wantNextSlide;
$show;
}
sub setRunning($)
{ my ($show,$running) = @_;
$show->{-halted} = not $running
if defined $running;
my $status = $show->{-halted}
? 'halted'
: $show->{runtime} > 0 ? 'continues' : 'started';
print $show->timeStamp,": run $status.\n";
}
sub setProceedAfter($) {$_[0]->{proceed_after} = $_[1]}
sub enableCallbacks()
{ my $show = shift;
my $old = $show->{-enableCallbacks};
$show->{-enableCallbacks} = shift if @_;
$old;
}
sub minSecs($)
{ my $secs = int $_[1];
return "??:??" unless defined $secs;
my $mins = 0;
if($secs > 60)
{ $mins = int($secs/60);
$secs -= $mins*60;
}
sprintf "%2d:%02d",$mins,$secs;
}
sub timeStamp(;$)
{ my $show = shift;
( run in 1.389 second using v1.01-cache-2.11-cpan-5735350b133 )