application_runner_&_wrapper

application_runner_&_wrapper

This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Aside from your courtesy, your wiki MONIKER and date as a signature and minimal good faith of any internet post are the rules of this TCL-WIKI. Its very hard to reply reasonably without some background of the correspondent on his WIKI bio page. Thanks, gold 12Dec2018



Introduction


gold Here is a stater on an application_runner in TCL. A runner or wrapper is slang for a program that uses or services a computation engine, usually in another or second computer language. Runners have been used to port or extend the use of legacy fortran codes, although there is some controversy on the efficiency of these applications.


Source code

# application_runner_&_wrapper.tcl --
# gold, tcl wiki script on 20060601
# modified to
# demo script in Expect 5.21
# TCL8 distribution, for Win95 use
# modified to  TCL8 distribution
#start of deck
# SCCS: @(#)   1.16 97/03/02 16:25:05
# GLOBAL VARIABLES
#
frame .f1
frame .f2
frame .f3
pack  .f1 .f2 .f3

catch {
    global filex
    set filex "1"
    global obj
    set obj {1}
    global widget
    set widget {TEST}
}

#################################
# USER DEFINED PROCEDURES
#
proc init {argc argv} {

}

init $argc $argv

proc main {argc argv} {
    global widget
    # $widget insert end "forced text"
    .list insert end "end of show!!!"
    .sorted insert end "end of show!!!"
}

proc Window {args} {
    global vTcl
    set cmd [lindex $args 0]
    set name [lindex $args 1]
    set rest [lrange $args 2 end]
    if {$name == "" || $cmd == ""} {return}
    set exists [winfo exists $name]
    switch $cmd {
        show {
            if {[info procs vTclWindow(pre)$name] != ""} {
                vTclWindow(pre)$name $rest
            }
            if {[info procs vTclWindow$name] != ""} {
                vTclWindow$name
            }
            if {[info procs vTclWindow(post)$name] != ""} {
                vTclWindow(post)$name $rest
            }
        }
        hide    { if $exists {wm withdraw $name; return} }
        iconify { if $exists {wm iconify $name; return} }
        destroy { if $exists {destroy $name; return} }
    }
}

proc browse {dir file} {
    global env
    #global file
    global filex
    global dirx
    set filex ""
    set dirx ""
    catch {if {[string compare $dir "."] != 0} {set file $dir/$file }}
    set filex $file
    #exec "\"C:/program files/microsoft office/office/winword\"" $file &
    #exec "\C:\/ ted\ " &
    # exec "ted" &
    #exec [C:\/Program\ Files \/Microsoft\ Office/Office/Winword] $file &
    #exec [C:\\Program\ Files\\Microsoft\ Office\\Office\\Winword] $file &
    #.entry01 insert end " "
    # .entry02 insert end " "
    set clipped_directory "2";
    set clipped_directory [file dirname $dir]
    .entry01 delete 0 end

    .entry02 delete 0 end

    #.entry01 insert end $dir
    .entry01 insert end [file dirname $dir]
    .entry01 insert end [eval file dirname  [eval file dirname $dir]]
    .entry02 insert end $filex
}

#################################
# VTCL GENERATED GUI PROCEDURES
#

button .button01 -text APPLICATION -command {C:\/Program\ Files\/Microsoft\ Office\/Office\/Winword}
# TCL has long noses for Microsoft
button .button02 -text EDIT -command \
{C:\/Program\ Files\/Microsoft\ Office\/Office\/Winword}

button .button03 -text EXIT -command {exit}
button .button04 -text RESET -command {browse $dir $i}
pack .button01 .button02 .button03 \
.button04 -in .f1 -side right
entry .entry01 \
     -textvariable $filex -justify left -width 50 -state normal
label .label02 \
       -text "target directory" -justify center -width 20
label .label01 \
       -text "target file" -justify center -width 20
entry .entry02  \
     -textvariable $filex -justify left -width 50 -state normal
pack .label01 -side bottom -fill y
pack .entry01 -side bottom -fill y
pack .label02 -side bottom -fill y
pack .entry02 -side bottom -fill y

# Create a scrollbar on the right side of the main window and a listbox
# on the left side.

scrollbar .scroll -command ".list yview"

listbox .list -yscroll ".scroll set" -relief sunken -width 20 -height 20 \
    -setgrid yes

pack .list -side left -fill both -expand yes

listbox .sorted -yscroll ".scroll set" \
    -width 20 -height 20

