Re: widget updating issue



At 11 Oct 2006 09:08:35 -0700 "cmurphy" <murphycc@xxxxxxxxx> wrote:


Hi folks,

I discovered something about TCL the other day that I did not know
before. I have a frame with a number of labels, entries and buttons.
When the "Update" button is pressed I execute a linux rsh command to
log onto 6 other linux hosts to check what jobs are running and how
many processors are free. It takes about 8 seconds for the loop of 6
rsh commands to finish, after which certain variables are changed and
updated in the TK frame containing the data.

The issue is that I would like each variable to REFLECT ITS CHANGED
VALUE IN THE FRAME as soon as the variable is changed in the loop or
procedure I am calling. In other words, in the loop I call which shoots
6 rsh commands to those other hosts, variables are updated after each
host is queried. But the frame does not reflect those values until the
entire 8 second loop is complete, even though the individual variables
change at times before 8 seconds.

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?

No, you don't need to use the VWAIT command. Instead, you need to just
enter the event loop each time through the rsh loop:

foreach host {host1 host2 host3 ...} {
# Execute the remote command
catch {exec rsh $host command} commandresult
# Update screen elements (eg. labels)
$label($host) configure -text "$commandresult"
# Enter the event loop to handle pending screen update events.
update idle
}


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.

Same answer:

# Build some widgets
frame .foo
pack .foo -expand yes -fill both
button .foo.button1 -text 'Hello'
pack ..foo.button1 -fill x
# Force display
update idle
# Get initial host state
foreach host {host1 host2 host3 ...} {
# Execute the remote command
catch {exec rsh $host command} commandresult
# Update screen elements (eg. labels)
$label($host) configure -text "$commandresult"
# Enter the event loop to handle pending screen update events.
update idle
}




If anyone understands this, please help.

Thanks,
-Chris



--
Robert Heller -- 978-544-6933
Deepwoods Software -- Linux Installation and Administration
http://www.deepsoft.com/ -- Web Hosting, with CGI and Database
heller@xxxxxxxxxxxx -- Contract Programming: C/C++, Tcl/Tk

.