The following code reads from a file called build.txt. Inside Build.tx are these elements:
VisualDSP Apex ; C:\program files\tools\run.bat
VisualDSP SHARC ; C:\program files\docs\run.bat
I set it up so only the text before the semicolon appears in the list box. My problem is how do I get it so when the button is pressed, it will output the path and execute run.bat?
wm title . "Automated Builds"
. config -bg grey50
label .label1 -text "Select which kit to build:"
pack .label1
proc Scroll_Set {scrollbar geoCmd offset size} {
if {$offset != 0.0 || $size != 1.0} {
eval $geoCmd;
$scrollbar set $offset $size
} else {
set manager [lindex $geoCmd 0]
$manager forget $scrollbar;
}
}
proc Scrolled_Listbox {f args} {
# Creates the scroll bar
frame $f
listbox $f.list -xscrollcommand [list Scroll_Set $f.xscroll [list grid $f.xscroll -row 1 -column 0 -sticky we]] -yscrollcommand [list Scroll_Set $f.yscroll [list grid $f.yscroll -row 0 -column 1 -sticky ns]]
eval {$f.list configure} $args
scrollbar $f.xscroll -orient horizontal -command [list $f.list xview]
scrollbar $f.yscroll -orient vertical -command [list $f.list yview]
grid $f.list $f.yscroll -sticky news
grid $f.xscroll -sticky news
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f.list
}
proc List_Select { parent values } {
# Creates two lists side by side
frame $parent
set choices [Scrolled_Listbox $parent.choices -width 20 -height 5]
pack $parent.choices -side left -expand true -fill both
#Insert all the choices
foreach x $values {
$choices insert end $x
}
}
set t [Scrolled_Listbox .f -width 40 -height 8]
pack .f -side top -fill both -expand true
set in [open "/tcl scripts/build.txt"]
while { ![eof $in]} {
### Seperates Before and After the colon.
set line_of_file [gets $in]
set length [string length $line_of_file]
set Before_colon [string first ";" $line_of_file]
set math [expr $Before_colon - 1]
set tool [string range $line_of_file 0 $math]
set math2 [expr $Before_colon + 2]
set path [string range $line_of_file $math2 end]
puts $path
$t insert end $tool
}
close $in
############# How do I get button to output path and ###############execute run.bat?
button .one -text "build" -command { set index [.f.list curselection]
if {$index != ""} {
puts [.f.list get $index]
}
}
pack .one -side right
Scrolled_Listbox
VisualDSP Apex ; C:\program files\tools\run.bat
VisualDSP SHARC ; C:\program files\docs\run.bat
I set it up so only the text before the semicolon appears in the list box. My problem is how do I get it so when the button is pressed, it will output the path and execute run.bat?
wm title . "Automated Builds"
. config -bg grey50
label .label1 -text "Select which kit to build:"
pack .label1
proc Scroll_Set {scrollbar geoCmd offset size} {
if {$offset != 0.0 || $size != 1.0} {
eval $geoCmd;
$scrollbar set $offset $size
} else {
set manager [lindex $geoCmd 0]
$manager forget $scrollbar;
}
}
proc Scrolled_Listbox {f args} {
# Creates the scroll bar
frame $f
listbox $f.list -xscrollcommand [list Scroll_Set $f.xscroll [list grid $f.xscroll -row 1 -column 0 -sticky we]] -yscrollcommand [list Scroll_Set $f.yscroll [list grid $f.yscroll -row 0 -column 1 -sticky ns]]
eval {$f.list configure} $args
scrollbar $f.xscroll -orient horizontal -command [list $f.list xview]
scrollbar $f.yscroll -orient vertical -command [list $f.list yview]
grid $f.list $f.yscroll -sticky news
grid $f.xscroll -sticky news
grid rowconfigure $f 0 -weight 1
grid columnconfigure $f 0 -weight 1
return $f.list
}
proc List_Select { parent values } {
# Creates two lists side by side
frame $parent
set choices [Scrolled_Listbox $parent.choices -width 20 -height 5]
pack $parent.choices -side left -expand true -fill both
#Insert all the choices
foreach x $values {
$choices insert end $x
}
}
set t [Scrolled_Listbox .f -width 40 -height 8]
pack .f -side top -fill both -expand true
set in [open "/tcl scripts/build.txt"]
while { ![eof $in]} {
### Seperates Before and After the colon.
set line_of_file [gets $in]
set length [string length $line_of_file]
set Before_colon [string first ";" $line_of_file]
set math [expr $Before_colon - 1]
set tool [string range $line_of_file 0 $math]
set math2 [expr $Before_colon + 2]
set path [string range $line_of_file $math2 end]
puts $path
$t insert end $tool
}
close $in
############# How do I get button to output path and ###############execute run.bat?
button .one -text "build" -command { set index [.f.list curselection]
if {$index != ""} {
puts [.f.list get $index]
}
}
pack .one -side right
Scrolled_Listbox