PerlVision

 view release on metacpan or  search on metacpan

lib/PerlVision.pm  view on Meta::CPAN

  my $dialog = new PerlVision::Dialog ("",$x1,$y1,$x2,$y2,1,1,
			       $yes,1,1,2,1,1,1,2,0,
			       $no,2,2,2,1,2,2,1,0,
			       $viewbox,0,0,0,0,0,0,0,0);
  my $stat=($dialog->activate)[0];
  ($stat==2) && ($stat=0);
  return $stat;
}

sub entry {
  my ($message,$width,$depth,$entrysize,$nohide)=@_;
  my ($maxheight,$maxwidth); getmaxyx($maxheight, $maxwidth);
  my @message=split("\n",$message);
  ($width<21) && ($width=21);
  $depth+=5;
  my $x1=int (($maxwidth-$width)/2+1);
  my $y1=int (($maxheight-$depth)/2);
  my $x2=$x1+$width;
  my $y2=$y1+$depth+1;
  my $viewbox = new PerlVision::Viewbox(2,1,$width-2,3,$message,0);
  my $static=new PerlVision::Static($message,2,1,$x2-$x1,$y2-$y1-4);
  my $entry = new PerlVision::Entryfield (($width-$entrysize)/2-2, 5, $entrysize, 256, " ", "");
  my $yes = new PerlVision::Cutebutton ("  OK   ",int($width/2)-13,$y2-$y1-2);
  my $no = new PerlVision::Cutebutton (" CANCEL ",int($width/2)+3,$y2-$y1-2);
  my $dialog = new PerlVision::Dialog ("",$x1,$y1,$x2,$y2,1,1,
			       $entry,1,2,1,1,1,1,2,2,
			       $yes,1,2,3,1,2,2,3,0,
			       $no,1,3,3,2,3,3,1,0,
			       $viewbox,0,0,0,0,0,0,0,0);
  my $stat=($dialog->activate($nohide))[0];
  if ($stat==3) { $stat=0 } else { $stat = $entry->stat }
  return $stat;
}

'True Value'

__END__

=head1 NAME

PerlVision - Text-mode User Interface Widgets.

=head1 SYNOPSIS

  use PerlVision;

  init PerlVision;

  my ($width, $height) = (50,1);
  my $dialog = new PerlVision::PVD::yesno ("Yes or no?", $width, $height);
  my $answer = $dialog->activate;

  PerlVision::done;

=head1 DESCRIPTION

PerlVision provides various text-mode user interface widgets,
including checkboxes, radiobuttons, pushbuttons, single and multiple
selection listboxes, an extensible editbox, a scrollable viewbox,
single line text entry fields, a menubar with pulldown menus, and
popup dialog boxes with multiple controls.

=head1 CLASSES

The following object classes are defined within PerlVision:

=over 2

=item L</PerlVision>

Not a widget. Provides a few important class methods.

=item L</PerlVision::Static>

A static text control.

=item L</PerlVision::Checkbox>

A single 2-state checkbox.

=item L</PerlVision::Radio>

A single 2-state radiobutton.

=item L</PerlVision::RadioG>

A group of connected radiobuttons.

=item L</PerlVision::Listbox>

A single selection list box.

=item L</PerlVision::Mlistbox>

A multiple selection list box.

=item L</PerlVision::Entryfield>

A single line text entry field.

=item L</PerlVision::Password>

A single line text entry field that echoes '*' to conceal the input.

=item L</PerlVision::Menubar>

A top line menu bar with single-level pulldown submenus.

=item L</PerlVision::Editbox>

A multi-line edit box.

=item L</PerlVision::Viewbox>

A readonly viewer/pager for text files.

=item L</PerlVision::Pushbutton>

A push button that uses 3 lines of screen real estate.

=item L</PerlVision::Cutebutton>

lib/PerlVision.pm  view on Meta::CPAN


  my $button1 = new PerlVision::Pushbutton ("Label", $x1, $y1);
  my $button2 = new PerlVision::Cutebutton ("Label", $x1, $y1);
  my $button3 = new PerlVision::Plainbutton ("Label", $x1, $y1);

Makes a push button of the specified type.

  $button1->display();    # Displays it.
  $button1->activate();   # Activates it.

Exits on codes 1,2,3,4,5,6,7,8. On 8, it 'depresses' and it's up to
you to 'undepress' it by calling the C<display> method.

