arch/Tk/demos/widtrib/treegraph.pl untested

filter: Statementstmt 0.0% 0 / 58 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 65 CC 1 SCAR 6.9
CC
1
Cov
0%
draw
2.0
treegraph
2.0
BEGIN
2.0
CRAP 2.0
1 # Treegraph - Draw a tree in a Canvas
2  
3 use Tk ;
4 use Tk::TreeGraph ;
5  
6 use vars qw/$TOP/;
7  
8 sub draw
9 {
10 my $tg = shift ;
11
12 my $ref = [qw/some text/];
13
14 $tg -> addNode
15 (
16 nodeId => '1.0',
17 text => $ref
18 ) ;
19
20 $tg -> addNode
21 (
22 after => '1.0',
23 nodeId => '1.1',
24 text => $ref
25 ) ;
26
27 $tg -> addNode
28 (
29 after => '1.1',
30 nodeId => '1.2',
31 text => $ref
32 ) ;
33
34 $tg -> addNode
35 (
36 after => '1.2',
37 nodeId => '1.3',
38 text => $ref
39 ) ;
40
41 $tg -> addNode
42 (
43 after => '1.3',
44 nodeId => '1.4',
45 text => $ref
46 ) ;
47
48 $tg -> addNode
49 (
50 after => '1.4',
51 nodeId => '1.5',
52 text => $ref
53 ) ;
54
55 $tg -> addNode
56 (
57 after => '1.4',
58 nodeId => '1.4.1.1',
59 text => $ref
60 ) ;
61
62 $tg -> addNode
63 (
64 after => '1.4',
65 nodeId => '1.4.2.1',
66 text => $ref
67 ) ;
68
69 $tg -> addNode
70 (
71 after => '1.4',
72 nodeId => '1.4.3.1',
73 text => $ref
74 ) ;
75
76 $tg -> addNode
77 (
78 after => '1.1',
79 nodeId => '1.1.1.1',
80 text => $ref
81 ) ;
82
83 $tg -> addNode
84 (
85 after => '1.1.1.1',
86 nodeId => '1.1.1.2',
87 text => $ref
88 ) ;
89
90 $tg -> addNode
91 (
92 after => '1.0',
93 nodeId => '1.0.2.1',
94 text => $ref
95 ) ;
96
97 $tg -> addNode
98 (
99 after => '1.0.2.1',
100 nodeId => '1.0.2.2',
101 text => $ref
102 ) ;
103
104 $tg -> addNode
105 (
106 after => '1.0.2.2',
107 nodeId => '1.0.2.3',
108 text => $ref
109 ) ;
110
111 $tg -> addNode
112 (
113 after => '1.0.2.1',
114 nodeId => '1.0.2.1.1.1',
115 text => $ref
116 ) ;
117 $tg->addShortcutInfo
118 (
119 to => '1.2',
120 from => '1.0.2.1'
121 ) ;
122
123 $tg->addShortcutInfo
124 (
125 to => '1.3',
126 from => '1.1.1.2'
127 ) ;
128
129 $tg->addAllShortcuts() ;
130
131 $tg->arrowBind
132 (
133 button => '<1>',
134 color => 'yellow',
135 command => sub{my %h = @_;
136 warn "clicked 1 arrow $h{from} -> $h{to}\n";}
137 );
138
139 $tg->nodeBind
140 (
141 button => '<2>',
142 color => 'red',
143 command => sub {my %h = @_;
144 warn "clicked 2 node $h{nodeId}\n";}
145 );
146  
147 $tg->command( on => 'arrow', label => 'dummy 1',
148 command => sub{warn "arrow menu dummy1\n";});
149 $tg->command( on => 'arrow', label => 'dummy 2',
150 command => sub{warn "arrow menu dummy2\n";});
151 $tg->arrowBind(button => '<3>', color => 'green',
152 command => sub{$tg->popupMenu(@_);});
153
154 $tg->command(on => 'node', label => 'dummy 1',
155 command => sub{warn "node menu dummy1\n";});
156 $tg->command(on => 'node', label => 'dummy 2',
157 command => sub{warn "node menu dummy2\n";});
158 $tg->nodeBind(button => '<3>', color => 'green',
159 command => sub{$tg->popupMenu(@_);});
160 }
161  
162 sub treegraph {
163 my($demo) = @_;
164 $TOP = $MW->WidgetDemo
165 (
166 -name => $demo,
167 -text => ["TreeGraph - Draw a tree in a Canvas
168 Click on button 1 and 3 on arrows.
169 Click on button 1,2 and 3 on rectangles or embedded text.",
170 qw/-wraplength 600/],
171 -geometry_manager => 'grid',
172 -width => 600,
173 -title => 'Draw a tree in a Canvas',
174 -iconname => 'TreeGraphDemo'
175 ) ;
176
177  
178 my $tg = $TOP->Scrolled
179 (
180 qw/TreeGraph -relief sunken -borderwidth 2 -animation 500
181 -width 500 -height 400/,
182 -scrollregion => [0, 0, 600 , 400 ]
183 ) ->grid ;
184  
185 &draw($tg);
186  
187 $tg->Tk::bind('<Key-z>',sub {print "hit z\n";
188 $tg->scale("all",0,0,0.5,0.5);});
189  
190 $TOP->Label(-text => 'Click "See Code".')->grid;
191 }