pack .sorted -side right

scrollbar .scrollx -command \
    ".sorted yview"

pack .scrollx -side right -fill y
pack .scroll -side right -fill y

# Fill the listbox with a list of all the files in the directory (run
# the "ls" command to get that information).
if {$argc > 0} {
    set dir [lindex $argv 0]
} else {
        set dir .
}

foreach i [lsort [glob * .*]] {
    #.list insert end $i
    .sorted insert end $i
}
foreach i [lsort [glob  {\*}]] {
    .list insert end $i
    #.sorted insert end $i
}

# Set up bindings for the browser.

bind all <Control-c> {destroy .}
bind .list <Double-Button-1> {foreach i [selection get] {browse $dir $i} }

bind .sorted <Double-Button-1> {foreach i [selection get] {browse $dir $i} }

main $argc $argv

References

Web References

  • Google Tutorials, [L4 ]

Earlier Version

#application_runner_&_wrapper!
global filex
set filex "1"
global obj; set obj {1}
global widget; 
set widget {TEST}

#################################
# USER DEFINED PROCEDURES
#
proc init {argc argv} {

}

init $argc $argv


proc main {argc argv} {
    global widget
    # $widget insert end "forced text"
    .list insert end "end of show!!!"
    .sorted insert end "end of show!!!"
}

proc Window {args} {
     global vTcl
     set cmd [lindex $args 0]
     set name [lindex $args 1]
     set rest [lrange $args 2 end]
     if {$name == "" || $cmd == ""} {return}
     set exists [winfo exists $name]
     switch $cmd {
         show {
             if {[info procs vTclWindow(pre)$name] != ""} {
                 vTclWindow(pre)$name $rest
             }
             if {[info procs vTclWindow$name] != ""} {
                 vTclWindow$name
             }
             if {[info procs vTclWindow(post)$name] != ""} {
                 vTclWindow(post)$name $rest
             }
         }
         hide    { if $exists {wm withdraw $name; return} }
         iconify { if $exists {wm iconify $name; return} }
         destroy { if $exists {destroy $name; return} }
     }
}

proc browse {dir file} {
    global env
    #global file
    global filex
    global dirx
    set filex ""
    set dirx ""
    catch {if {[string compare $dir "."] != 0} {set file $dir/$file }}
    set filex $file
    #exec "\"C:/program files/microsoft office/office/winword\"" $file &
    #exec "\C:\/ ted\ " &
    # exec "ted" &
    #exec [C:\/Program\ Files \/Microsoft\ Office/Office/Winword] $file &
    #exec [C:\\Program\ Files\\Microsoft\ Office\\Office\\Winword] $file &
    #.entry01 insert end " "
    # .entry02 insert end " "
    set clipped_directory "2";
    set clipped_directory [file dirname $dir]
    .entry01 delete 0 end
    
    .entry02 delete 0 end
    
    #  .entry01 insert end $dir
    .entry01 insert end [file dirname $dir]
    .entry01 insert end [eval file dirname  [eval file dirname $dir]]
    .entry02 insert end $filex
}
#################################
# VTCL GENERATED GUI PROCEDURES
#

button .button01 -text APPLICATION -command {C:\/Program\ Files\/Microsoft\ Office\/Office\/Winword}  
# TCL has long noses for Microsoft
button .button02 -text EDIT -command \
{C:\/Program\ Files\/Microsoft\ Office\/Office\/Winword} 

button .button03 -text EXIT -command {exit} 
button .button04 -text RESET -command {browse $dir $i} 
pack .button01 .button02 .button03 \
.button04  

entry .entry01 \
    -font   \
    -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
    -textvariable $filex -justify left -width 50 -state normal

label .label02 \
    -text "target directory" -justify center -width 20 

label .label01 \
    -text "target file" -justify center -width 20 

entry .entry02 \
    -font   \
    -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* \
    -textvariable $filex -justify left -width 50 -state normal

pack .label01 -side bottom -fill y
pack .entry01 -side bottom -fill y
pack .label02 -side bottom -fill y
pack .entry02 -side bottom -fill y
# Create a scrollbar on the right side of the main window and a listbox
# on the left side.

scrollbar .scroll -command ".list yview"


listbox .list -yscroll ".scroll set" -relief sunken -width 20 -height 20 \
    -setgrid yes


pack .list -side left -fill both -expand yes

