EAFDSS

 view release on metacpan or  search on metacpan

examples/TypeA/OpenEAFDSS-TypeA.pl  view on Meta::CPAN

#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ID: $Id: OpenEAFDSS-TypeA.pl 105 2009-05-18 10:52:03Z hasiotis $

use strict;
use Config::IniFiles;
use Data::Dumper;
use Curses::UI;
use DBI;
use EAFDSS; 


my($cfg) = Config::IniFiles->new(-file => "/etc/OpenEAFDSS/OpenEAFDSS-TypeA.ini", -nocase => 1);

my($ABC_DIR) = $cfg->val('MAIN', 'ABC_DIR', '/tmp/signs');
my($SQLITE)  = $cfg->val('MAIN', 'SQLITE', '/tmp/eafdss.sqlite');

my($SN)      = $cfg->val('DEVICE', 'SN', 'ABC02000001');
my($DRIVER)  = $cfg->val('DEVICE', 'DRIVER', 'SDNP');
my($PARAM)   = $cfg->val('DEVICE', 'PARAM', 'localhost');

my(%reply);
my($cui) = new Curses::UI(
			-clear_on_exit  => 1,
			-color_support  => 1,
			-fg             => 'white',
			-bg             => 'blue',
		);

my($menuFile) = [
	{ -label => ' Settings  ^S', -value => \&settingsDialog },
	{ -label => ' Exit      ^Q', -value => \&exitDialog     }
];
my($menuTypeA) = [
	{ -label => ' Issue Z Report ',   -value => \&issueReportDialog   },
	{ -label => ' Browse Invoices',   -value => \&browseInvoiceDialog },
	{ -label => ' Search Invoices',   -value => \&searchInvoiceDialog },
	{ -label => ' Check A,B,C Files', -value => \&checkABCDialog      },
];
my($menuTools) = [
	{ -label => ' Get Status     ', -value => \&getStatusDialog      },
	{ -label => ' Get Headers    ', -value => \&getHeadersDialog     },
	{ -label => ' Set Headers    ', -value => \&setHeadersDialog     },
	{ -label => ' Read Time      ', -value => \&readTimeDialog       },
	{ -label => ' Set Time       ', -value => \&setTimeDialog        },
	{ -label => ' Version Info   ', -value => \&versionInfoDialog    },
];
my($menuHelp) = [
	{ -label => ' Help ', -value => \&helpDialog },
	{ -label => ' About', -value => \&aboutDialog }
];
my($menuBar) = [
	{ -label => 'File',   -submenu => $menuFile  },
	{ -label => 'Type A', -submenu => $menuTypeA },
	{ -label => 'Tools',  -submenu => $menuTools },
	{ -label => 'Help',   -submenu => $menuHelp  }
]; 

my($menu) = $cui->add( 'menu', 'Menubar', -menu => $menuBar);

my($statusBar) = $cui->add( 'statusbar_win', 'Window', -height => 4, -y => -1);
my($status) = $statusBar->add(
	'status_text', 'TextViewer',
	-text		=> " ^X:Menu | OpenEAFDSS Type A *example* Solution Utility",
	-padtop		=> 2,
	-width		=> 180,
	-fg             => 'white',
	-bg             => 'blue',
);

$cui->set_binding(sub {$menu->focus()},     "\cX");
$cui->set_binding( \&settingsDialog,        "\cS");
$cui->set_binding( \&exitDialog,            "\cQ");

$cui->mainloop();

sub exitDialog {
	my($return) = $cui->dialog(
			-fg  => 'cyan', -bg  => 'black',
			-tfg => 'blue', -tbg => 'cyan',
			-bfg => 'blue', -bbg => 'black',
			-message   => "Do you really want to quit?",
			-title     => "[ EXIT ]", 
			-buttons   => ['yes', 'no'],
		);
	exit(0) if $return;
}

sub issueReportDialog {
	my($dh) = loadDriverHandle();

	my($result) = $dh->Report();
	if ($result) {
		$cui->dialog(
			-fg  => 'cyan', -bg  => 'black',
			-tfg => 'blue', -tbg => 'cyan',
			-bfg => 'blue', -bbg => 'black',
			-title => "Z Report",
			-message => $result
		);
	} else {
		my($errNo)  = $dh->error();
		my($errMsg) = $dh->errMessage($errNo);
		$cui->dialog(
			-fg  => 'cyan', -bg  => 'black',
			-tfg => 'blue', -tbg => 'cyan',
			-bfg => 'blue', -bbg => 'black',
			-title => "Error producing Z report",
			-message => sprintf("ERROR [0x%02X]: %s\n", $errNo, $errMsg)
		)
	}
}

sub settingsDialog {
	my($winSettings) = $cui->add(
		'winSettings', 'Window',
		-title		=> 'Device Settings',
		-width          => 60,
		-height         => 23,
		-border         => 1,
		-padtop         => 2,
		-padbottom      => 2,
		-padleft        => 2,
		-padright       => 2,



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