• Is it possible to make a tcl script both graphical (tk) and console (tc

    From pd@21:1/5 to All on Sun Nov 26 16:25:03 2023
    I have a little tcl script for system operation, basically it get some data and call a system command to do an action.

    I'd like to have a graphical frontend in tk to fill the form with right values and use them to construct the call to the command (a windows exe program)

    But I also want to directly call the program if you call the tcl script with parameters and in this case to show info in the console (and stdout or stderr).

    I know I can make to scripts, one for tk and another one for console tcl, but I want to merge them both in one script because the share almost all the code and because I consider it a challenge ;-)

    My first idea was to have a Tk script with widget and a button to call the windows exe program with right parameters, and also call directly the windows program if you call the script with right number of arguments.
    Something like this:

    ---my.tcl--------------------------------------------------------
    package require Tk

    set cmd scite

    if { $argc > 2 } {
    wm withdraw .
    puts "executing $cmd"
    exec $cmd [lindex $argv 0] [lindex $argv 1] [lindex $argv 2]
    exit
    }

    entry .e1 -textvariable p1
    entry .e2 -textvariable p2
    entry .e3 -textvariable p3
    button .b -text "Do it" -command {exec $cmd $p1 $p2 $p3}
    pack .e1 .e2 .e3 .b --------------------------------------------------------------------

    And now I can execute the script from console as "wish my.tcl" to get a tk frontend or as "wish my.tcl a b c" to execute the command scite with parameters a b c and no graphical fronted

    The problem is the puts writing to stdout does not write to the console but to the graphical console emulator if I show it previously, but in this case I see the output in the graphical console rather than real text console, and also the graphical
    console isn't any help since I have to call exit to finish the tk event loop and the script.

    If I redirect stdin or stderr to a file I get the output in the file as expected, but I want to show it in the text console.

    So, my question, Is any way to merge a console app and a graphical app in the same tcl script?

    Really I'm wrapping the script in a starkit so another point of view is, is there any way to pack in a starkit (starpack) a console app and a graphical app deciding to call one or another based in some criteria?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From pd@21:1/5 to All on Sun Nov 26 16:39:12 2023
    El lunes, 27 de noviembre de 2023 a las 1:25:06 UTC+1, pd escribió:

    So, my question, Is any way to merge a console app and a graphical app in the same tcl script?

    Really I'm wrapping the script in a starkit so another point of view is, is there any way to pack in a starkit (starpack) a console app and a graphical app deciding to call one or another based in some criteria?

    Ok, I answer myself after simple testing, it's so easy to do that, simply refactor the script as:

    ----my.tcl---------------------------------------------------------
    set cmd scite

    if { $argc > 2 } {
    puts "executing $cmd"
    exec $cmd [lindex $argv 0] [lindex $argv 1] [lindex $argv 2]
    exit
    } else {

    package require Tk

    entry .e1 -textvariable p1
    entry .e2 -textvariable p2
    entry .e3 -textvariable p3
    button .b -text "Do it" -command {exec $cmd $p1 $p2 $p3}
    pack .e1 .e2 .e3 .b
    }
    -----------------------------------------------------------------------

    and execute it using tclsh rather than wish

    sorry for that silly question!

    regards

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From pd@21:1/5 to All on Sun Nov 26 17:02:30 2023
    El lunes, 27 de noviembre de 2023 a las 1:39:15 UTC+1, pd escribió:
    El lunes, 27 de noviembre de 2023 a las 1:25:06 UTC+1, pd escribió:

    Really I'm wrapping the script in a starkit so another point of view is, is there any way to pack in a starkit (starpack) a console app and a graphical app deciding to call one or another based in some criteria?
    Ok, I answer myself after simple testing, it's so easy to do that, simply refactor the script as:

    well not so easy after all, the problem arises when trying to make a starkit, if I use a tclkit with Tk I get the problem of emulated console since it seems to use wish or init tk somehow and if I use a tclkitsh then I don't have Tk, any idea? thanks

    regards

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)