listbox .sorted -yscroll ".scroll set" \
    -width 20 -height 20
  
pack .sorted -side right

scrollbar .scrollx -command \
    ".sorted yview"

pack .scrollx -side right -fill y
pack .scroll -side right -fill y

# Fill the listbox with a list of all the files in the directory (run
# the "ls" command to get that information).
if {$argc > 0} {
    set dir [lindex $argv 0]
} else {
    set dir .
}

foreach i [lsort [glob * .*]] {
    #.list insert end $i
    .sorted insert end $i
}

foreach i [lsort [glob  {\*}]] {
    .list insert end $i
    #.sorted insert end $i
}


# Set up bindings for the browser.

bind all <Control-c> {destroy .}
bind .list <Double-Button-1> {foreach i [selection get] {browse $dir $i} }

bind .sorted <Double-Button-1> {foreach i [selection get] {browse $dir $i} }


main $argc $argv
# loaded on tcl wiki tcl8
# 2JUn2006, goldshell7

Followup scraps of code

Text from Ask, and it shall be given # 9: How to run external script from Tk and make it throw output to the console?

gold 2011-05-10, Perhaps, exec, https://www.tcl-lang.org/man/tcl8.5/TclCmd/exec.htm , https://www.tcl-lang.org/faq/tclwin.htm , https://www.tcl-lang.org/man/tcl/tutorial/Tcl26.html and A minimal console would be a good place to start.

Many commands in TCL are effectively scripts to themselves; try "eval exit" on your console. A session from the Etcl console on a an XP windows.

Directory of C:\Program Files\Evolane\eTcl\bin
4% set output5 [ dir ] #using catch and windows command
5% puts $output5    2% exec etcl.exe king4.tcl 
9% exec king4.exe # using freewrap compiled tcl executable
11% eval exec etcl.exe king4.tcl
12% console eval {pack [button .b -text hello -command {puts hello}]}
from https://wiki.tcl-lang.org/67212
%13 console eval {pack [button .bpanic -text panic -command { exec etcl.exe king4.tcl }]} 
%14 set output [exec external_program_king4.exe arg1 arg2 arg3]
%15 set output [exec etcl.exe external_script_king4.tcl arg1 arg2 arg3]
#using catch []  for non zero return, Ralf Fassel 
%16 puts $output
%17 console eval {pack [button .b2 -text hello -command {puts $output}]}

The application_runner_&_wrapper, Combining Fortran and Tcl in one program and Managing Fortran programs are some starter code for calling on external programs and external scripts. Also, the pull down menu on the etcl console has buttons for sourcing and executing TCL code.


Some years ago, i had a script that used exec in a display button. The tricky part on the exec statement was that unix and microsoft had different file location structures ( backslash \ or forward slash / on the pc, for example). One can play with the buttons on Simple Canvas Demo, appendix demo and load a button like

button .b7 -text "new_game" -command { exec etcl.exe king4.tcl } -background $colorite
button .b8 -text "exit" -command { eval exit }

If you are a thumb typist like me, you'll soon find why a stored command in a button is used.


gold 2011-05-10, Perhaps, exec, https://www.tcl-lang.org/man/tcl8.5/TclCmd/exec.htm , https://www.tcl-lang.org/faq/tclwin.htm , https://www.tcl-lang.org/man/tcl/tutorial/Tcl26.html and A minimal console would be a good place to start.

A session from the Etcl console on a an XP windows.

2% exec etcl.exe king4.tcl 
9% exec king4.exe # using freewrap compiled tcl executable
11% eval exec etcl.exe king4.tcl
12% set output5 [exec etcl.exe external_script_king4.tcl ]
15% puts $output5
17% set tip [ more king4.tcl] #using  more to grab script
16% eval $tip
17% console eval $tip # may overwrite console display or functions
load hello.tcl (text file) as one line, puts "overwrite hello"
18% source hello.tcl #should see "overwrite hello" on console window
load pie.tcl (text file) as one line, proc pi {} {expr acos(-1)}
19% source pie.tcl
20% set piepie [ pi ]; puts $piepie
answer: 3.141592653589793

The application_runner_&_wrapper, Combining Fortran and Tcl in one program and Managing Fortran programs are some starter code for calling on external programs and external scripts. Also, the pull down menu on the etcl console has buttons for sourcing and executing TCL code.


Hidden Comments Section

Please place any comments here with your wiki MONIKER and date, Thanks.gold12Dec2018