use Tk; $mw=MainWindow->new; #--the pop up for each tagged item in canvas $menu=$mw->Menu(-tearoff => 0, -menuitems=> [ ['command' => "$boxname",-command => \&null], "-", ['command' =>"Stop Job",-command => \&test], ['command' =>"Start Job",-command => \&test], ['command' =>"Pause Job",-command => \&test], ['command' =>"Resume Job",-command => \&test], ['command' =>"Job Status",-command => \&test], ['command' =>"Laminate Job",-command => \&test], ['command' =>"Edit Job",-command => \&test] ] ); $cscroll=$mw->Scrolled("Canvas",-width=>500,-height=>200,-bg=>'Blue')->pack(-side=>'top',-expand=>'yes',-fill=>'both'); $cscroll->configure(-scrollregion=>[0,0,17000,9000]); $bttnbox=$mw->Frame()->pack(-side=>'top',-fill=>'x',-expand=>'yes'); $l1=$bttnbox->Label(-textvariable=>\$metadata011)->pack(-side=>'top',-fill=>'x',-expand=>'yes'); $zi=$bttnbox->Button(-text=>'Zoom_in',-command=>sub { $cscroll->scale('all',0,0,1.5,1.5)})->pack(-side=>'top',-fill=>'x',-expand=>'yes'); $z0=$bttnbox->Button(-text=>'Zoom_out',-command=>sub { $cscroll->scale('all',0,0,.5,.5)})->pack(-side=>'top',-fill=>'x',-expand=>'yes'); $lpr=$bttnbox->Button(-text=>'Print',-command=>sub { $cscroll->postscript(-file => "status.ps"); print "printed status.ps\n"; })->pack(-side=>'top',-fill=>'x',-expand=>'yes'); $xt=$bttnbox->Button(-text=>'Exit',-command=>sub { exit; })->pack(-side=>'top',-fill=>'x',-expand=>'yes'); @cmd=`dot -Tplain status.dot`; @data=grep { /box/ } @cmd; foreach $item ( @data ) { chomp($item); $item=~s/\+*//g; $item=~s/\?*//g; $item=~s/\**//g; @stuff1=split(/\"/,$item); $namer1=$stuff1[1]; $namer2=$namer1; $namer2=~s/ +/_/g; $item=~s/$namer1/$namer2/g; #($node,$name1,$x1,$y1,$width,$height,$name2,$filled,$objtype,$color)=split(/ +/,$item); ($node,$name1,$x1,$y1,$width,$height,$name,$esfilled,$objtype,@misc)=split(/ +/,$item); $color=$misc[$#misc]; $x1=int($x1 * 80 ) ; $x2=int($x1 + ( $width * 70 ) ); $y1=int($y1 * 90 ) ; $y2=int($y1 + ( $height * 70 )); $x3=int(($x1+$x2)/2); $y3=int(($y1+$y2)/2); $y3=$y1 + 15; $item=~s/\.*//g; $name1=~s/\"//g; $assoc_hash{$name1}="$x3,$y3"; $assoc_hash2{$name1}="$x1,$y1,$x2,$y2,$x3,$y3,$color,$objtype"; #print "coords for $name1 are $x1 $y1 / $x2 $y2 and $color\n"; } @data=grep { /node/ } @cmd; #@data=`dot -Tplain status.dot | grep node`; foreach $item ( @data ) { chomp($item); $item=~s/\+*//g; $item=~s/\?*//g; $item=~s/\**//g; @stuff1=split(/\"/,$item); $namer1=$stuff1[1]; $namer2=$namer1; $namer2=~s/ +/_/g; $item=~s/$namer1/$namer2/g; #($node,$name1,$x1,$y1,$width,$height,$name2,$filled,$objtype,$color)=split(/ +/,$item); ($node,$name1,$x1,$y1,$width,$height,$name2,$filled,$objtype,@misc)=split(/ +/,$item); $color=$misc[$#misc]; $x1=int($x1 * 80 ) ; $x2=int($x1 + ( $width * 70 ) ) ; $y1=int($y1 * 90 ) - 40; $y2=int($y1 + ( $height * 70 )) ; $x3=int(($x1+$x2)/2); $y3=int(($y1+$y2)/2); $y3=$y1 + 15; #$y1=400 - $y1 ; #$y2=400 - $y2 ; #$y3=400 - $y3 ; #$y1-=200; #$y2-=200; #$y3-=200; $item=~s/\.*//g; #print "PRE coords for $name1 are $x1 $y1 / $x2 $y2 - $x3 $y3 and $color\n"; $name1=~s/\"//g; $assoc_hash{$name1}="$x3,$y3"; $assoc_hash2{$name1}="$x1,$y1,$x2,$y2,$x3,$y3,$color,$objtype"; #print "coords for $name1 are $x1 $y1 / $x2 $y2 and $color\n"; } #@data=`dot -Tplain status.dot | grep edge`; @data=grep { /edge/ } @cmd; foreach $item ( @data ) { chomp($item); $item=~s/solid//; $item=~s/black//; $item=~s/\+*//g; $item=~s/\?*//g; $item=~s/\**//g; @stuff1=split(/\"/,$item); $namer1=$stuff1[1]; $namer2=$namer1; $namer2=~s/ +/_/g; $namer3=$stuff1[3]; $namer4=$namer3; $namer4=~s/ +/_/g; $item=~s/$namer1/$namer2/g; $item=~s/$namer3/$namer4/g; ($edge,$from,$to,@points)=split(/ +/,$item); $item=~s/\.*//g; $from=~s/\"//g; $to=~s/\"//g; @points2=@points[1..$#points]; $cntr=0; foreach $point ( @points2 ) { if ( $cntr % 2 == 0 ) { int ($point*=80 ); } else { int ($point*=90 ); } push(@{"$from$to"},$point); $cntr++; }; push(@assoc,"$from,$to"); } foreach $association ( @assoc ) { ($from,$to)=split(/,/,$association); if ( $from && $to ) { ($x1,$y1)=split(/,/,$assoc_hash{$from}); ($xf,$yf)=split(/,/,$assoc_hash{$to}); ${"$from$to"}[0]=$x1; ${"$from$to"}[1]=$y1; ${"$from$to"}[$#{"$from$to"} - 1]=$xf; ${"$from$to"}[$#{"$from$to"} ]=$yf; $cscroll->createLine(@{"$from$to"},-splinesteps=>40,-smooth=>1,-tags=>['line',$from,$to,-color=>'red']); } } foreach $key ( keys %assoc_hash2 ) { $name1=$key; ($x1,$y1,$x2,$y2,$x3,$y3,$color,$objtype)=split(/,/,$assoc_hash2{$name1}); $color=$color||"white"; $color=~s/black/white/; #print "color is $color\n"; if ( $objtype=~/polygon/i ) { $cscroll->createOval($x1,$y1,$x2,$y2,-fill=>$color,-tags=>[$name1,'box']); } else { $cscroll->createRectangle($x1,$y1,$x2,$y2,-fill=>$color,-tags=>[$name1,'box']); } $cscroll->createText($x3,$y3,-text=>"$name1",-fill=>'black',-tags=>['text',$name1]); } $cscroll->bind('all',"", [\&cscroll_enter]); $cscroll->bind('all',"", [\&cscroll_leave,\$ref_old_fill]); $cscroll->bind('box',,"",[\&display_menu,]); sub test { print "This is a test\n"; } sub null { }; sub display_menu { @curr_tags=$cscroll->gettags('current'); $boxname="@curr_tags"; $boxname=~s/ +.*//g; $boxname="Job: $boxname"; $menu->delete(0,0); $menu->insert(0,'command',-label=>"$boxname"); $menu->Popup(-popover=>"cursor"); } sub cscroll_button { my($cscroll) = @_; my $id = $cscroll->find(qw/withtag current/); $id++ if ($cscroll->gettags('current'))[0] ne 'text'; print STDOUT 'You buttoned at ', ($cscroll->itemconfigure($id, -text))[4], "\n"; } # end cscroll_button sub cscroll_enter { my $id = $cscroll->find(qw/withtag current/); $old_fill = ($cscroll->itemconfigure($id, -fill))[4]; $ref_old_fill=\$old_fill; @tags011=$cscroll->gettags('current'); $metadata011="@tags011"; if (($cscroll->depth > 1) && !( grep {$_=~/text/} @tags011) ) { $cscroll->itemconfigure($id, -fill => 'SeaGreen1'); @info=$cscroll->gettags($id); print "TEST @info\n"; ($type,$string)=split(/,/,$info[0]); $nodes{$string}=time; } else { $cscroll->itemconfigure($id, -fill => 'black'); } } # end cscroll_enter sub cscroll_leave { my $id = $cscroll->find(qw/withtag current/); $cscroll->itemconfigure($id, -fill => $$ref_old_fill); } # end cscroll_leave #$cscroll->scale('all',0,0,.1,.1); MainLoop; 1;