Debian Codegraph @

examples/classtree

raw
1 #!/usr/local/bin/perl -w
2 use strict;
3 use Tk;
4 use Tk::widgets qw(Tree Menubar);
5
6 my $mw = MainWindow->new;
7 my $mb = $mw->Menubar;
8 $mb->Menubutton(-text => '~File', -menuitems => [
9 [Button => 'E~xit', -command => ['destroy' => $mw]],
10 ]);
11
12 my $cl = $mw->Scrolled('Tree', -width => 60, -height => 40, -separator => '.',-itemtype => 'text');
13
14 # do "t/Require.t";
15 enter_classes($cl,'Tk::','open');
16
17 Tk::grid($cl,-sticky => 'nsew');
18 $mw->gridRowconfigure(0, -weight => 1);
19 $mw->gridColumnconfigure(0, -weight => 1);
20
21 MainLoop;
22
23 sub enter_classes
24 {
25 my ($cl,$name,$mode) = @_;
26 no strict 'refs';
27 if (defined(%{$name}) && $name =~ /^(.*)::$/)
28 {
29 my $path = $1;
30 $path =~ s/::/./g;
31 my ($leaf) = $path =~ /(?:^|\.)([^\.]+)$/;
32 # print join(' ',$name,$path,$leaf),"\n";
33 $cl->add($path,-text => $leaf);
34 foreach my $child (sort keys %$name)
35 {
36 enter_classes($cl,$name.$child,'close') if $child =~ /::$/;
37 }
38 foreach my $child (sort keys %$name)
39 {
40 if ($child !~ /::$/ && defined &{$name.$child})
41 {
42 my $cp = $path.'.'.$child;
43 $cl->add($cp,-text => $child) unless $cl->infoExists($cp);
44 }
45 }
46 $cl->Activate($path,$mode);
47 }
48 }
49