5
# BEGIN { $ENV{'PERL_DL_NONLAZY'} = 1 }
9
$SIG{__DIE__} = \&Carp::confess;
15
use Tk::widgets qw(Button Label Menu Photo Optionmenu Pixmap Balloon);
16
use Tk::widgets qw(Scrollbar Checkbutton Radiobutton Entry
17
Message BrowseEntry Listbox);
27
print "$w $_ = ",$w->bind($_),"\n";
36
test_back_trace($w,$count-1);
40
$w->BackTrace("Moan");
48
while (@info = caller($i))
50
print "$i: ",join(' ',@info),"\n";
58
my $result = eval { $w->send('basic_demo',"Hi there") };
59
die "Send failed '$@'" if ($@);
60
print "Send returned '$result'\n";
67
my $f = ($scroll) ? $top->Frame() : $top;
68
my $e = $f->Entry("-relief","ridge",@_);
69
$e->pack("-side"=>"top","-fill"=>"x","-expand"=>"yes");
70
$e->bind("<Any-Enter>", sub { shift->focus() });
71
$e->bind("<Any-FocusIn>", sub { shift->configure("-relief" => "sunken") });
72
$e->bind("<Any-FocusOut>", sub { shift->configure("-relief" => "ridge" ) });
75
my $es = $f->Scrollbar(-orient=>"horizontal","-command",["view",$e], -width => '4m');
76
$e->configure("-scrollcommand",["set",$es]);
77
$es->pack("-side"=>"bottom","-fill"=>"x");
78
$f->pack("-side","top");
86
my $l = $top->ScrlListbox("-selectmode"=>"extended",-label => 'Listbox',-takefocus => 1);
89
$l->insert("end", "item" . $_);
91
$l->pack("-side","top","-fill","both","-expand","yes");
97
return shift->Button(@_)->pack(-side => 'left');
103
my $b = $top->Checkbutton(@_);
104
$b->pack(-side => 'left');
111
my $b = $top->Radiobutton(@_);
112
$b->pack(-side => 'left');
119
my $w = $top->Label((@_) ? @_ : ('-text' => "A Label") );
120
$w->pack("-side"=>"bottom","-fill"=>"x");
127
my $w = $top->Message("-text","Press keys in blue square");
128
configure $w "-foreground","blue";
129
$w->pack("-fill"=>"x");
135
my $w = $top->Frame("-width",40, "-height",40,"-relief" => "ridge",
136
"-background" => "blue", "-border" => 7,
138
$w->bind("<Enter>", "focus");
139
$w->bind("<FocusIn>", NoOp);
140
$w->bind("<Any-Escape>", sub { shift->toplevel->destroy()});
141
$w->bind("<Any-KeyPress>",
144
# print "Key(",join(',',@_),")\n";
150
print "press $s$K ($k) '$c' $A\n"
158
my $menu = $top->Menubar;
159
my $file = $menu->Menubutton("-text" => "File","-underline" => 0, -bg => 'ivory',
162
$file->command("-label","Save","-command" => sub { print "Save\n" },"-underline" => 0);
163
$file->command("-label","Delete","-command" => sub { print "Delete\n" },"-underline" => 0);
165
$file->command("-label","Quit","-command" => sub { $top->destroy },"-underline" => 0);
167
$file = $menu->Menubutton(-text => "Options", -underline => 0, -font => 'fixed');
169
$file->checkbutton('-label' => 'Strict ~Motif', '-variable' => 'Tk::strictMotif');
172
$file->checkbutton('-label' => 'Oil checked', '-variable' => 'main::oil');
173
$file->checkbutton('-label' => 'Water checked', '-variable' => \$Water);
174
my $om = $file->cget('-menu');
175
$om->bind('<ButtonRelease-1>',[ sub {my ($b,$arg,$orig) = @_; print "Hey ",join(' ',map($_->PathName,$b,$arg),$orig),"\n";}, $om, $om->PathName] );
176
$file->command("-label","Interps", "-underline" => 0,
177
"-command" => sub { print 'Interps(',join(',',$file->interps),")\n" } );
179
$file = $menu->Menubutton(-text => "Exceptions", -underline => 0);
181
$file->command("-label","Busy","-command" => \&MakeBusy,"-underline" => 0);
182
$file->command("-label","Exit","-command" => sub { exit 0 },"-underline" => 0);
183
$file->command("-label","Close","-command" => sub { close Gibberish },"-underline" => 0);
184
$file->command("-label","Moan","-command" => [ \&test_back_trace, $menu, 3 ],"-underline" => 0);
185
$file->command("-label","Trace","-command" => \&back_trace,"-underline" => 0);
186
$file->command("-label","Wrong","-command" => sub { $top->configure(-gibberish => 'junk') });
187
$file->command("-label","Send","-command" => [\&send_test,$top] );
191
$menu->cascade(-label => 'Other', -underline => 1,
192
-menuitems => [[ Command => '~Busy',
193
-command => \&MakeBusy]]
197
$menu->cascade(-label => 'Help', -underline => 0,
198
-menuitems => [[ Command => '~Versions', -command => [\&ShowVersion, $top ]]]
206
for ($i = 0; $i < $entry->width; $i++)
208
my $cur = $entry->index('@'.$i);
209
print "$i => $cur\n";
215
my $top = $w->MainWindow;
216
$w->{Cursor} = $top->cget("-cursor");
217
$top->configure("-cursor"=>"watch");
218
$w->Popup(-popover => $top, -popanchor => 'c', -overanchor => 'c');
226
my $top = $w->MainWindow;
227
$top->configure("-cursor"=> $w->{Cursor});
235
my $t = $top->Toplevel("-class","Dialogue",
236
# -screen => $ENV{'DISPLAY'}
238
my $l = &label($t,@_);
239
my $b = &button($t,"-text","OK","-command"=>[ \&popdown ,$t]);
240
$t->wm("group",$top);
241
$t->wm("transient",$top);
243
$t->wm("minsize",0,0);
244
$l->pack("-side"=> "top", "-expand" => 1, "-fill" => "both");
245
$b->pack("-side"=> "bottom");
246
$t->wm("protocol","WM_DELETE_WINDOW",[\&popdown,$t]);
250
$top = MainWindow->new();
252
$top->optionAdd($top->Name.'*Dialog*Background', 'yellow');
256
$top->bind('MainWindow','<Map>',
258
printf "Mapped %.3g Sec. after bootstrap (u=%.3g s=%.3g)\n",Tk::Time_So_Far,times;
259
printf("%gK\n",Memory->used/1024) if (defined &Memory::used);
260
system("/bin/ps","-o",'vsz,osz,rss,pmem,time','-p',$$) if ($^O eq 'solaris');
264
$camel = $top->Photo(-format => 'gif', -file => Tk->findINC("Xcamel.gif"));
267
print "camel is ",$camel->width," wide\n";
272
print "ARGV now ",join(' ',@ARGV),"\n"
277
my $d = $top->Dialog(-title => 'Versions',
282
"Core Tk version : $Tk::version
283
Tk patchLevel : $Tk::patchLevel
284
library : $Tk::library
285
perl/Tk Version : $Tk::VERSION\n",-justify => 'center');
290
$fred = "Initial Text";
292
my $bl = $top->Balloon;
296
my $bf = $top->Frame->pack(-fill => 'x');
298
my $bigfont = "-Adobe-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*";
300
my $om = $bf->Optionmenu(-textvariable => \$option, -font => $bigfont,
301
-options => [qw(one two three four)],
302
-command => sub { print "Optionmenu set to: ",shift,"\n"}
303
)->pack(-side => 'right');
305
my $f = $om->cget('-font');
307
my $sz = $f->PostscriptFontName($ps);
308
print "Font is $f $$f $ps ($sz)\n";
310
my $be = $bf->BrowseEntry(-variable => \$option )->pack(-side => 'right');
311
$be->insert('end',qw(one two three four));
313
$QuitPB = $top->Pixmap('-file' => Tk->findINC("demos/images/QuitPB.xpm"));
314
$QuitPBa = $top->Pixmap('-file' => Tk->findINC("demos/images/QuitPBa.xpm"));
316
my $q = &button($bf,"-image",$QuitPB,
317
# "-activeimage",$QuitPBa,
318
"-command", sub { $top->destroy });
319
$bl->attach($q, -msg => "Exit Application");
321
&button($bf,"-text","Push me","-command",
322
[ sub {print "push(",join(',',@_),")\n"}, 1, Two , "iii" ]);
323
&checkbutton($bf,"-text","oil","-variable",\$oil,-command => \&MakeBusy);
324
&checkbutton($bf,"-text","water","-variable",main::Water);
325
&radiobutton($bf,"-text","one","-variable",\$option,"-value"=>"one",-command => \&MakeBusy);
326
&radiobutton($bf,"-text","two","-variable",\$option,"-value"=>"two");
327
&radiobutton($bf,"-text","three","-variable",\$option,"-value"=>"three");
328
&button($bf,"-text","State","-command",
329
sub {print "water=$main::Water oil=$oil option=$option\n"});
330
&button($bf,"-text","Chop","-command", sub { chop($fred) });
335
$entry = &entry($top,0,"-width","30","-textvariable",\$fred);
338
&label($top,"-bitmap"=>"info");
341
$l = &listbox($top,1..25);
342
&button($top,"-bitmap",'@'.Tk->findINC("demos/images/c.icon"),"-command", [ sub { shift->SetList(<*.c>) }, $l ] );
344
$pic = $top->Photo("-file" => Tk->findINC("demos/images/earthris.gif"));
346
$d = dialogue($top, "-image" => $pic );
348
$p = &button($top,"-text" => "popup picture", "-command" => [ \&popup , $d ]);
349
$p = &button($top,"-text" => "bisque", "-command" => [ 'bisque', $top ]);
350
$p = &button($top,"-text" => "Busy", "-command" => \&MakeBusy);
354
$top->Busy(-recurse => 1);
357
$top->after(6000, sub { $done = 1; warn "Fired\n" });
358
Tk::DoOneEvent(0) until ($done);
362
# Check that we have not broken array context again...
364
# print join(',',$top->children),"\n";
366
$top->Icon(-image => $camel);
368
$top->property("set",MYPROP,AREA,32,[1,2,3,4,5]);
370
$top->update("idletasks");
372
if ($^O ne 'MSWin32')
374
if (open(Gibberish, '<&STDIN'))
376
$top->fileevent(Gibberish,'readable',
377
[sub { my ($fh) = @_; print "stdin:",scalar <$fh> },\*Gibberish]);
381
warn "Cannot open /dev/tty:$!";
385
# print "imageNames(",join(',',$top->imageNames),")\n";
386
# print "imageTypes(",join(',',$top->imageTypes),")\n";