#!/usr/bin/wish #--------------------------------------------------------------------- # To be used with the C program executable # this script will pass 3 arguments to the executable. # # outputfile, numberofvalues, configurationfile, resultfile # # main(int argc, char** args){ # if(argc == 5) # CGraph* myGraph = new CGraph(args[1], atoi(args[2]), args[3], args[4]); # exit(0); #} #--------------------------------------------------------------------- # kishan@hackorama.com http://www.hackorama.com 1999 #--------------------------------------------------------------------- set outfile test.txt set confile confile.txt set exe /usr/local/bin/echarts set result result.html set msgboxIcon info set msgboxType ok set msgboxMsg "eCharts Message" set msgboxTitle "eCharts Error" set step2flag 1 set step3flag 1 # Genearates the wizard screen Step 1 # Gets values for variables [ numlabels, numvalues ] proc Start_up { } { set step2flag 1 wm title . "eCharts Step1" wm iconname . "eCharts" set font {Helvetica 10} label .linfo -wraplength 4i -font $font -justify left -text "Please Enter the number of Labels and values of your chart" pack .linfo -side top -pady 10 -padx 5 frame .f1 label .f1.lnumlab -text "Number of Labels:" -font $font -justify left entry .f1.enumlab -width 5 -relief sunken -textvariable numlabels pack .f1.lnumlab .f1.enumlab -padx 10 -pady 3 -side left -fill x frame .f2 label .f2.lnumval -text "Number of Values:" -font $font -justify left entry .f2.enumval -width 5 -relief sunken -textvariable numvalues #set $numvalues 0 pack .f2.lnumval .f2.enumval -padx 10 -pady 3 -side left -fill x frame .flogo set font {Helvetica 14 bold} label .flogo.logo1 -font $font -justify left -text "e" label .flogo.logo2 -font $font -justify left -foreground red -text "C" label .flogo.logo3 -font $font -justify left -text "harts" pack .flogo.logo1 .flogo.logo2 .flogo.logo3 -side left -padx 0 -pady 0 frame .fbuts -borderwidth 1 -width 160 button .fbuts.okay -text OK -width 6 -command Step1_ok button .fbuts.quit -text Quit -command exit -width 6 pack .fbuts.quit .fbuts.okay -side right -padx 3 -pady 5 -fill x frame .filler pack .f1 .f2 -side top pack .filler -side top -pady 10 -padx 10 pack .flogo -side left -padx 5 -pady 5 pack .fbuts -side right -padx 5 -pady 5 focus .f1.enumlab } # Data validation for Step 1 # Before going ahead with Step 2 # Called from "Start_up" # Calls Step2 proc Step1_ok { } { global numlabels numvalues msgboxMsg if { $numlabels < 1 } { set msgboxMsg "Please enter a value greater than 1." showMessageBox . } else { if { $numvalues > 0 } { Step2 } } } # Genearates the wizard screen Step 2 # Fills up the arrays [ values, labels ] # Called from "Step1_ok" proc Step2 { } { set step2flag 1 set step3flag 1 wm title . "eCharts Step2" global numlabels numvalues result destroy .linfo .f1 .f2 .fbuts .filler .flogo set font {Helvetica 10} label .linfo -wraplength 4i -font $font -justify left -text "Please Enter the Labels and values of your chart" pack .linfo -side top -pady 10 -padx 5 frame .fmain -borderwidth 3 set icount 1 while {$icount <= $numlabels} { label .fmain.l$icount -text "$icount" -padx 2 entry .fmain.elabel$icount -width 40 -relief sunken -textvariable labels($icount) frame .fmain.f$icount -borderwidth 3 set jcount 1 while { $jcount <= $numvalues } { entry .fmain.f$icount.e$icount$jcount -width 5 -relief sunken -textvariable values($icount,$jcount) pack .fmain.f$icount.e$icount$jcount -side left -padx 3 incr jcount } grid .fmain.l$icount .fmain.elabel$icount .fmain.f$icount incr icount } pack .fmain -side top frame .filler #frame .ffile #set font {Helvetica 10} #label .ffile.lfile -text "Save the chart as:" -font $font -justify left #entry .ffile.efile -width 20 -relief sunken -textvariable result #button .ffile.bfile -text "Browse ..." -command "fileDialog . .ffile.efile save" #pack .ffile.lfile -padx 1 -pady 3 -side left -fill x #pack .ffile.efile -padx 1 -pady 3 -side left -expand yes -fill x #pack .ffile.bfile -padx 1 -pady 3 -side left -fill x frame .flogo set font {Helvetica 14 bold} label .flogo.logo1 -font $font -justify left -text "e" label .flogo.logo2 -font $font -justify left -foreground red -text "C" label .flogo.logo3 -font $font -justify left -text "harts" pack .flogo.logo1 .flogo.logo2 .flogo.logo3 -side left -padx 0 -pady 0 frame .fbuts -borderwidth 1 button .fbuts.back -width 6 -text "< Back" -command Back_tostep1 #button .fbuts.okay -width 6 -text OK -command Step2_ok button .fbuts.next -width 6 -text "Next >" -command Step2_next button .fbuts.quit -width 6 -text Done -command exit #pack .fbuts.back .fbuts.okay .fbuts.next .fbuts.quit -side left -padx 3 -pady 5 -fill x pack .fbuts.back .fbuts.next .fbuts.quit -side left -padx 3 -pady 5 -fill x #pack .ffile -pady 5 -side top pack .filler -pady 10 -side top pack .flogo -side left -padx 0 -pady 5 pack .fbuts -side right -padx 0 -pady 5 if {$numlabels >= 1} { focus .fmain.elabel1 } } # Invokes the back engine binary # Configures the labels and buttons with new labels # Calls "Step2_write" to store the values # Called from "Step2" proc Step2_ok { } { global outfile confile exe numvalues result step2flag if { $step2flag == 1 } { set step2flag 0 #update the data files Step2_write #execute the c++ back engine exec $exe $outfile $numvalues $confile $result .linfo configure -foreground black -text "Please open the file $result in a browser" .fbuts.okay configure -foreground black -text "Update" } else { #update the data files Step2_write #execute the c++ back engine exec $exe $outfile $numvalues $confile $result .linfo configure -foreground black -text "The file $result was updated, reload in browser" .fbuts.okay configure -foreground black -text "Update" } } # Dumps the values in [ values, labels ] # into a tab separated text file # Called from "Step2_ok" # Called from "Step2_next" proc Step2_write { } { global values labels numlabels numvalues outfile confile exe set fileid [open $outfile w 0600] set icount 1 while {$icount <= $numlabels} { puts -nonewline $fileid "$labels($icount) " set jcount 1 while { $jcount <= $numvalues } { puts -nonewline $fileid "$values($icount,$jcount) " incr jcount } puts $fileid "" incr icount } close $fileid } # Data validation for Step 2 # Called from "Step2_ok" # Called from "Step2_next" proc Step2_validate { } { } # Go back to Step 1 # Remove all widgets in Step 2 # Recreate widgets in Step 1 # Called from "Step1_ok" # Calls "Start_up" proc Back_tostep1 { } { global numlabels numvalues destroy .fbuts .linfo .filler .ffile .flogo .fmain Start_up } # Data validation for Step 2 # Before going ahead with Step 3 # Called from "Step2" # Calls "Step3" proc Step2_next { } { #update the data files Step2_write Step3 } # Genearates the wizard screen Step 3 # Remove all widgets in Step 2 # Called from "Step2_next" proc Step3 { } { set step2flag 1 set step3flag 1 global numlabels numvalues outfile wm title . "eCharts Step3" destroy .fbuts .linfo .filler .ffile .flogo .fmain set font {Helvetica 10} label .linfo -wraplength 4i -font $font -justify left -text "Please Enter the Titles and Legends for the Chart" pack .linfo -side top -pady 10 -padx 5 frame .fmain label .fmain.lmaint -text "Main Title:" -font $font -justify left entry .fmain.emaint -width 40 -relief sunken -textvariable maintitle grid .fmain.lmaint .fmain.emaint -padx 3 -pady 5 grid .fmain.lmaint -sticky w grid .fmain.emaint -sticky e label .fmain.llabelt -text "Label Title:" -font $font -justify left entry .fmain.elabelt -width 40 -relief sunken -textvariable labeltitle grid .fmain.llabelt .fmain.elabelt -padx 3 -pady 5 grid .fmain.llabelt -sticky w grid .fmain.elabelt -sticky e label .fmain.lvaluet -text "Value Title:" -font $font -justify left entry .fmain.evaluet -width 40 -relief sunken -textvariable valuetitle grid .fmain.lvaluet .fmain.evaluet -padx 3 -pady 5 grid .fmain.lvaluet -sticky w grid .fmain.evaluet -sticky e set count 1 while { $count <= $numvalues } { label .fmain.llegendt$count -text "Legend $count:" -font $font -justify left entry .fmain.elegendt$count -width 40 -relief sunken -textvariable legendtitle($count) grid .fmain.llegendt$count .fmain.elegendt$count -padx 3 -pady 5 grid .fmain.llegendt$count -sticky w grid .fmain.elegendt$count -sticky e incr count } set font {Helvetica 10} label .fmain.lfile -text "Save as:" -font $font -justify left frame .fmain.ffile entry .fmain.ffile.efile -width 25 -relief sunken -textvariable result button .fmain.ffile.bfile -width 10 -font $font -text "Browse..." -command "fileDialog . .fmain.ffile.efile save" pack .fmain.ffile.efile -side left -expand yes -fill x pack .fmain.ffile.bfile -side left -fill x grid .fmain.lfile .fmain.ffile -padx 3 -pady 5 grid .fmain.lfile -sticky w grid .fmain.ffile -sticky e pack .fmain -side top frame .filler frame .flogo set font {Helvetica 14 bold} label .flogo.logo1 -font $font -justify left -text "e" label .flogo.logo2 -font $font -justify left -foreground red -text "C" label .flogo.logo3 -font $font -justify left -text "harts" pack .flogo.logo1 .flogo.logo2 .flogo.logo3 -side left -padx 0 -pady 0 frame .fbuts -borderwidth 1 button .fbuts.back -width 6 -text "< Back" -command Back_tostep2 button .fbuts.okay -width 6 -text "OK" -command Step3_ok #button .fbuts.next -width 6 -text "Next >" -command Step3_next button .fbuts.quit -width 6 -text Done -command exit pack .fbuts.back .fbuts.okay .fbuts.quit -side left -padx 3 -pady 5 -fill x #pack .fbuts.back .fbuts.okay .fbuts.next .fbuts.quit -side left -padx 3 -pady 5 -fill x pack .filler -pady 10 -side top pack .flogo -side left -padx 0 -pady 5 pack .fbuts -side right -padx 0 -pady 5 if {$numlabels >= 1} { focus .fmain.emaint } } # Go back to Step 2 # Remove all widgets in Step 3 # Recreate widgets in Step 2 # Called from "Step3" # Calls "Step2" proc Back_tostep2 { } { global numlabels numvalues destroy .linfo .fmain .filler .flogo .fbuts Step2 } # Invokes the back engine binary # Calls "Step3_write" to store the values # Configures the labels and buttons with new labels # Called from "Step3" proc Step3_ok { } { global numvalues outfile confile exe step3flag result #update the data files Step3_write #execute the c++ back engine exec $exe $outfile $numvalues $confile $result if { $step3flag == 1 } { .linfo configure -text "Please open the file $result in a browser" .fbuts.okay configure -text "Update" set step3flag 0 } else { .linfo configure -text "The file $result was updated, reload in browser" .fbuts.okay configure -text "Update" } } # Dumps the titles and legends # into a tab separated text file # Called from "Step3_ok" # Called from "Step3_next" proc Step3_write { } { global numvalues confile maintitle labeltitle valuetitle legendtitle set fileid [open $confile w 0600] puts $fileid "MAINTITLE $maintitle" puts $fileid "LABELTITLE $labeltitle" puts $fileid "VALUETITLE $valuetitle" set count 1 while {$count <= $numvalues} { puts $fileid "VALUELEGEND $legendtitle($count)" incr count } close $fileid } # Data validation for Step 3 # Called from "Step3_ok" # Called from "Step3_next" proc Step3_validate { } { } # Generic Message box # Configure using [ msgboxIcon msgboxType msgboxMsg ] # Called from "Step1_ok" proc showMessageBox {w} { global msgboxIcon msgboxType msgboxMsg msgboxTitle tk_messageBox -icon $msgboxIcon -type $msgboxType \ -title $msgboxTitle -parent $w -message $msgboxMsg } # Generic Message boxFile Selection # For Saving/Opening a file # Called from "Step3" proc fileDialog { . efile operation} { #----------------------------------------------------------- # Type names Extension(s) Mac File Type(s) #----------------------------------------------------------- set types { {"HTML Files" {.html .htm} } {"HTML Files" {} HTML} {"Text files" {.txt .doc} } {"Text files" {} TEXT} {"All files" *} } if {$operation == "open"} { set file [tk_getOpenFile -filetypes $types -parent .] } else { set file [tk_getSaveFile -filetypes $types -parent . \ -initialfile Untitled -defaultextension .html] } if [string compare $file ""] { $efile delete 0 end $efile insert 0 $file $efile xview end } } # # Let it all start ! # Start_up