| 1 |
# -*- perl -*- |
| 2 |
use strict; |
| 3 |
use Tk; |
| 4 |
|
| 5 |
BEGIN { |
| 6 |
if (!eval q{ |
| 7 |
use Test::More; |
| 8 |
1; |
| 9 |
}) { |
| 10 |
print "1..0 # skip: no Test::More module\n"; |
| 11 |
exit; |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
plan tests => 14; |
| 16 |
|
| 17 |
# Run |
| 18 |
# env BATCH=0 perl -Mblib t/balloon.t |
| 19 |
# for interactive balloon test |
| 20 |
if (!defined $ENV{BATCH}) { $ENV{BATCH} = 1 } |
| 21 |
|
| 22 |
my $mw = Tk::MainWindow->new; |
| 23 |
eval { $mw->geometry('+10+10'); }; # This works for mwm and interactivePlacement |
| 24 |
|
| 25 |
my $statusbar = $mw->Label->pack; |
| 26 |
|
| 27 |
my $balloon; |
| 28 |
eval { require Tk::Balloon; }; |
| 29 |
is($@, "", 'Loading Tk::Balloon'); |
| 30 |
eval { $balloon = $mw->Balloon; }; |
| 31 |
is($@, "", 'Creating Balloon widget'); |
| 32 |
ok( Tk::Exists($balloon), "Existance of ballon" ); |
| 33 |
|
| 34 |
my $l = $mw->Label->pack; |
| 35 |
eval { $balloon->attach($l, -msg => "test"); }; |
| 36 |
is($@, "", 'Attaching message to Label widget'); |
| 37 |
eval { $balloon->attach($l, -statusmsg => "test1", -balloonmsg => "test2"); }; |
| 38 |
is($@, "", 'Attaching statusmsg/baloonmsg to Label widget'); |
| 39 |
|
| 40 |
{ |
| 41 |
my $c = $mw->Canvas(-width => 100, -height => 50)->pack; |
| 42 |
my $ci = $c->createLine(0,0,10,10); |
| 43 |
eval { $balloon->attach($c, -msg => {$ci => "test"}); }; |
| 44 |
is($@, "", 'Attaching message to Canvas item'); |
| 45 |
} |
| 46 |
|
| 47 |
{ |
| 48 |
my $c = $mw->Scrolled("Canvas", -width => 100, -height => 50)->pack; |
| 49 |
my $ci = $c->createLine(0,0,10,10); |
| 50 |
eval { $balloon->attach($c, -msg => {$ci => "test"}); }; |
| 51 |
is($@, "", 'Attaching message to scrolled Canvas item'); |
| 52 |
} |
| 53 |
|
| 54 |
my $menubar = $mw->Menu; |
| 55 |
$mw->configure(-menu => $menubar); |
| 56 |
my $filemenu = $menubar->cascade(-label => "~File", -tearoff => 0); |
| 57 |
$filemenu->command(-label => "Test1"); |
| 58 |
$filemenu->command(-label => "Test2"); |
| 59 |
$filemenu->command(-label => "Test3"); |
| 60 |
my $filemenu_menu = $filemenu->cget(-menu); |
| 61 |
|
| 62 |
eval { $balloon->attach($filemenu_menu, |
| 63 |
-msg => ["Test1 msg", "Test2 msg", "Test3 msg"]); }; |
| 64 |
is($@, "", 'Attaching message to Menu'); |
| 65 |
|
| 66 |
eval { $balloon->configure(-motioncommand => \&motioncmd); }; |
| 67 |
is($@, "", "Set motioncommand option"); |
| 68 |
eval { $balloon->configure(-motioncommand => undef); }; |
| 69 |
is($@, "", "Reset motioncommand option"); |
| 70 |
|
| 71 |
{ |
| 72 |
my $lb = $mw->Listbox(-height => 6)->pack; |
| 73 |
$lb->insert("end",1,2,3,4); |
| 74 |
eval { $balloon->attach($lb, -msg => ['one','two','three','four']); }; |
| 75 |
is($@, "", 'Attaching message to Listbox items'); |
| 76 |
} |
| 77 |
|
| 78 |
{ |
| 79 |
my $slb = $mw->Scrolled('Listbox', -height => 2)->pack; |
| 80 |
$slb->insert("end",1,2,3,4); |
| 81 |
eval { $balloon->attach($slb, |
| 82 |
-msg => ['one','two','three','four']); }; |
| 83 |
is($@, "", 'Attaching message to scrolled Listbox items'); |
| 84 |
} |
| 85 |
|
| 86 |
{ |
| 87 |
require Tk::NoteBook; |
| 88 |
my $nb = $mw->NoteBook->pack; |
| 89 |
for (1..4) { |
| 90 |
my $p = $nb->add("page$_", -label => "Page$_"); |
| 91 |
$p->Label(-text => "Page $_")->pack; |
| 92 |
} |
| 93 |
$balloon->attach($nb, |
| 94 |
-balloonposition => 'mouse', |
| 95 |
-msg => { page1 => "This is page1", |
| 96 |
page2 => "This is page2", |
| 97 |
page3 => "This is page3", |
| 98 |
page4 => "This is page4", |
| 99 |
}); |
| 100 |
pass("Attached hash ballooninfo to NoteBook"); |
| 101 |
} |
| 102 |
|
| 103 |
{ |
| 104 |
my $nb = $mw->NoteBook->pack; |
| 105 |
for (1..4) { |
| 106 |
my $p = $nb->add("page$_", -label => "Page$_"); |
| 107 |
$p->Label(-text => "Page $_")->pack; |
| 108 |
} |
| 109 |
$balloon->attach($nb, |
| 110 |
-balloonposition => 'mouse', |
| 111 |
-msg => "Balloon applies to whole notebook", |
| 112 |
); |
| 113 |
pass("Attached scalar ballooninfo to NoteBook"); |
| 114 |
} |
| 115 |
|
| 116 |
## not yet: |
| 117 |
# $l->eventGenerate("<Motion>"); |
| 118 |
# sub motioncmd { |
| 119 |
# my(@args) = @_; |
| 120 |
# warn "<<<@args"; |
| 121 |
# } |
| 122 |
|
| 123 |
MainLoop if !$ENV{BATCH}; |
| 124 |
|
| 125 |
sub motioncmd { warn "dummy motioncommand\n" } |
| 126 |
|
| 127 |
__END__ |