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

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

From: Robert Suetterlin <robert@mpe.mpg.de>
Date: Mon Sep 12 2005 - 14:37:46 CEST

I have a tcl programm that updates a blt plot according to selections I
make in a listbox. That listbox has an associated scrollbar. The
update is done in several steps by an idle worker, which in turn uses
blt's bgexec and an external program to generate the data to be displayed.

The error occurs only if bgexec is running while I change my selection,
that is I change my selection while bgexec is running, beyond the
visible area of the listbox. The callback for the listboxes
yscrollcommand generates error messages about widgets(scrollbar) not
existing. wigets is a global (array) variable and $widgets(scrollbar)
contains the name of the scrollbar widget.

I have stripped down my program to a minimal working (i.e. breaking)
example, and attached it to this eMail. To repeat the error message,
just click in the listbox, and keep the button klicked, now move mouse
down, crossing the bottom of the visible listbox.

I do know that the idle worker as presented is not handling all updates
correctly. Even if I would not get the error message about
widgets(scrollbar).)

BTW. this happens with BLT2.4z, ActiveState ActiveTcl 8.4.11.1, on
Windows XP.

Regards, Robert S.

foreach word $argv {
  puts $word
  after 500
}
[plaintext external.tcl]
package require BLT

global widgets

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

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

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

  unset dataset(worker)

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