CursesApplication
view release on metacpan or search on metacpan
# Reset the form fields
resetfields($f);
}
sub showaddrec {
$app->createForm('AddRec', 'AddRecFrm');
$app->execForm('AddRec');
$app->delForm('AddRec');
}
sub resetfields {
my $f = shift;
# Reset the displayed record field
foreach (qw(Last First E-mail City State)) {
$f->getWidget($_)->setField(VALUE => '') };
}
sub addbtns {
my $f = shift;
my $key = shift;
my @fields = qw(Last First E-mail City State);
my %rec;
return unless $key =~ /[\n ]/;
# Close the dialog if the user canceled
if ($f->getWidget('Buttons')->getField('VALUE') == 1) {
$f->setField(EXIT => 1);
return;
}
# Get the field values
foreach (@fields) { $rec{$_} = $f->getWidget($_)->getField('VALUE') };
# Make sure there's a first and last name
unless ($rec{Last} && $rec{First}) {
dialog('Error!', BTN_OK, 'The First & Last Names are required fields!',
qw(white red yellow));
return;
}
# Save the record and set the dialog to close
$records{join(', ', @rec{qw(Last First)})} = { %rec };
$f->setField(EXIT => 1);
# Update the list box on the main form
$f = $app->getForm('Main');
$f->getWidget('People')->setField(
LISTITEMS => [map { [split(', ', $_)] } sort keys %records]);
# Reset the form fields
resetfields($f);
}
__DATA__
%forms = (
MainFrm => {
TABORDER => [qw(Menu People)],
FOCUSED => 'People',
WIDGETS => {
Menu => {
TYPE => 'Menu',
MENUS => {
MENUORDER => [qw(File Record)],
File => {
ITEMORDER => [qw(Save Exit)],
Exit => \&main::quit,
Save => \&main::save,
},
Record => {
ITEMORDER => ['Add Record', 'Delete Record'],
'Add Record' => \&main::showaddrec,
'Delete Record' => \&main::delrec,
},
},
},
People => {
TYPE => 'ListBox::MultiColumn',
LISTITEMS => [],
COLUMNS => 20,
LINES => 10,
Y => 2,
X => 1,
COLWIDTHS => [10, 10],
HEADERS => [qw(Last First)],
BIGHEADER => 1,
CAPTION => 'People',
FOCUSSWITCH => "\t\n ",
OnExit => \&main::displayrec,
},
Last => {
TYPE => 'TextField',
Y => 2,
X => 24,
CAPTION => 'Last Name',
COLUMNS => 20,
},
First => {
TYPE => 'TextField',
Y => 2,
X => 46,
CAPTION => 'First Name',
COLUMNS => 20,
},
'E-mail' => {
TYPE => 'TextField',
Y => 5,
X => 24,
CAPTION => 'E-mail',
COLUMNS => 42,
},
City => {
TYPE => 'TextField',
Y => 8,
X => 24,
CAPTION => 'City',
COLUMNS => 38,
},
State => {
TYPE => 'TextField',
Y => 8,
X => 64,
( run in 1.732 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )