Curses-Devkit

 view release on metacpan or  search on metacpan

fulldemo/cdkdemo  view on Meta::CPAN

#!../../../perl

#
# Purpose:
#	This script demonstrates the Cdk widget set and how you can use them.
#

#
# Use the Cdk module.
#
use Cdk;
Cdk::init();

# Set up the label rows.
my @titleMessage = ("<C></5>This is a CDK demo script<!5>",
			"<C></5>It will demonstrate all of the<!5>",
			"<C></5>widgets available with the<!5>",
			"<C></5/U>Cdk Perl 5 extension.<!5>");

# Create the title.
my $title = new Cdk::Label ('Message' => \@titleMessage, 'Box'  => "FALSE");

# Set some global vars
my $CONTINUE	= "</B/48>Press Any Key To Continue.<!B!48>";
my $HOME	= $ENV{'HOME'};

# Create the menu.
my $currentLoc	= 0;
my @mLoc	= ("Switch to Pull-Up Menu  ", "Switch to Pull-Down Menu");
my @fMenu	= ("</5>File<!5>", "</5>Quit<!5>");

my @iMenu	= ("</5>Info<!5>",
			"</5>Calendar        <!5>",
			"</5>Date            <!5>",
			"</5>Label           <!5>",
			"</5>Scrolling Window<!5>",
			"</5>Viewer          <!5>");

my @eMenu	= ("</5>Entry<!5>",
			"</5>Entry Field              <!5>",
			"</5>Item List                <!5>",
			"</5>Matrix                   <!5>",
			"</5>Multiple Line Entry Field<!5>",
			"</5>Scale                    <!5>",
			"</5>Slider                   <!5>",
			"</5>Template                 <!5>");

my @lMenu	= ("</5>Lists<!5>",
			"</5>Alpha List    <!5>",
			"</5>Dialog        <!5>",
			"</5>Radio List    <!5>",
			"</5>Scrolling List<!5>",
			"</5>Selection List<!5>");

my @mMenu	= ("</5>Misc<!5>",
			"</5>Histogram               <!5>",
			"</5>Graph                   <!5>",
			"</5>Marquee                 <!5>",
			"</5>Menu                    <!5>",
			"</5>$mLoc[$currentLoc]");

my @hMenu	= ("</5>Help<!5>",
			"</5>General Help<!5>",
			"</5>Widget Help <!5>",
			"</5>About...    <!5>");

# Create the pulldown menu menu lists.
my @menulist = (\@fMenu, \@iMenu, \@eMenu, \@lMenu, \@mMenu, \@hMenu);

