File: matrix

package info (click to toggle)
libcdk-perl 20130816-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,284 kB
  • ctags: 430
  • sloc: perl: 6,151; sh: 2,997; makefile: 24
file content (75 lines) | stat: -rwxr-xr-x 1,831 bytes parent folder | download | duplicates (4)
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
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl -w
# $Id: matrix,v 1.3 2013/07/14 22:49:11 tom Exp $

#
# Purpose:
#	To demonstrate the Perl5 Cdk Matrix Widget

use strict;

#
# Initialize Cdk.
#
use Cdk;
Cdk::init();

# Set up the matrix field attibutes.
my @rowtitles = ( "Course 1", "Course 2", "Course 3", "Course 4", "Course 5" );
my @coltitles = ( "Course",   "Lec 1",    "Lec 2",    "Lec 3",    "Flag" );
my @colwidths = ( 7,          5,          5,          5,          1 );
my @coltypes  = ( "UMIXED",   "UMIXED",   "UMIXED",   "UMIXED",   "UMIXED" );
my $title = [ "<C>Course Selection Matrix", "", "<C><#HL(30)>" ];
my $x;

# Create the matrix object.
my $matrix = new Cdk::Matrix(
    'Title'     => $title,
    'RowTitles' => \@rowtitles,
    'ColTitles' => \@coltitles,
    'ColWidths' => \@colwidths,
    'ColTypes'  => \@coltypes,
    'Vrows'     => 3,
    'Vcols'     => $#coltitles + 1,
    'BoxCell'   => "TRUE",
    'BoxMatrix' => "TRUE"
);

# Using this array, we will load up the matrix.
my @matrixValues = (
    [ "PSY340Y", "L0101", "L0201", "", "" ],
    [ "PSY340H", "L0101", "L0201", "", "" ],
    [ "PSY440Y", "L0101", "L0201", "", "" ],
    [ "PSY201Y", "L0101", "L0201", "", "" ]
);

# Load up the matrix.
$matrix->set( 'Values' => \@matrixValues );

# Draw the matrix.
$matrix->draw();

# Activate the matrix.
my ( $rows, $cols, $info ) = $matrix->activate();

# Check the results.
if ( !defined $rows ) {
    popupLabel( ["<C>Escape hit. No information in the matrix."] );
}
else {
    my @info = ("<C>Rows: $rows Cols: $cols");

    for ( $x = 0 ; $x < $rows ; $x++ ) {
        my $row = "";
        for ( my $y = 0 ; $y < $cols ; $y++ ) {
            $row .= "($x,$y) = $info->[$x][$y], ";
        }
        chomp $row;
        chomp $row;
        push( @info, $row );
    }
    popupLabel( \@info );
}

# Exit Cdk.
Cdk::end();