File: demo-add

package info (click to toggle)
libcurses-ui-perl 0.9609-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,312 kB
  • sloc: perl: 12,464; makefile: 2
file content (102 lines) | stat: -rwxr-xr-x 2,037 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/perl -w
# 2004 (c) by Marcus Thiesen (marcus@thiesen.org)
# This file is a part of Curses::UI and might be distributed 
# under the same terms as perl itself.

# Use the libraries from the distribution, instead of 
# system wide libraries.
use FindBin;
use lib "$FindBin::RealBin/../lib";

use strict;
use Curses::UI;
$Curses::UI::debug = 0;

my $cui = new Curses::UI( -color_support => 1 );

my $win1 = $cui->add(
		     'win1', 'Window',
		     -border => 1,
		     -y    => 1,
		     -bfg  => 'red',
		     );


$win1->add("d1", "TextEntry", 
	      -border => 0,
	      -fg => "green",
	      -x => 2 ,
	      -y => 1 ,
	      -width => 5,
	      -text => "A",
	      -focusable => 0,
	      -readonly => 1,);


my $ent1 = $win1->add("ent1", "TextEntry", 
		      -border => 1,
		      -bfg => "green",
		      -x => 10 ,
		      -width => 10);


$win1->add("d2", "TextEntry", 
	      -border => 0,
	      -fg => "blue",
	      -x => 2 ,
	      -y => 4 ,
	      -width => 5,
	      -text => "B",
	      -focusable => 0,
	      -readonly => 1,);


my $ent2 = $win1->add("ent2", "TextEntry", 
		      -border => 1, 
		      -bfg => "blue",
		      -y => 3, 
		      -x => 10,  
		      -width => 10);


$win1->add("d3", "TextEntry", 
	      -border => 0,
	      -fg => "red",
	      -x => 2 ,
	      -y => 11 ,
	      -width => 5,
	      -text => "C",
	      -focusable => 0,
	      -readonly => 1,);


my $ent3 = $win1->add("ent3", "TextEntry",
		      -border => 1,
		      -bfg => "red",
		      -y => 10,
		      -x => 10 ,
		      -width => 10,
		      -readonly => 1,
		      -focusable => 0,
		      ) ;


my $but1 = $win1->add("addbutton", "Buttonbox" ,
	   -buttons => [ { -label => "< ADD >",
			   -onpress => \&add } ] ,
		      -y => 15, -x => 5
	   );

sub add {
    if (($ent1->get() =~ /[\d.]+/) &&
	($ent2->get() =~ /[\d.]+/)) {
	$ent3->text($ent1->get() + $ent2->get());
    } else {
	$cui->error("You have to enter a number in A and B");
    }

}

$cui->set_binding( sub {exit 0;}, "q");
$cui->mainloop;