Re: Again: error in event handler while using BLT bgexec: global variable seems to vanish.
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Again: error in event handler while using BLT bgexec: global variable seems to vanish.

From: Keith Nash <kjn9@citizenearth.com>
Date: Mon Sep 12 2005 - 23:46:35 CEST

Robert,

This seems to be a bug in BLT. BLT's docs for bgexec specify that Tk events
will continue to be processed while bgexec is executing. The context of
execution should be #0 (the toplevel context), but in fact it appears to be
the context of the bgexec command (if, as in your case, bgexec is told to
wait for its payload command to complete). Bizarrely, scrollbar event
bindings after the first error run neither in #0, nor in the context of
bgexec, but in the context of the Tk bgerror command.

The workaround is to run the bgexec command with 'uplevel #0'.

The attached script has the workaround, and also has 'info vars' (commented
out) to examine the context of execution.

Best wishes,

Keith.

package require BLT

global widgets
global tclExe
set tclExe tclsh84.exe
#set tclExe tclsh

set widgets(listbox) .l
set widgets(scrollbar) .s

#listbox $widgets(listbox) -selectmode extended -yscrollcommand {puts "<[info vars]>"; puts "Level = [info level]"; $widgets(scrollbar) set}
listbox $widgets(listbox) -selectmode extended -yscrollcommand {$widgets(scrollbar) set}
scrollbar $widgets(scrollbar) -command {$widgets(listbox) yview}

set people [list Peter Paul Mary Caesar Herodes Nero Nena Nina Nonna]
foreach me $people {
  foreach you $people {
    $widgets(listbox) insert 0 "$you and $me"
  }
}

pack $widgets(scrollbar) -side right -expand true -fill y
pack $widgets(listbox) -side right -expand true -fill both

bind $widgets(listbox) <<ListboxSelect>> [list update_selection %W]

proc update_selection {W} {
  global dataset

  foreach i [$W curselection] {
    lappend selection [$W get $i]
  }

  set dataset(selection) $selection

  if {![info exists dataset(worker)]} {
    set dataset(worker) [after idle update_worker]
  }

  return
}

proc update_worker {} {
  global dataset
  global tclExe

  uplevel #0 {blt::bgexec dataset(external) -onerror puts -onoutput puts $tclExe external.tcl [join $dataset(selection)]}
# blt::bgexec dataset(external) -onerror puts -onoutput puts $tclExe external.tcl [join $dataset(selection)]
  foreach name [array names dataset external*] {
    unset dataset($name)
  }

  unset dataset(worker)

  return
}
[plaintext test2.tcl]
Received on Thu Sep 29 14:36:35 2005