Hello Perl Monks,
i would like to write a console GUI in perl. To get started, i want to learn how to display just two Fields named First Name and Last Name, and once the User has entered some data into them and presses Enter (or hits a Button), basically the data he entered into that Field gets read into two Variables, so i can process them, check Input, etc.
Right now here is what i have, taken from the demo-widgets File that came with Curses::UI. I can display a Field, but i have no Idea how to get the Data out.
If someone could help me enhance the Code would be really really great. Additionally, i would like to ask if anyone can recommend a Good Online Course, Tutorial or Howto, Resource, or ideally a Book that has at least one Section showing how to use Curses::UI to build console GUI Applications with Perl.
Thanks for any Suggestions,
regards
#!/usr/bin/perl -w
use strict;
use File::Temp qw( :POSIX );
use FindBin;
use Curses::UI;
my $cui = new Curses::UI (
-clear_on_exit => 1,
-debug => 0,
);
my $current_demo = 1;
my %w = ();
sub select_demo($;)
{
my $nr = shift;
$current_demo = $nr;
$w{$current_demo}->focus;
}
my $file_menu = [
{ -label => 'Quit program',-value => sub {exit(0)}},
],
my $demo_menu = [
{ -label => 'Adding a User',-value => sub{select_demo(1)}},
];
my $menu = [
{ -label => 'File',-submenu =>$file_menu},
{ -label => 'Select demo',-submenu =>$demo_menu},
];
$cui->add('menu', 'Menubar', -menu => $menu);
my $w0 = $cui->add(
'w0', 'Window',
-border => 1,
-y => -1,
-height => 3,
);
$w0->add('explain', 'Label',
-text => "CTRL+X: menu CTRL+Q: quit"
);
my %screens = (
'1' => 'Adding a User',
);
my @screens = sort {$a<=>$b} keys %screens;
my %args = (
-border => 1,
-titlereverse => 0,
-padtop => 2,
-padbottom => 3,
-ipad => 1,
);
while (my ($nr, $title) = each %screens)
{
my $id = "window_$nr";
$w{$nr} = $cui->add(
$id, 'Window',
-title => "$title ($nr/" . @screens . ")",
%args
);
}
#Here is where it starts
my $rfid;
my $emp_id;
$w{1}->add(
undef, 'Label', -y => -20,
-text => "Employee ID",
-width => 20,
);
$w{1}->add(
#undef, 'TextEntry',
$emp_id, 'TextEntry',
-sbborder => 1,
-y => -20,
-x => 21,
-width => 20,
);
# Setup bindings and focus
# Bind <CTRL+Q> to quit.
$cui->set_binding( sub{ exit }, "\cQ" );
# Bind <CTRL+X> to menubar.
$cui->set_binding( sub{ shift()->root->focus('menu') }, "\cX" );
$w{$current_demo}->focus;
# Get things rolling...
$cui->mainloop;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.