line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TextDialog;
|
2
|
|
|
|
|
|
|
$VERSION=0.01;
|
3
|
1
|
|
|
1
|
|
7576
|
use vars qw($VERSION @EXPORT_OK);
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
79
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Tk::TextDialog - Dialog widget with text entry.
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Tk;
|
12
|
|
|
|
|
|
|
use Tk::TextDialog;
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$d = $w -> TextDialog ( -font => [-family=>'helvetica',-size=>12, -weight=>'normal'],
|
15
|
|
|
|
|
|
|
-title => 'Text Entry',
|
16
|
|
|
|
|
|
|
-textlabel => 'Please enter your text:');
|
17
|
|
|
|
|
|
|
$d -> WaitForInput;
|
18
|
|
|
|
|
|
|
$d -> destroy;
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
The -font option defaults to helvetica 12
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
The -textlabel option prints the text of its argument in label above
|
25
|
|
|
|
|
|
|
the text entry box.
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
After WaitForInput is called, clicking on the 'Accept' button closes the dialog
|
28
|
|
|
|
|
|
|
and returns the text in the entry box.
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
The WaitForInput method does not destroy the dialog window. Instead
|
31
|
|
|
|
|
|
|
WaitForInput unmaps the dialog box from the display. To de-allocate
|
32
|
|
|
|
|
|
|
the widget, you must explicitly call $w -> destroy or $w -> DESTROY.
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Refer to the Tk::options man page for a description of options
|
35
|
|
|
|
|
|
|
common to all Perl/Tk widgets.
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Example:
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use Tk;
|
40
|
|
|
|
|
|
|
use Tk::TextDialog;
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $w = new MainWindow;
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $b = $w -> Button (-text => 'Dialog',
|
45
|
|
|
|
|
|
|
-command => sub{&show_dialog($w)}) -> pack;
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub show_dialog {
|
48
|
|
|
|
|
|
|
my ($w) = @_;
|
49
|
|
|
|
|
|
|
my $e;
|
50
|
|
|
|
|
|
|
if (not defined $e) {
|
51
|
|
|
|
|
|
|
$e = $w -> TextDialog (-title => 'Enter Text', -height=>5, -width=>20); # Height and width of the text box
|
52
|
|
|
|
|
|
|
$e -> configure (-textlabel => 'Please enter your text:');
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
my $resp = $e -> WaitForInput;
|
55
|
|
|
|
|
|
|
print "$resp\n";
|
56
|
|
|
|
|
|
|
$e -> configure (-textlabel => '');
|
57
|
|
|
|
|
|
|
my $resp = $e -> WaitForInput;
|
58
|
|
|
|
|
|
|
print "$resp\n";
|
59
|
|
|
|
|
|
|
return $resp;
|
60
|
|
|
|
|
|
|
}
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
MainLoop;
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 VERSION
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$Revision: 0.0.1 $
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Licensed for free distribution under the terms of the
|
69
|
|
|
|
|
|
|
Perl Artistic License.
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Written by Mark Daglish ,mark-daglish@blueyonder.co.uk>, but heavily copied from the EntryDialog module written
|
72
|
|
|
|
|
|
|
by Robert Allan Kiesling and Dave Scheck .
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut
|
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
1
|
|
2221
|
use Tk;
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
use strict;
|
78
|
|
|
|
|
|
|
use Carp;
|
79
|
|
|
|
|
|
|
use base qw(Tk::Toplevel);
|
80
|
|
|
|
|
|
|
use Tk::widgets qw(Text Button);
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Construct Tk::Widget 'TextDialog';
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub Accept {$_[0]->{Configure}{-accept} += 1}
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub Cancel {
|
87
|
|
|
|
|
|
|
$_[0]->delete('0.1','end');
|
88
|
|
|
|
|
|
|
$_[0] -> {Configure}{-accept} += 1;
|
89
|
|
|
|
|
|
|
}
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub textlabel {
|
92
|
|
|
|
|
|
|
my $w = $_[0];
|
93
|
|
|
|
|
|
|
my $text = $_[1];
|
94
|
|
|
|
|
|
|
if (defined $text and length ($text)) {
|
95
|
|
|
|
|
|
|
my $l1 = $w->Subwidget('Frame')->Component(Label=>'textlabel', -textvariable=>\$w->{Configure}{-textlabel}, -font=>$w->{Configure}{-font});
|
96
|
|
|
|
|
|
|
$l1->pack( -padx=>5, -pady=>5, -side=>'top');
|
97
|
|
|
|
|
|
|
$w->Advertise('textlabel' => $l1);
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$w->Subwidget('text')->pack( -side=>'top', -expand=>1, -fill=>'both');
|
100
|
|
|
|
|
|
|
$w->Subwidget('acceptbutton')->pack( -padx=>5, -pady=>5, -side=>'left');
|
101
|
|
|
|
|
|
|
$w->Subwidget('cancelbutton')->pack( -padx=>5, -pady=>5, -side=>'right');
|
102
|
|
|
|
|
|
|
} else {
|
103
|
|
|
|
|
|
|
$w->Subwidget('textlabel')->destroy if defined $w->Subwidget('textlabel');
|
104
|
|
|
|
|
|
|
}
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub height {
|
108
|
|
|
|
|
|
|
my ($cw,$h) = @_;
|
109
|
|
|
|
|
|
|
$cw->Subwidget('text')->configure(-height=>$h) if (defined($h));
|
110
|
|
|
|
|
|
|
}
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub width {
|
113
|
|
|
|
|
|
|
my ($cw,$w) = @_;
|
114
|
|
|
|
|
|
|
$cw->Subwidget('text')->configure(-width=>$w) if (defined($w));
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub foreground {
|
118
|
|
|
|
|
|
|
my ($cw,$fg)=@_;
|
119
|
|
|
|
|
|
|
$cw->Subwidget('text')->configure(-foreground=>$fg) if (defined($fg));
|
120
|
|
|
|
|
|
|
}
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub background {
|
123
|
|
|
|
|
|
|
my ($cw,$bg) = @_;
|
124
|
|
|
|
|
|
|
$cw->Subwidget('text')->configure(-background=>$bg) if (defined($bg));
|
125
|
|
|
|
|
|
|
}
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub Populate {
|
128
|
|
|
|
|
|
|
my ($w,$args) = @_;
|
129
|
|
|
|
|
|
|
require Tk::Button;
|
130
|
|
|
|
|
|
|
require Tk::Toplevel;
|
131
|
|
|
|
|
|
|
require Tk::Label;
|
132
|
|
|
|
|
|
|
require Tk::Text;
|
133
|
|
|
|
|
|
|
$w->SUPER::Populate($args);
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
$w->ConfigSpecs( -font => ['ADVERTISED','font','Font',[-family=>'helvetica', -size=>12, -weight=>'normal']],
|
136
|
|
|
|
|
|
|
-textlabel => ['METHOD',undef,undef,''],
|
137
|
|
|
|
|
|
|
-accept => ['PASSIVE',undef,undef,0],
|
138
|
|
|
|
|
|
|
-height => ['METHOD',undef,undef,5],
|
139
|
|
|
|
|
|
|
-width => ['METHOD',undef,undef,20],
|
140
|
|
|
|
|
|
|
-foreground => ['METHOD',undef,undef,'black'],
|
141
|
|
|
|
|
|
|
-background => ['METHOD',undef,undef,'white'] );
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$w->withdraw;
|
144
|
|
|
|
|
|
|
my $f = $w->Component(Frame =>'Frame');
|
145
|
|
|
|
|
|
|
$f->pack(-side=>'top');
|
146
|
|
|
|
|
|
|
$w->configure(-textlabel=>$args->{-textlabel}) if (defined $args->{-textlabel} and length ($args->{-textlabel}));
|
147
|
|
|
|
|
|
|
$args->{-height}=5 unless defined($args->{-height});
|
148
|
|
|
|
|
|
|
$args->{-width}=20 unless defined($args->{-width});
|
149
|
|
|
|
|
|
|
$args->{-foreground}='black' unless defined($args->{-foreground});
|
150
|
|
|
|
|
|
|
$args->{-background}='white' unless defined($args->{-background});
|
151
|
|
|
|
|
|
|
my $e1 = $w->Component(Text => 'text', -delegate=>['get', 'delete'], -height=>$args->{-height}, -width=>$args->{-width}, -foreground=>$args->{-foreground}, -background=>$args->{-background});
|
152
|
|
|
|
|
|
|
$e1->pack(-side=>'top', -fill=>'both', -expand=>1);
|
153
|
|
|
|
|
|
|
$w -> Advertise ('text' => $e1);
|
154
|
|
|
|
|
|
|
my $b1 = $w -> Component (Button => 'acceptbutton',
|
155
|
|
|
|
|
|
|
-text => 'Accept',
|
156
|
|
|
|
|
|
|
-default => 'active' );
|
157
|
|
|
|
|
|
|
$b1->pack( -padx=>5, -pady=>5, -side=>'left');
|
158
|
|
|
|
|
|
|
$b1->bind('', sub {$w -> Accept});
|
159
|
|
|
|
|
|
|
$b1->focus;
|
160
|
|
|
|
|
|
|
my $b2 = $w->Component(Button => 'cancelbutton',
|
161
|
|
|
|
|
|
|
-text => 'Cancel',
|
162
|
|
|
|
|
|
|
-command => sub{$w -> Cancel},
|
163
|
|
|
|
|
|
|
-default => 'normal' );
|
164
|
|
|
|
|
|
|
$b2->pack( -padx=>5, -pady=>5, -side=>'right');
|
165
|
|
|
|
|
|
|
return $w;
|
166
|
|
|
|
|
|
|
}
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub WaitForInput {
|
169
|
|
|
|
|
|
|
my ($w, @args) = @_;
|
170
|
|
|
|
|
|
|
$w -> Popup (@args);
|
171
|
|
|
|
|
|
|
$w -> waitVariable(\$w->{Configure}{-accept});
|
172
|
|
|
|
|
|
|
$w -> withdraw;
|
173
|
|
|
|
|
|
|
return $w->get('0.1','end');
|
174
|
|
|
|
|
|
|
}
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1;
|