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
|
#!/usr/bin/perl -w
# $Id: viewer,v 1.3 2013/07/14 22:37:55 tom Exp $
#
# Purpose:
# To demonstrate the Perl5 Cdk Viewer Widget.
use strict;
#
# Initialize Cdk.
#
use Cdk;
use Getopt::Long;
Cdk::init();
our ( $opt_f, $opt_h, $opt_w );
# Get the screen dimensions.
my ( $rows, $cols ) = Cdk::getCdkScreenDim();
# Parse the command line options.
my $ret = GetOptions( 'f|file:s', 'h|height:i', 'w|width:i' );
my $height = $opt_h || $rows - 2;
my $width = $opt_w || $cols;
my $filename = $opt_f;
# Activate the object.
if ( !defined $filename ) {
# Create a file selector widget to get the filename.
my $fselect = new Cdk::Fselect(
'Label' => "Filename:",
'Height' => $height,
'Width' => $width
);
# Get the filename.
$filename = $fselect->activate();
}
# Open the file and load it up.
my @info = qx (cat $filename);
chomp @info;
# Create the viewer object.
my $viewer = new Cdk::Viewer(
'Buttons' => ["<<OK>>"],
'Height' => $height,
'Width' => $width
);
# Set the contents of the viewer.
$viewer->set(
'Title' => "<C></5>File: $filename",
'Info' => \@info
);
# Activate the viewer.
my $selection = $viewer->activate();
# End Cdk.
Cdk::end();
|