#!/usr/bin/perl -w # $Id: async,v 1.4 2013/07/17 19:34:06 tom Exp $ # # This demo demonstrates how to use async functions with Cdk... # use strict; # # Initialize Cdk. # use Cdk; Cdk::init(); # Set the async function... $SIG{'ALRM'} = "littleWeeClock"; our @listItems; # Set up the scrolling list. setpwent(); while ( my $item = getpwent() ) { push( @listItems, $item ); } # Get the screen dimensions. my ( $rows, $cols ) = Cdk::getCdkScreenDim(); # Create the scrolling list object. my $scroll = new Cdk::Scroll( 'Title' => "Pick An Account", 'Height' => 10, 'Numbers' => "TRUE", 'Highlight' => "", 'Width' => 25, 'List' => \@listItems ); # Create the label... my $clock = new Cdk::Label( 'Message' => ["Current Time: HH:MM:SS"], 'Xpos' => "TOP" ); # Draw the scrolling window. $clock->draw(); # Set the alarm to go off. alarm(1); # Do this forever. for ( ; ; ) { # Activate the scrolling list. my $itemPicked = $scroll->activate(); # Do we need to exit... exit if !defined $itemPicked; # Get the password info. my ( $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell ) = getpwnam( $listItems[$itemPicked] ); # Display it. my $info = [ "Account Name $name", "UID $uid", "GID $gid", "Directory $dir", "Shell $shell" ]; popupLabel($info); } # Exit Cdk. Cdk::end(); # # This is the async function. # sub littleWeeClock { # # Turn off the alarm # $SIG{'ALRM'} = "IGNORE"; alarm(0); # # Get the current time/date. # my ( $sec, $min, $hour ) = ( localtime(time) ); my $mesg = sprintf( "%02d:%02d:%02d", $hour, $min, $sec ); # # Add the line to the scrolling window. # $clock->set( 'Message' => ["Current Time: $mesg"] ); # # Reset the alarm. # $SIG{'ALRM'} = "littleWeeClock"; alarm(1); }