C<PerlVision::Pushbutton> is BIG. It uses 3 lines on the
screen. C<PerlVision::Cutebutton> is smaller - it uses only two lines, and
'depresses' when clicked. C<PerlVision::Plainbutton> is a basic one-line
button which does nothing fancy but is useful in some situations
(e.g. for hypertext links).

=item B<PerlVision::Dialog>

A dialog box with multiple controls.

This is the widget that brings other controls together, and manages
focus switching between multiple controls. Once you've created all the
controls you need, you can add them to a C<PerlVision::Dialog> object to
create a functional UI panel.

C<PerlVision::Dialog> uses the return code from each control's activate method
do decide how to switch focus between controls. The activate method
for all controls returns an exit code when focus is released. This is
what these codes mean:

1 = Up Arrow            (Traditional shift-focus key)

2 = Down Arrow          (Traditional shift-focus key)

3 = Right Arrow         (Traditional shift-focus key)

4 = Left Arrow          (Traditional shift-focus key)

5 = M-h                 (For  help)

6 = M-x                 (For menu)

7 = Tab                 (Traditional shift-focus key)

8 = Enter               (Traditional 'Done here' key)

These codes are used by the C<PerlVision::Dialog> control to figure out how to
switch focus between controls, and when to exit. Here's how to create
a C<PerlVision::Dialog> object:

  $dialog = new PerlVision::Dialog ("Title", $x1, $y1, $x2, $y2, $style, $color,
                            $control1, 1, 2, 2, 1, 1, 1, 2, 0,
                            $control2, 1, 3, 3, 1, 2, 2, 3, 0,
                            ...);

C<"Title"> is currently ignored.

C<$style>: if 1, creates a popup that is 'raised'. if 0, creates a
popup that is 'depressed'

C<$color> is the background color for the dialog. I'd recommend 6
(cyan) because of the overall hardcoded nature of colors at present.

C<$control*> are C<PerlVision::*> objects that you created beforehand They
can't be C<PerlVision::Menubar> objects. Note that the controls must be
positioned relative to the origin (top left) of the dialog box, not
relative to the screen origin.

How the dialog box works is that the control+exitcode matrix tells
C<PerlVision::Dialog> which control to switch focus to on each of the 8 exit
codes listed above. So when you do a:

  $dialog->activate;

C<PerlVision::Dialog> starts off by displaying itself and giving focus to
C<$control1>. When C<$control1> exits, C<$dialog> looks in the list
that follows C<$control1> in the constructor syntax above to figure
out which control to give focus to next. The list is simply numbers
that say which control. So 1 represents C<$control1>, 2 represents
C<$control2>, and so on, based on the order in which the controls
appear in the constructor invocation.

The special value 0 is reserved to tell C<PerlVision::Dialog> to exit and hide
the dialog box. I also use it as a place-holder for those exit-codes
that a certain control never returns, for example of C<$control1>
above was a C<PerlVision::Editbox>, I'd put 0's in the list following
C<$control1> at positions 1,2,3 and 4 because the edit box object
never exits on those codes (those keys have meaning within the
editbox)

If you don't want focus to switch off a control when a certain
exitcode is returned, simply put that control's own number in the
corresponding position in the list.

Look in the C<rap> code for an example of C<PerlVision::Dialog> use, the
C<$options> object.

When C<PerlVision::Dialog>'s C<activate> method exits, it returns a
two-element list. The first element tells you which was the last
control to be active (again numbered as they appear in the constructor
invocation), and the second element tells you what exitcode that
control returned.

After the dialog box has exited, you can call C<stat> on each control
to determine its status. Remember, don't put C<PerlVision::RadioG> controls in
a dialog box; they don't have an activate method. Put the
corresponding C<PerlVision::Radio> controls in. When you call C<stat>, call it on
the C<PerlVision::RadioG> object.

Also, don't put a C<PerlVision::Static> as the first control in a
C<PerlVision::Dialog>. It doesn't have an activate method. If you just want a
pop-up box with text and no other controls, you could use a
C<PerlVision::Viewbox control>.

=item B<PerlVision::PVD>

PerlVision also defines three often needed dialog box styles:

=over



( run in 0.780 second using v1.01-cache-2.11-cpan-364913b4093 )