File: bind

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 (73 lines) | stat: -rwxr-xr-x 1,552 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
#!/usr/bin/perl -w
# $Id: bind,v 1.4 2013/07/14 22:27:47 tom Exp $

#
# Purpose:
#	To demonstrate the character binding features of the
# Perl5/Cdk extension.
#

use strict;

#
# Load in the Cdk Extension.
#
use Cdk;
Cdk::init();

# This callback fills the entry field with a filename.
sub callback {
    my $entryObj = shift @_;

    # Generate a list of files in the current directory.
    my @files    = <*>;
    my $filelist = new Cdk::Scroll(
        'Title'  => "<C></U>Pick A File",
        'Height' => 10,
        'Width'  => 20,
        'List'   => \@files
    );

    # Activate the scrolling list.
    my $itemPicked = $filelist->activate();
    undef $filelist;

    # Set the filename.
    $entryObj->set( 'Min' => 0, 'Max' => 255, 'Value' => $files[$itemPicked] );

    # Redraw the entry field.
    $entryObj->draw();
    return 1;
}

# Create a new entry object.
my $title =
  [ "", "<C>Type in a filename or", "<C>Press </R>tab<!R> to get a list.", "" ];
my $filename = new Cdk::Entry(
    'Label' => "Filename: ",
    'Title' => $title,
    'Width' => 20,
    'Min'   => 0,
    'Max'   => 256
);

# Create a key binding.
my @mesg = ( "<C>Hi Mike", "<C></U>How Are You?" );
$filename->bind(
    'Key'      => "KEY_TAB",
    'Function' => sub { main::callback($filename); }
);

# Activate the object.
my $file = $filename->activate();

# Check the results.
if ( !defined $file ) {
    popupLabel( ["<C>Escape hit, no filename entered."] );
}
else {
    popupLabel( ["<C>You typed in the filename ($file)"] );
}

# Exit Cdk.
Cdk::end();