# Set the location of the menus
my @menuloc = ("LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "RIGHT");

# Create the menu
my $menu = new Cdk::Menu ('Menulist' => \@menulist, 'Menuloc' => \@menuloc);

# Create the callback for the menu.
$menu->bind ('Key' => '?', 'Function' => sub { main::menuCallback($menu); });

# Create the scrolling window.
my $swindow = new Cdk::Swindow ('Title' => "<C></U>Menu Selection History<!U>",
				'Lines' => 200,
				'Height' => 6,
				'Width' => 60,
				'Ypos' => "BOTTOM");
my $menuItemCount = 0;

# Let the user play.
for (;;)
{
   # Redraw the screen.
   Cdk::refreshCdkScreen();

   # Get the selection.
   my ($submenu, $submenuItem) = $menu->activate();
   my $menuSelection = $menulist[$submenu]->[$submenuItem];

   # I'm going to use the name, instead of the numeric value to
   # determine what was picked. But either way is acceptable.
   if ($menuSelection =~ "Label")
   {
      my @mesg	= ("<C></B/32>You just selected the Cdk label widget<!B!32>",
			"<C></B/32>demo. The labels have many personalities<!B!32>",
			"<C></B/32>To discover them all, use the help option<!B!32>",
			"<C></B/32>and pick the Label item.<!B!32>", "",
			"<C>$CONTINUE");
      labelDemo (@mesg);
   }
   elsif ($menuSelection =~ "Calendar")
   {
      itemlistDemo();
   }
   elsif ($menuSelection =~ "Date")
   {
      my $date	= qx (date); chomp $date;
      my @mesg	= ("<C>The current time is:", "",
			"<C></B/24>$date<!B!24>", "",
			"<C>$CONTINUE");
      labelDemo (@mesg);
   }
   elsif ($menuSelection =~ "Scrolling Window")
   {
      # Put a message inside the scrolling window.
      $swindow->addline ('Info' => "<C></R>This is the scrolling window.<!R> It's purpose");
      $swindow->addline ('Info' => "<C>is to act as an information window. It also");
      $swindow->addline ('Info' => "<C>has the ability to display </15>colors<!15>");
      $swindow->addline ('Info' => "<C>and </B>attributes<!B>.");
      $swindow->addline ('Info' => "<C>Hit return, tab, or escape to exit this window.");
      $swindow->activate();
   }
   elsif ($menuSelection =~ "Viewer")
   {
      viewerDemo();
   }
   elsif ($menuSelection =~ "Multiple Line Entry Field")
   {
      mentryDemo();
   }
   elsif ($menuSelection =~ "Entry Field")
   {
      entryDemo();
   }
   elsif ($menuSelection =~ "Item List")
   {
      itemlistDemo();
   }
   elsif ($menuSelection =~ "Template")
   {
      templateDemo();
   }
   elsif ($menuSelection =~ "Matrix")
   {
      matrixDemo();
   }
   elsif ($menuSelection =~ "$mLoc[$currentLoc]")
   {
      # We are going to switch the menu type.
      if ($currentLoc == 0)
      {
         # Pull-Down to Pull-Up
         $currentLoc = 1;
         @mMenu = ("</5>Misc<!5>",
			"</5>Histogram               <!5>",
			"</5>Graph                   <!5>",
			"</5>Marquee                 <!5>",
			"</5>Menu                    <!5>",
			"</5>$mLoc[$currentLoc]");
         @menulist = (\@fMenu, \@iMenu, \@eMenu, \@lMenu, \@mMenu, \@hMenu);
         undef $menu;
         $menu = new Cdk::Menu ('Menulist' => \@menulist,
				'Menuloc' => \@menuloc,
				'Tattrib' => $highlight,
				'Menupos' => "BOTTOM",
				'SubTattrib' => $highlight);
      }
      elsif ($currentLoc == 1)
      {
         # Pull-Up to Pull-Down
         $currentLoc = 0;
         @mMenu = ("</5>Misc<!5>",
			"</5>Histogram               <!5>",
			"</5>Graph                   <!5>",
			"</5>Marquee                 <!5>",
			"</5>Menu                    <!5>",
			"</5>$mLoc[$currentLoc]");
         @menulist = (\@fMenu, \@iMenu, \@eMenu, \@lMenu, \@mMenu, \@hMenu);
         undef $menu;
         $menu = new Cdk::Menu ('Menulist' => \@menulist,
				'Menuloc' => \@menuloc,
				'Tattrib' => $highlight,
				'Menupos' => "TOP",
				'SubTattrib' => $highlight);
      }
   }
   elsif ($menuSelection =~ "Menu")
   {
      # Pop up a message stating what we got.
      my @mesg	= ("<C>The Cdk Menu widget is what",
			"is driving this application.", "",
			"<C>$CONTINUE");
      labelDemo (@mesg);
   }
   elsif ($menuSelection =~ "Dialog")
   {
      dialogDemo();
   }
   elsif ($menuSelection =~ "Scrolling List")
   {
      scrollDemo();
   }
   elsif ($menuSelection =~ "Selection List")
   {
      selectionDemo();
   }
   elsif ($menuSelection =~ "Radio List")
   {
      radioDemo();
   }
   elsif ($menuSelection =~ "Histogram")
   {
      histogramDemo();
   }
   elsif ($menuSelection =~ "Graph")
   {
      graphDemo();
   }
   elsif ($menuSelection =~ "Scale")
   {
      scaleDemo();
   }
   elsif ($menuSelection =~ "Slider")
   {
      sliderDemo();
   }
   elsif ($menuSelection =~ "Marquee")
   {
      marqueeDemo();
   }
   elsif ($menuSelection =~ "Alpha List")
   {
      alphalistDemo();
   }
   elsif ($menuSelection =~ "General Help")
   {
      generalHelp();
   }
   elsif ($menuSelection =~ "Widget Help")
   {
      widgetHelp();
   }
   elsif ($menuSelection =~ "About...")
   {
      # Pop up a message about this script.
      my @mesg	= ("<C></U/40>Cdk Perl 5 Extension<!U!40>",
			"<C></32>Written by Mike Glover<!32>", "",
			"</16>Created     : December, 1995<!16>", 
			"</16>Last Updated: April, 1997<!16>", "",
			$CONTINUE);

fulldemo/cdkdemo  view on Meta::CPAN

			"<C>$CONTINUE");
          labelDemo (@error);
      }
      else
      {
         # Display the file.
         my @info = ();
         undef $helpviewer;
         my $helpviewer = new Cdk::Viewer ('Buttons' => ["OK"],
						'Height' => $rows-3,
						'Width' => $cols-2);

          chop (@info = `cat $helpfile`);
          $helpviewer->set ('Title' => "<C></18>Help: </U>$topic<!18U>",
				   'Info' => \@info);
          $helpviewer->activate();
      }
   }
}

