Leser: 2
![]() |
|< 1 2 >| | ![]() |
15 Einträge, 2 Seiten |
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
sub del
{
my( $self, @num ) = @_; # pick parameters
$self->close if $self->{container}->ismapped; # close the menu if it is being displayed
# delete menu entries
for my $i (
sort { $b <=> $a } @num # sort this to delete the right entries
) {
$self->{menu}->[$i] -> destroy(); # destroy the menu entry
splice( @{ $self->{menu} }, $i, 1 ); # delete the array member
} # for
return $self; # return object
} # del
sub close
{
my( $self ) = @_; # pick parameters
$self->{shadow} -> withdraw; # close shadow
$self->{container} -> withdraw; # close menu
return $self; # return object
} # close
sub show
{
my( $self, $x, $y ) = @_; # pick parameters
$self->close if $self->{container}->ismapped; # close menu if it is being displayed
# set shadow position
$self->{shadow} -> geometry(
'=' .
$self->{container}->reqwidth . # menu width
'x' .
$self->{container}->reqheight . # menu height
'+' .
( $x + 3 ) . # menu x position + extra pixels for the shadow
'+' .
( $y + 3 ) # menu y position + extra pixels for the shadow
);
$self->{shadow} -> deiconify; # show shadow
$self->{container} -> geometry("+$x+$y"); # set menu position
$self->{container} -> deiconify; # show menu
$self->{container} -> raise( $self->{shadow} ); # draw the menu over the shadow
$self->{container} -> focus(); # give focus() to the menu
return $self; # return object
} # show
1;
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
#!/usr/bin/perl
use strict;
use warnings 'all';
use Tk;
use Tk::KMenu;
# create main window
my $mw = tkinit();
# create menu
my $menu = new Tk::KMenu $mw;
# add menu entries
$menu -> add(
Test => sub {
print "Test\n";
},
Test2 => sub {
print "Test 2\n";
},
Delete => sub {
$menu -> del( 0 .. 2 );
},
Beenden => sub {
$mw -> destroy;
},
);
# should create a package for MenuButtons, so that the following can be written simpler
#
# create menubutton
#
my $menubutton = $mw -> Button(
-text => 'Open Menu',
) -> pack;
# have to split this because $menubutton has to be defined,
# so we can use it in the -command callback.
$menubutton -> configure(
-command => sub {
$menu->show(
$mw->rootx + $menubutton->x, # calculate the x position
$mw->rooty + $menubutton->y # calculate the y position
+ $menubutton->reqheight,
);
},
);
MainLoop;
Gast+2008-01-15 08:41:16--Hey! Das sieht ja geil aus ;) Danke Horst!
Gast+2008-01-15 08:41:16--Sollten wir uns mal begegnen, gebe ich garantiert ein aus.
![]() |
|< 1 2 >| | ![]() |
15 Einträge, 2 Seiten |