Building Starpacks with ttask

ttask - http://pdt.github.com/ttask.html

pdt 11/7/2012 - ttask is something I'm currently working on. The initial reason for writing it was for FPGA development, but I also want it for other things as well. Currently I'm developing/running it on Linux only.

Although I want to be able to create Starpacks easily, I also like to structure source files according to what works for me, rather than structuring in a tclkit vfs, for easy wrapping. Hence the reason for the ttask tclkit extension, http://pdt.github.com/tclkit_extension.html

On the tclkit extension page there are some examples. Below is another, a simple temperature converter app.

http://pdt.github.com/temp_conv.png

The source tree for the app is as follows:

temp_app/
   src/
       gui.tcl
       nso.tcl
   ttaskfile.tcl

The contents of the ttaskfile build script is as follows:

config linuxRuntime ~/tclkit/tclkit-8.5.9-linux-ix86
config winRuntime ~/tclkit/tclkit-8.5.9-win32.upx.exe

task build {
    tclkit build -exe all -runtime $linuxRuntime
    tclkit build -exe wrap -runtime $winRuntime
}
task clean {rmdir build}
        
project add tclkit -type tclkit 
tclkit src -srcDir src -add *.tcl
tclkit build -buildDir build -prepare gui.tcl -name temp_conv

The ttaskfile.tcl build script sets two runtimes (with config, should they need be overridden on the command line). Then we have two tasks. The first one is the build task, which creates the vfs in the build directory, and wraps twice, once with the Linux runtime and again with the Windows runtime. The second task simply deletes the build directory. Finally the project is defined, which here means specifying the source files, a build directory, the file to prepare (i.e. the main entry file), and the name of the executable.

Typing ttask in a terminal, in the directory containing the build script, runs the build task:

> ttask
tclkit: sdx wrap temp_conv -runtime ~/tclkit/tclkit-8.5.9-linux-ix86
5 updates applied
tclkit: sdx wrap temp_conv.exe -runtime ~/tclkit/tclkit-8.5.9-win32.upx.exe
5 updates applied

The newly created build directory has the two executables and the VFS:

> ls build/
temp_conv temp_conv.exe temp_conv.vfs

We can remove the build directory by running the clean task

> ttask clean
> ls
src ttaskfile.tcl

The app can be run, either by running 'tclsh gui.tcl' in the src directory, or by running one of the Starpack binaries in the build directory. Because '-prepare gui.tcl' was specified in the build script, a package provide line was automatically added to the top of the gui.tcl file:

> head --lines 2 build/temp_conv.vfs/lib/app-temp_conv/gui.tcl 
package provide app-temp_conv 1.0
package require Tk

For completeness, here is the contents of the gui.tcl file in src/ directory:

package require Tk
source [file dir [file normalize [info script]]]/nso.tcl
namespace import ::nso::*

class Gui {
    private variables celcius fahrenheit

    constructor {} {
        buildGui
    }

    private method toCelcius {} {
        set degC error
        catch {set degC [format %.1f [expr {($fahrenheit - 32) * 5.0 / 9.0}]]}
        set celcius $degC
    }

    private method toFahrenheit {} {
        set degF error
        catch {set degF [format %.1f [expr {$celcius * 9.0 / 5.0 + 32}]]}
        set fahrenheit $degF
    }

    private method buildGui {} {
        set ns [namespace current]

        wm title . "Temperature Converter"
        ttk::frame .f 
        ttk::frame .f.main -padding 5
        ttk::label .f.main.celciusLabel -text "Celcius:"
        ttk::entry .f.main.celciusEntry  -width 7 -textvar ${ns}::celcius
        ttk::label .f.main.fahrenheitLabel -text "Fahrenheit:"
        ttk::entry .f.main.fahrenheitEntry -width 7 -textvar ${ns}::fahrenheit
        ttk::frame .f.buttons -padding 5
        ttk::button .f.buttons.toCelciusButton -text "To Celcius" \
                -command ${ns}::toCelcius
        ttk::button .f.buttons.toFahrenheitButton -text "To Fahrenheit" \
                -command ${ns}::toFahrenheit
        
        grid .f -sticky nsew
        grid .f.main 
        grid .f.main.celciusLabel .f.main.celciusEntry \
                .f.main.fahrenheitLabel .f.main.fahrenheitEntry
        grid .f.buttons 
        grid .f.buttons.toFahrenheitButton .f.buttons.toCelciusButton 

        grid configure .f.main.fahrenheitLabel -padx {10 0}
        grid configure .f.buttons.toCelciusButton -padx {10 0}
    }
}

new Gui

And the nso.tcl file is from my NSO project, at https://github.com/pdt/nso .