sub widgetHelp
{
   my ($helpfile, $topic, $helpviewer);
   my $helpdir		= $ENV{'CDKHELPDIR'}	|| "./help";

   # Define the widget help files.
   my @helpFiles = ("alphalist.help",
			"calendar.help",
			"dialog.help",
			"entry.help",
			"fselect.help",
			"graph.help",	
			"histogram.help",
			"itemlist.help",
			"label.help",
			"marquee.help",
			"matrix.help",
			"menu.help",
			"mentry.help",
			"radio.help",
			"scale.help",
			"scroll.help",
			"swindow.help",
			"selection.help",
			"slider.help",
			"template.help",
			"viewer.help");

   # Define the widget help entries.
   my @widgetList = ("</B/40>Alphalist Widget             <!40>",
			"</B/40>Calendar Widget             <!40>",
			"</B/40>Dialog Widget               <!40>",
			"</B/40>Entry Field Widget          <!40>",
			"</B/40>File Selector Widget        <!40>",
			"</B/40>Graph Widget                <!40>",
			"</B/40>Histogram Widget            <!40>",
			"</B/40>Item List Widget            <!40>",
			"</B/40>Label Widget                <!40>",
			"</B/40>Marquee Widget              <!40>",
			"</B/40>Matrix Widget               <!40>",
			"</B/40>Menu Widget                 <!40>",
			"</B/40>Multiple Line Entry Widget  <!40>",
			"</B/40>Radio List Widget           <!40>",
			"</B/40>Scale Widget                <!40>",
			"</B/40>Scrolling List Widget       <!40>",
			"</B/40>Scrolling Window Widget     <!40>",
			"</B/40>Selection List Widget       <!40>",
			"</B/40>Slider Widget               <!40>",
			"</B/40>Template Widget             <!40>",
			"</B/40>Viewer Widget               <!40>",
			"</B/40>Exit Help                   <!40>");

   # Get the screen dimensions.
   my ($rows, $cols) = Cdk::getCdkScreenDim();

   # Create the scrolling list ...
   my $helplist	= new Cdk::Scroll ('Title' => "<C></U/B/29>Pick A Topic",
					'Highlight' => "</R>",
					'List' => \@widgetList,
					'Numbers' => "TRUE",
					'Height' => $#widgetList+4,
					'Width' => 40);

   # Keep doing this until we are told to leave.
   for (;;)
   {
      # Redraw the screen.
      Cdk::refreshCdkScreen();

      my $choice = $helplist->activate();
   
      # Exit if we have to .
      return if ! defined $choice;
      return if ($choice == $#widgetList);

      # Create the help filename
      $helpfile = "${helpdir}/$helpFiles[$choice]";
      $topic = "$widgetList[$choice]";
   
      # Does the help file exist?
      if (! -e $helpfile)
      {
         my @error = (
			"<C></16>Can not seem to find the help file on the topic </U>$topic<!U><!16>",
			"<C></16>Try setting the CDKHELPDIR environment variable<!16>",
			"<C></16>or check if the help file '$helpfile' exists<!16>", "",
			"<C>$CONTINUE");
         labelDemo (@error);
      }
      else
      {
         # Display the file.
         my @info = ();
         my $helpviewer = new Cdk::Viewer ('Buttons' => ["OK"],
							'Height' => $rows-3,
							'Width' => $cols-2);
         chop (@info = `cat $helpfile`);
         $helpviewer->set ('Title' => "<C></18>Help: </U>$topic<!18U>",
				   'Info' => \@info);
         $helpviewer->activate();
      }



( run in 0.682 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )