Re: widget updating issue
- From: Neil Madden <nem@xxxxxxxxxxxxx>
- Date: Wed, 11 Oct 2006 19:10:09 GMT
cmurphy wrote:
....
I have the "Practical Programming..." book by Welch and Jones, and that
has answered 99% of my questions except for this one. Do I need to use
the VWAIT command, which checks for variables changing state? Also, is
this an inherent issue with TCL/TK that frames/widgets can never be
updated until a loop or procedure is exited?
You can force an update using the [update] command (or [update idletasks]). However, this is almost always a bad idea (see "Update considered harmful": http://wiki.tcl.tk/1255).
Another related behavior of TCL/TK I notice is that I can create and
pack my widgets, but the GUI will not appear on the screen if I have
other (non-TK) code that still needs to execute. That occurs in this
same program because I kick off the 6 rsh queries during the initial
program startup, so even though the widget creation and packing occurs
in order before the rsh loop starts, the frame will not appear until
the queries are done. This seems odd to me. It tells me that TCL only
displays frames when all other commands are done executing, and that
the only way around this is to bind those "other" commands to buttons
in the GUI.
This is the same problem. Tk delays updates until the event loop is idle. This is generally a good thing, as it means Tk is not endlessly re-updating things.
The best way to solve this is to restructure your application to work with the event loop, rather than re-entering the event loop periodically with [update]. For instance, in your case it may be a simple case of changing the [exec rsh ...] to an [open "|rsh ..."]. You can then use [fileevent] ([chan event] in 8.5) to read output from each command while still keeping the event loop running (and your GUI alive). The general pattern looks like:
set chan [open "|rsh $server ..."]
fconfigure $chan -blocking 0
fileevent $chan readable [list ReadInput $server $chan]
and then the ReadInput procedure callback looks something like:
proc ReadInput {server chan} {
if {[catch { gets $chan line } result]} {
puts "ERROR: $result"
catch { close $chan }
} elseif {$result >= 0} {
# OK case
puts "Received: $line from $server"
} elseif {[eof $chan]} {
# All done
puts "Done: $server"
} elseif {[fblocked $chan]} {
# Not enough data available. Leave for now.
return
} else {
# ???
puts "Unknown condition: $server"
}
}
-- Neil
.
- Follow-Ups:
- Re: widget updating issue
- From: Ralf Fassel
- Re: widget updating issue
- From: Neil Madden
- Re: widget updating issue
- From: cmurphy
- Re: widget updating issue
- References:
- widget updating issue
- From: cmurphy
- widget updating issue
- Prev by Date: Times font sizes are different on screen and on eps files
- Next by Date: Re: widget updating issue
- Previous by thread: Re: widget updating issue
- Next by thread: Re: widget updating issue
- Index(es):