| 1 |
#!/usr/bin/perl -w |
| 2 |
# -*- perl -*- |
| 3 |
|
| 4 |
# |
| 5 |
# $Id: $ |
| 6 |
# Author: Slaven Rezic |
| 7 |
# |
| 8 |
|
| 9 |
use strict; |
| 10 |
|
| 11 |
use Tk; |
| 12 |
|
| 13 |
BEGIN { |
| 14 |
if (!eval q{ |
| 15 |
use Test::More; |
| 16 |
1; |
| 17 |
}) { |
| 18 |
print "1..0 # skip: no Test::More module\n"; |
| 19 |
exit; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
plan tests => 17; |
| 24 |
|
| 25 |
use_ok('Tk::MsgBox'); |
| 26 |
|
| 27 |
my $mw = MainWindow->new; |
| 28 |
$mw->geometry("+10+10"); |
| 29 |
|
| 30 |
my @opts = (-icon => "info", |
| 31 |
-detail => "Some details...", |
| 32 |
-message => "A message", |
| 33 |
-type => "ok", |
| 34 |
-title => "Dialog title", |
| 35 |
); |
| 36 |
|
| 37 |
for my $icon (qw(info warning error question)) { |
| 38 |
my $w = $mw->MsgBox(@opts, -icon => $icon); |
| 39 |
ok(Tk::Exists($w), "Setting -icon to $icon"); |
| 40 |
is($w->state, "withdrawn", "Initially invisible"); |
| 41 |
$w->after(100, sub { $w->destroy }); |
| 42 |
$w->Show; |
| 43 |
} |
| 44 |
|
| 45 |
for my $type (qw(abortretryignore ok okcancel retrycancel yesno yesnocancel)) { |
| 46 |
my $w = $mw->MsgBox(@opts, -type => $type); |
| 47 |
ok(Tk::Exists($w), "Setting -type to $type"); |
| 48 |
$w->after(100, sub { $w->destroy }); |
| 49 |
$w->Show; |
| 50 |
} |
| 51 |
|
| 52 |
{ |
| 53 |
my $w = $mw->MsgBox(-type => "okcancel"); |
| 54 |
ChooseMsg($w,'ok'); |
| 55 |
is($w->Show, 'ok', "Emulating mouse click to ok"); |
| 56 |
ChooseMsg($w,'cancel'); |
| 57 |
is($w->Show, 'cancel', "Emulating mouse click to cancel"); |
| 58 |
} |
| 59 |
|
| 60 |
if (0) { # XXX this probably only works after the grab stuff... |
| 61 |
my $w = $mw->MsgBox(-type => "okcancel"); |
| 62 |
ChooseMsgByKey($w,'ok'); |
| 63 |
is($w->Show, 'ok', "Emulating key press to ok"); |
| 64 |
ChooseMsgByKey($w,'cancel'); |
| 65 |
is($w->Show, 'cancel', "Emulating key press to cancel"); |
| 66 |
} |
| 67 |
|
| 68 |
sub ChooseMsg { |
| 69 |
my($w,$btn) = @_; |
| 70 |
$w->after(100, sub {SendEventToMsg($w,$btn,'mouse')}); |
| 71 |
} |
| 72 |
|
| 73 |
sub ChooseMsgByKey { |
| 74 |
my($w,$btn) = @_; |
| 75 |
$w->after(100, sub {SendEventToMsg($w,$btn,'key')}); |
| 76 |
} |
| 77 |
|
| 78 |
sub PressButton { |
| 79 |
my($b) = @_; |
| 80 |
$b->eventGenerate('<Enter>'); |
| 81 |
$b->eventGenerate('<ButtonPress-1>', '-x' => 5, '-y' => 5); |
| 82 |
$b->eventGenerate('<ButtonRelease-1>', '-x' => 5, '-y' => 5); |
| 83 |
} |
| 84 |
|
| 85 |
sub SendEventToMsg { |
| 86 |
my($w, $btn, $type) = @_; |
| 87 |
my $b = $w->Subwidget($btn); |
| 88 |
if (!$b->ismapped) { |
| 89 |
$b->update; |
| 90 |
} |
| 91 |
if ($type eq 'mouse') { |
| 92 |
PressButton($b); |
| 93 |
} else { |
| 94 |
$w->eventGenerate('<Enter>'); |
| 95 |
$w->focus; |
| 96 |
$b->eventGenerate('<Enter>'); |
| 97 |
$w->eventGenerate('<KeyPress>', -keysym => 'Return'); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
__END__ |