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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
# -*- perl -*-
#
# Author: Slaven Rezic
#
# Copyright (C) 1997,1998,2008,2016 Slaven Rezic. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# Mail: srezic@cpan.org
# WWW: http://user.cs.tu-berlin.de/~eserte/
#
use strict;
use warnings;
use Test::More;
use Tk;
use Tk::HistEntry;
my $top = eval { new MainWindow };
if (!$top) {
plan skip_all => "cannot open DISPLAY: $@";
}
$top->geometry('+10+10');
if (!eval {
require Tk::FireButton;
$top->event('generate', '<Button-1>');
die "event generate is working different on Win32" if $^O eq 'MSWin32';
1;
}) {
plan skip_all => "Tk::FireButton and/or event missing";
}
plan tests => 14;
{
package MyHistEntry;
@MyHistEntry::ISA = qw(Tk::Frame);
Construct Tk::Widget 'MyHistEntry';
sub Populate {
my($f, $args) = @_;
no warnings 'once';
my $e = $f->Component(SimpleHistEntry => 'entry');
my $binc = $f->Component( FireButton => 'inc',
-bitmap => $Tk::FireButton::INCBITMAP,
-command => sub { $e->historyUp },
);
my $bdec = $f->Component( FireButton => 'dec',
-bitmap => $Tk::FireButton::DECBITMAP,
-command => sub { $e->historyDown },
);
$f->gridColumnconfigure(0, -weight => 1);
$f->gridColumnconfigure(1, -weight => 0);
$f->gridRowconfigure(0, -weight => 1);
$f->gridRowconfigure(1, -weight => 1);
$binc->grid(-row => 0, -column => 1, -sticky => 'news');
$bdec->grid(-row => 1, -column => 1, -sticky => 'news');
$e->grid(-row => 0, -column => 0, -rowspan => 2, -sticky => 'news');
$f->ConfigSpecs
(-repeatinterval => ['CHILDREN', "repeatInterval",
"RepeatInterval", 100 ],
-repeatdelay => ['CHILDREN', "repeatDelay",
"RepeatDeleay", 300 ],
DEFAULT => [$e],
);
$f->Delegates(DEFAULT => $e);
$f;
}
}
$top->geometry($top->screenwidth . "x" .$top->screenheight . "+0+0");
my($b2, $lb2);
{
my $bla;
$b2 = $top->MyHistEntry(-textvariable => \$bla,
-repeatinterval => 30,
-bell => 1,
-dup => 1,
-command => sub {
my($w, $s, $added) = @_;
if ($added) {
$lb2->insert('end', $s);
$lb2->see('end');
}
$bla = '';
})->pack;
ok $b2;
$b2->update;
pass "after calling update";
}
$lb2 = $top->Scrolled('Listbox', -scrollbars => 'osoe')->pack;
my $e = $b2->Subwidget('entry');
my $inc = $b2->Subwidget('inc');
my $dec = $b2->Subwidget('dec');
$e->focus;
$e->insert("end", 'first');
$e->event('generate', "<Return>", -keysym => 'Return');
is_deeply [$b2->history], ['first'];
$e->event('generate', "<Up>", -keysym => 'Up');
is $e->get, 'first';
$e->event('generate', "<Down>", -keysym => 'Down');
is $e->get, '';
$e->insert(0, 'second');
$e->event('generate', "<Return>", -keysym => 'Return');
is_deeply [$e->history], ['first', 'second'];
$inc->invoke;
$inc->invoke;
is $e->get, 'first';
$dec->invoke;
is $e->get, 'second';
# The next two tests are disabled, because they fail on systems without
# configured Alt key.
if (0) {
$e->focus;
$e->event('generate', "<Alt-less>", -state => 8, -keysym => 'less');
is $e->get, 'first';
$e->event('generate', "<Alt-greater>", -state => 8, -keysym => 'greater');
is $e->get, 'second';
}
$e->historyAdd("third");
{
my @h = $e->history;
is @h, 3;
is $h[2], 'third';
}
$e->invoke("fourth");
{
my @h = $lb2->get(0, 'end'); # only three elements (because of use of historyAdd)
is @h, 3;
is $h[2], 'fourth';
}
$e->delete(0, 'end');
$e->insert(0, 'bla');
$e->historyAdd;
{
my @h = $e->history;
is @h, 5;
is $h[4], 'bla';
}
if ($ENV{PERL_TEST_INTERACTIVE}) {
my $cb = $top->Button(-text => "Ok",
-command => sub { $top->destroy })->pack;
$cb->focus;
$top->after(30000, sub { $top->destroy });
MainLoop;
}
|