Curses-UI
view release on metacpan or search on metacpan
examples/demo-widgets view on Meta::CPAN
);
# ----------------------------------------------------------------------
# Progressbar
# ----------------------------------------------------------------------
$w{7}->add(
'progressbarlabel', 'Label',
-x => -1, -y => 3, -width => 10, -border => 1,
-text => "the time"
);
$w{7}->add(
undef, 'Label',
-text => "The progressbar can be used to provide some progress information\n"
. "to the user of a program. Progressbars can be drawn in several\n"
. "ways (see below for a couple of examples). In this example, I\n"
. "just built a kind of clock (the values for the bars are \n"
. "depending upon the current time)."
);
$w{7}->add( undef, "Label", -y => 7, -text => "Showing value");
$w{7}->add( 'p1', 'Progressbar', -max => 24,
-x => 15, -y => 6, -showvalue => 1 );
$w{7}->add( undef, "Label", -y => 10, -text => "No centerline");
$w{7}->add( 'p2', 'Progressbar', -max => 60,
-x => 15, -y => 9, -nocenterline => 1 );
$w{7}->add( undef, "Label", -y => 13, -text => "No percentage");
$w{7}->add( 'p3', 'Progressbar', -max => 60,
-x => 15, -y => 12, -nopercentage => 1 );
sub progressbar_timer_callback($;)
{
my $cui = shift;
my @l = localtime;
$w{7}->getobj('p1')->pos($l[2]);
$w{7}->getobj('p2')->pos($l[1]);
$w{7}->getobj('p3')->pos($l[0]);
$w{7}->getobj('progressbarlabel')->text(
sprintf("%02d:%02d:%02d", @l[2,1,0])
);
}
$cui->set_timer(
'progressbar_demo',
\&progressbar_timer_callback, 1
);
$cui->disable_timer('progressbar_demo');
$w{7}->onFocus( sub{$cui->enable_timer ('progressbar_demo')} );
$w{7}->onBlur( sub{$cui->disable_timer ('progressbar_demo')} );
# ----------------------------------------------------------------------
# Calendar
# ----------------------------------------------------------------------
$w{8}->add(
undef, 'Label',
-text => "The calendar can be used to select a date, somewhere between\n"
. "the years 0 and 9999. It honours the transition from the\n"
. "Julian- to the Gregorian calender in 1752."
);
$w{8}->add(
undef, 'Label',
-y => 5, -x => 27,
-text => "Use your cursor keys (or <H>, <J>, <K> and <L>)\n"
. "to walk through the calender. Press <ENTER>\n"
. "or <SPACE> to select a date. Press <SHIFT+J> to\n"
. "go one month forward and <SHIFT+K> to go one\n"
. "month backward. Press <SHIFT+L> or <N> to go one\n"
. "year forward and <SHIFT+H> or <P> to go one year\n"
. "backward. Press <T> to go to today's date. Press\n"
. "<C> to go to the currently selected date."
);
$w{8}->add(
'calendarlabel', 'Label',
-y => 14, -x => 27,
-bold => 1,
-width => -1,
-text => 'Select a date please...'
);
$w{8}->add(
'calendar', 'Calendar',
-y => 4, -x => 0,
-border => 1,
-onchange => sub {
my $cal = shift;
my $label = $cal->parent->getobj('calendarlabel');
$label->text("You selected the date: " . $cal->get);
},
);
# ----------------------------------------------------------------------
# Dialog::Basic
# ----------------------------------------------------------------------
$w{9}->add(
undef, 'Label',
-text => "Curses::UI has a number of ready-to-use dialog windows.\n"
. "The basic dialog is one of them. It consists of a dialog\n"
. "showing a message and one or more buttons. Press the\n"
. "buttons to see some examples of this."
);
$w{9}->add(
undef, 'Buttonbox',
-y => 7,
-buttons => [
{
-label => "< Example 1 >",
-onpress => sub {
shift()->root->dialog("As basic as it gets")
}
},{
-label => "< Example 2 >",
-onpress => sub {
shift()->root->dialog(
-message => "Basic, but carrying a\n"
. "title this time.",
-title => 'Dialog::Basic demo',
);
}
},{
-label => "< Example 3 >",
-onpress => sub {
my $b = shift();
my $value = $b->root->dialog(
-message => "Basic, but carrying a\n"
. "title and multiple buttons.",
-buttons => ['ok','cancel', 'yes', 'no'],
-title => 'Dialog::Basic demo',
);
$b->root->dialog(
-message => "The value for that\n"
. "button was: $value",
-title => "Value?"
);
}
}
],
);
# ----------------------------------------------------------------------
# Dialog::Error
# ----------------------------------------------------------------------
$w{10}->add(
examples/demo-widgets view on Meta::CPAN
-title => 'Progress dialog with a message',
-message => $msg,
);
for my $pos (0..700) {
$cui->setprogress($pos, $msg . $pos . " / 700");
}
$cui->setprogress(undef, "Finished counting!");
sleep 1;
$cui->noprogress;
}
}
]
);
# ----------------------------------------------------------------------
# Dialog::Status
# ----------------------------------------------------------------------
$w{13}->add(
undef, 'Label',
-text => "Curses::UI has a number of ready-to-use dialog windows.\n"
. "The Status dialog is one of them. Using this dialog\n"
. "it is possible to present some status information to\n"
. "the user. Press the buttons below for a demo."
);
$w{13}->add(
undef, 'Buttonbox',
-y => 7,
-buttons => [
{
-label => "< Example 1 >",
-onpress => sub {
$cui->status("This is a status dialog...");
sleep 1;
$cui->nostatus;
}
},{
-label => "< Example 2 >",
-onpress => sub {
$cui->status("A status dialog can contain\n"
. "more than one line, but that is\n"
. "about all that can be told about\n"
. "status dialogs I'm afraid :-)"
);
sleep 3;
$cui->nostatus;
}
}
]
);
# ----------------------------------------------------------------------
# Dialog::Calendar
# ----------------------------------------------------------------------
$w{14}->add(
undef, 'Label',
-text => "Curses::UI has a number of ready-to-use dialog windows.\n"
. "The calendar dialog is one of them. Using this dialog\n"
. "it is possible to select a date."
);
$w{14}->add( undef, 'Label', -y => 7, -text => 'Date:' );
$w{14}->add(
'datelabel', 'Label',
-width => 10,
-y => 7,
-x => 6,
-text => 'none',
);
$w{14}->add(
undef, 'Buttonbox',
-y => 7,
-x => 17,
-buttons => [
{
-label => "< Set date >",
-onpress => sub {
my $label = shift()->parent->getobj('datelabel');
my $date = $label->get;
print STDERR "$date\n";
$date = undef if $date eq 'none';
my $return = $cui->calendardialog(-date => $date);
$label->text($return) if defined $return;
}
},{
-label => "< Clear date >",
-onpress => sub {
my $label = shift()->parent->getobj('datelabel');
$label->text('none');
}
}
]
);
# ----------------------------------------------------------------------
# Dialog::Question
# ----------------------------------------------------------------------
$w{15}->add(
undef, 'Label',
-text => "Curses::UI has a number of ready-to-use dialog windows.\n"
. "The question dialog is one of them. Using this dialog\n"
. "it is possible to prompt the user to enter an answer.",
);
$w{15}->add(
undef, 'Buttonbox',
-y => 7,
-buttons => [
{
-label => "< Example 1 >",
-onpress => sub {
my $button = shift;
my $feeling = $button->root->question("How awesome are you?");
if ($feeling) {
$button->root->dialog("You answered '$feeling'");
}
else {
$button->root->dialog("Question cancelled.");
}
}
},{
-label => "< Example 2 >",
-onpress => sub {
my $button = shift;
my $feeling = $button->root->question(
-question => "How does coffee make you feel?",
-title => 'Dialog::Question example',
);
if ($feeling) {
$button->root->dialog("You answered '$feeling'");
}
else {
$button->root->dialog("Question cancelled.");
}
}
},{
-label => "< Example 3 >",
-onpress => sub {
my $button = shift;
my $feeling = $button->root->question(
-question => "How does coffee make you feel?",
( run in 0.953 second using v1.01-cache-2.11-cpan-39bf76dae61 )