Re: Odd error when closing a window.



Dave (from the UK) wrote:
Hi,
I have a bit of long procedure (::tools::twic) which open a new window, amongst other thing. It has a 'Download' and a 'Cancel' button - see below. Closing the Window works fine, but if I hit the download button first, then try to hit Cancel, it generates an error.



proc ::tools::twic {} {
set w .twicWin
if {[winfo exists $w]} {
destroy .twicWin
set twicWin 0
return
}
set twicWin 1
toplevel $w
wm title $w [tr TitleDownloadFromTWIC]
wm minsize $w 25 10
bind $w <Destroy> {set .twicWin 0}
bind $w <F1> {helpWindow TWIC}

# Frame 1
set tf [frame $w.tf]
set txt [text $tf.txt -wrap word]
set yscroll [scrollbar $tf.yscroll -orient vertical -command [list $txt\
yview]]
$txt configure -yscrollcommand [list $yscroll set]
grid $txt -sticky news
grid $yscroll -column 1 -row 0 -sticky ns
grid rowconfigure $tf 0 -weight 1
grid columnconfigure $tf 0 -weight 1

$tf.txt tag configure h1 -font "helvetica 16" -underline on

$tf.txt tag configure h2 -font "helvetica 13" -justify "left" -underline on

$tf.txt tag configure normal -font "helvetica 10" -justify "left"\
-underline off

pack $tf

<snip>

button $b.close -text "Cancel -command { destroy .twicWin }
button $b.download -text "Download" -command {::tools::twic::download}

}

Hitting the 'Cancel' button closes things fine.

As you can see above, there is also a 'Dwonlaod' button, which when pressed calls ::tools::twic::download. That works fine.

proc ::tools::twic::download {} {
# There are no buttons in this procedure.
}


doesn't matter if there are any buttons, what does matter is that there is
an update in there somewhere.


But if I
1) Hit the 'dwonload' button then
2) Hit the cancel button,

I get this:

invalid command name ".twicWin.tf.txt"
invalid command name ".twicWin.tf.txt"
while executing
".twicWin.tf.txt insert end "$ZIPFILE ( $ZIPFILESIZE b )\n""
(procedure "::tools::twic::download" line 156)
invoked from within
"::tools::twic::download"
invoked from within
".twicWin.b.download invoke"
("uplevel" body line 1)
invoked from within
"uplevel #0 [list $w invoke]"
(procedure "tk::ButtonUp" line 22)
invoked from within
"tk::ButtonUp .twicWin.b.download"
(command bound to event)


Any ideas?

yes, the download function is running along downloading something, (but isn't finished)
there is an update along the way (to provide GUI feedback of progress maybe?) adn you hit
(or have hit) the cancel button, so that event is triggered and deletes the entire window.
then processing is continuing in the download function and tries to work with stuff that
no longer exists - bam. either remove the update, or diabled the cancel while download in
progress, or have the cancel button actually stop the downloading before destroying the window.

Bruce
.