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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#!/bin/sh
# \
exec wish "$0" "$@"
# browser.tcl --
#
# A mini XML browser
#
# Copyright (c) 2009 Explain
# http://www.explain.com.au/
# Copyright (c) 2003 Zveno Pty Ltd
# http://www.zveno.com/
#
# See the file "LICENSE" in this distribution for information on usage and
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: browser.tcl,v 1.3 2003/12/09 04:56:40 balls Exp $
package require dom
package require domtree
package require domtext
package provide app-browser 3.3
proc Open {} {
global tree text doc view
set fname [tk_getOpenFile]
if {![string length $fname]} {
return {}
}
set ch [open $fname]
set newdoc [dom::parse [read $ch]]
close $ch
$tree configure -rootnode {}
$text configure -rootnode {}
catch {dom::destroy $doc}
set doc $newdoc
if {[lsearch $view tree] >= 0} {
$tree configure -rootnode $doc
}
if {[lsearch $view text] >= 0} {
$text configure -rootnode $doc
}
return {}
}
proc View:tree {} {
global view
set view tree
.controls.view configure -text {Tree & Text} -command View:both
return {}
}
proc View:both {} {
global view
set view {tree text}
.controls.view configure -text {Tree Only} -command View:tree
return {}
}
frame .controls
ttk::button .controls.open -text Open -command Open
ttk::button .controls.view
View:both
grid .controls.open .controls.view -sticky w
set p [ttk::panedwindow .panes -orient horizontal]
grid .controls -row 0 -column 0 -sticky ew
grid $p -row 1 -column 0 -sticky news
grid rowconfigure . 1 -weight 1
grid columnconfigure . 0 -weight 1
ttk::labelframe $p.tree -text {Tree View}
$p add $p.tree
set tree [domtree::create $p.tree.t \
-yscrollcommand [list $p.tree.y set] \
-xscrollcommand [list $p.tree.x set]]
ttk::scrollbar $p.tree.y -orient vertical -command [list $p.tree.t yview]
ttk::scrollbar $p.tree.x -orient horizontal -command [list $p.tree.t xview]
grid $p.tree.t -row 0 -column 0 -sticky news
grid $p.tree.y -row 0 -column 1 -sticky ns
grid $p.tree.x -row 1 -column 0 -sticky ew
grid rowconfigure $p.tree 0 -weight 1
grid columnconfigure $p.tree 0 -weight 1
ttk::labelframe $p.text -text {Source View}
$p add $p.text
set text [domtext::create $p.text.t \
-yscrollcommand [list $p.text.y set] \
-xscrollcommand [list $p.text.x set]]
ttk::scrollbar $p.text.y -orient vertical -command [list $p.text.t yview]
ttk::scrollbar $p.text.x -orient horizontal -command [list $p.text.t xview]
grid $p.text.t -row 0 -column 0 -sticky news
grid $p.text.y -row 0 -column 1 -sticky ns
grid $p.text.x -row 1 -column 0 -sticky ew
grid rowconfigure $p.text 0 -weight 1
grid columnconfigure $p.text 0 -weight 1
|