tcltk-toolkittcltkstarkit

tcl/tk - dependency library issue in multifile starkit


I am trying to create a starkit consisting of multiple tcl source files, which can be executed without problem on my machine with wish. However, on trying to do the same with tclkit, I got this error from one of the second level source files sourced from the toplevel one directly sourced from main.tcl.

unknown or ambiguous item type "waveform"
    while executing
"$c create waveform 0 0 -sound snd -height $v(waveh) -width $v(cWidth)  -tags [list obj wave] -debug $::debug -fill $v(wavColor) -limit $v(waveScale)"
    invoked from within
"if $v(showWave) {
    $c create waveform 0 0 -sound snd -height $v(waveh) -width $v(cWidth)  -tags [list obj wave] -debug $::debug -fill $v(wavColor) ..."
    (procedure "Redraw" line 28)
    invoked from within
"Redraw all"
    (procedure "resetDisplay" line 21)
    invoked from within
"resetDisplay"
    (file "MYAPPLICATION.vfs/TOPLEVEL.tcl" line 591)

waveform is from snack library, so I investigated it. The library does not have unresolved external dependency and the error would have occured much earlier if the library could not be used at all, so I have tried the following:

None of the above works. The only working way I have found is to combine all the source files into one by substituting sources. Therefore, I suspect this to be some kind of race condition, but I am neither able to prove it nor to debug it.

Sorry if I am missing anything important here (pretty new to tcl/tk). Would really appreciate any suggestions. Thanks very much in advance! :)


Solution

  • Snack is primarily a sound toolkit. It adds a snack::sound command to Tcl for working with audio (playback, recording, etc.). When used in combination with Tk, it also adds a waveform item type to the Tk canvas. For this to work, Tk has to be loaded before snack. When using wish, Tk is loaded from the start. But with a tclkit (unless running on windows), Tk has to be loaded with a package require Tk command.

    I can reproduce your error using the following code:

    package require snack
    package require Tk
    
    snack::sound snd
    snd read foo.wav
    
    canvas .c
    .c create waveform 0 0 -sound snd
    

    The error goes away when I swap the first two lines around. So:

    package require Tk
    package require snack