File: popup

package info (click to toggle)
perl-tk 1:800.025-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 18,444 kB
  • ctags: 19,081
  • sloc: ansic: 206,740; perl: 40,187; makefile: 4,371; sh: 2,373; yacc: 762
file content (56 lines) | stat: -rwxr-xr-x 1,410 bytes parent folder | download | duplicates (5)
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
#!/usr/local/bin/perl -w


use Tk;

$top = MainWindow->new;

$p = $top->Toplevel;
$p->Frame(-width => 50, -height => 30, -bg => 'blue')->pack;
$p->protocol('WM_DESTROY_WINDOW' => ['withdraw',$p]);
$p->withdraw;
$p->overrideredirect(1);

$anchor  = "c";
$overanchor  = "c";
$where   = $top;

sub Show
{
 $p->Popup(-popanchor  => $anchor, -overanchor => $overanchor, -popover => $where);
 $p->after(1000,['withdraw',$p]);
}

sub Anchor
{
 my ($top,$label,$var) = @_;
 my $out = $top->Frame(-label => $label,-relief => 'ridge',-borderwidth => 3);
 foreach $r ([qw(nw n ne)],[qw(w c e)],[qw(sw s se)])
  {
   my $f = $out->Frame;
   foreach $a (@$r)
    {
     $b = $f->Radiobutton(-text=> $a, -variable => $var, -value => $a,
                          -command => \&Show);
     $b->pack(-side => 'left');
    }
   $f->pack;
  }
 return $out;
}

my $w = $top->Frame;
my $b = $w->Radiobutton(-text => 'Window', -variable => \$where, 
                -value => $top, -command => \&Show);
$b->pack(-side=>'left');

$w->Radiobutton(-text => 'Screen', -variable => \$where, 
                -value => undef, -command => \&Show)->pack(-side=>'left');
$w->Radiobutton(-text => 'Cursor', -variable => \$where, 
                -value => 'cursor', -command => \&Show)->pack(-side=>'left');
$w->pack;

Anchor($top,"Self",\$anchor)->pack(-side => 'left');
Anchor($top,"Over",\$overanchor)->pack(-side => 'right');

MainLoop;