| 1 |
#!/bin/sh |
| 2 |
# next line is a comment in tcl \ |
| 3 |
exec wish "$0" ${1+"$@"} |
| 4 |
|
| 5 |
package require Tkspline |
| 6 |
package require Tcldot |
| 7 |
|
| 8 |
# disp - display a .gv file - [email protected] |
| 9 |
# |
| 10 |
# Usage: disp <file.gv> |
| 11 |
# |
| 12 |
# disp displays the graph in a canvas widget. Clicking on a node, edge, |
| 13 |
# or the background will list the attributes of that object to stdout. |
| 14 |
|
| 15 |
# scrollEnter - as the mouse moves over an object change its shading |
| 16 |
proc scrollEnter {c} { |
| 17 |
upvar #0 tk_library tk_library saveFill saveFill |
| 18 |
set item [string range [lindex [$c gettags current] 0] 1 end] |
| 19 |
set saveFill [lindex [$c itemconfigure 1$item -fill] 4] |
| 20 |
$c itemconfigure 1$item -fill black \ |
| 21 |
-stipple @$tk_library/demos/images/gray25.bmp |
| 22 |
} |
| 23 |
|
| 24 |
# scrollLeave - as the mouse moves out of an object restore its shading |
| 25 |
proc scrollLeave {c} { |
| 26 |
upvar #0 saveFill saveFill |
| 27 |
set item [string range [lindex [$c gettags current] 0] 1 end] |
| 28 |
$c itemconfigure 1$item -fill $saveFill -stipple {} |
| 29 |
} |
| 30 |
|
| 31 |
# select - if the mouse is currently over an object and button 1 |
| 32 |
# is pressed then print out its attributes to stdout |
| 33 |
proc select {c} { |
| 34 |
upvar #0 g g |
| 35 |
set item [string range [lindex [$c gettags current] 0] 1 end] |
| 36 |
if {$item == ""} {set item $g} |
| 37 |
puts [set name [$item showname]] |
| 38 |
foreach attr [$item listattr] { |
| 39 |
set val [lindex [$item queryattr $attr] 0] |
| 40 |
# support dot's "\N" = name substitution in labels and URLS |
| 41 |
if {"$attr" == "label" || "$attr" == "URL"} { |
| 42 |
regsub -all {\\N} $val $name val |
| 43 |
} |
| 44 |
puts " $attr = $val" |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
# load a .gv file and render the graph to a canvas widget |
| 49 |
proc load {c} { |
| 50 |
upvar #0 g g argc argc argv argv saveFill saveFill |
| 51 |
|
| 52 |
set saveFill "" |
| 53 |
catch {$g delete} |
| 54 |
$c delete all |
| 55 |
|
| 56 |
if {$argc == 0} { |
| 57 |
puts "No .gv file specified. Assuming poly.gv demo." |
| 58 |
set argv "data/poly.gv" |
| 59 |
} |
| 60 |
if {[llength $argv] > 1} {puts "Too many args."; exit} |
| 61 |
if {[catch {open $argv r} f]} {puts "unable to open .gv file"; exit} |
| 62 |
set g [dotread $f] |
| 63 |
close $f |
| 64 |
|
| 65 |
$g layout |
| 66 |
|
| 67 |
eval [$g render] |
| 68 |
|
| 69 |
# size the window to match the bounding box of the graph layout |
| 70 |
scan [$g queryattr bb] "{%d %d %d %d}" ulx uly lrx lry |
| 71 |
$c configure -height [expr $lry + $uly]]p -width [expr $lrx + $ulx]p |
| 72 |
|
| 73 |
wm minsize . 100 100 |
| 74 |
} |
| 75 |
|
| 76 |
# set up widgets and bindings and load initial file |
| 77 |
set c [canvas .c -highlightthickness 0] |
| 78 |
pack $c -expand 1 -fill both -side top |
| 79 |
pack [frame .tb] -expand 1 -fill x -side bottom |
| 80 |
|
| 81 |
pack [button .tb.b1 -highlightthickness 0 -command "load $c" -text reload] \ |
| 82 |
[button .tb.b2 -highlightthickness 0 -command exit -text quit] \ |
| 83 |
-side left -fill x -expand 1 |
| 84 |
|
| 85 |
$c bind all <Any-Enter> "scrollEnter $c" |
| 86 |
$c bind all <Any-Leave> "scrollLeave $c" |
| 87 |
|
| 88 |
bind $c <1> "select $c" |
| 89 |
|
| 90 |
load $c |