File: popup_menu

package info (click to toggle)
perl-tk 1%3A800.011-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 16,820 kB
  • ctags: 17,448
  • sloc: ansic: 189,575; perl: 31,426; makefile: 4,360; sh: 1,921; yacc: 762
file content (56 lines) | stat: -rwxr-xr-x 1,424 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 strict;

use Tk;

my $top = MainWindow->new;

my $p = $top->Menu(-menuitems => 
                   [ '------',
                     [Button => 'Quit', -command => ['destroy' => $top]],
                     '------'
                   ]);

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

sub Show
{
 $p->Popup(-popanchor  => $anchor, -overanchor => $overanchor, -popover => $where);
}

sub Anchor
{
 my ($top,$label,$var) = @_;
 my $out = $top->Frame(-label => $label,-relief => 'ridge',-borderwidth => 3);
 my $r;
 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;