Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2002-12-05
16:47 • Ticket [645964ffff] "update idle" fails to redraw tk windows statu... artifact: 61c16f6081 user: dkf
2002-12-03
20:54 • Ticket [645964ffff]: 6 changes artifact: f4e64b8a64 user: vincentdarley
20:22 • Ticket [645964ffff]: 7 changes artifact: 3864c44325 user: dkf
20:15 • Ticket [645964ffff]: 7 changes artifact: 8c3044ff66 user: petasis
18:05 • Ticket [645964ffff]: 7 changes artifact: 77ba52c345 user: vincentdarley
05:45 • Ticket [645964ffff]: 7 changes artifact: 8a93b37472 user: hobbs
05:24 • Ticket [645964ffff]: 2 changes artifact: ea54c6287e user: petasis
05:24 • Ticket [645964ffff]: 5 changes artifact: bc6f2f9b82 user: petasis
2002-12-02
20:59 • Ticket [645964ffff]: 7 changes artifact: ab662e3f40 user: dkf
15:10 • Ticket [645964ffff]: 7 changes artifact: 01ab71381e user: petasis
2002-12-01
03:58 • Closed ticket [645964ffff]. artifact: 62c83d4da3 user: hobbs
2002-11-30
06:25 • New ticket [645964ffff]. artifact: df327776b6 user: petasis

"update idle" fails to redraw tk windows

Closed / Invalid645964ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 24 years ago
Descriptionplain2002-11-30 06:25:51
There seems to be an annoying problem with the
"update idletasks" option of the update command.
While this command is supposed to redraw windows,
in the recent versions of tcl it does not. Consider for 
example the following small script:

pack [label .x -text label]

for {set i 0} {$i <= 100000} {incr i} {
  ## This will at least redraw the windows...
  .x configure -text "Count: $i"
  update idletasks
}

The behaviour of the above script is very strange.
In my windows XP machine, the above script only
updates the label widget (where its text changes) and
the rest of the . window is not painted at all,
showing the desktop part that was beneath the
window at its creation time. If you move a window
and pass it over the . window, it turns white,
the label does not visually update any more and even 
when the computation is finished, the window remains
white. You have to interact with the window (i.e.
by moving it) to be drawn.
hobbsplain2002-12-01 03:58:47
Logged In: YES 
user_id=72656

update idle is doing exactly what you tell it to - only servicing 
the idle tasks.  If you want the other behavior, use 'update' 
without any arguments.
petasisplain2002-12-02 15:10:00
Logged In: YES 
user_id=92283

Is it? According to the manual:
"This causes operations that are normally deferred, such as 
display updates and window layout calculations, to be 
performed immediately."

Are display updates done? Clearly no. Only partial
updates (the label that changes) and this up to the point that
you move a window over it. Then display update stops
completelly (even the label that changes).

Update in 8.3 displayed differently. I always had in mind
that update idle handled all the "idle" events, including
requests from the OS to redraw or move windows. Other
input from the user (i.e. mouse clicks) were not processed.

Now, with 8.4 update idle, no display events are processed
and this causes problems under windows 2000 & XP. The app
is marked as a non-responding one, and the OS may
offer a window to kill it.

Removing the idle parameter is not an exact alternative,
as then input from the user is processed. You need a grab
also to simulate how update idle worked in the past.

I think that the update idle behaviour should be restored
to what it used to be (I am not the only one who complains :-))
or to make clear that its behaviour has been changed in 8.4.
dkfplain2002-12-02 20:59:00
Logged In: YES 
user_id=79902

Redraws depend on not just Tk's internal state, but also the
state of the windowing system and that can only get conveyed
to us by way of events, and you need a full [update] for
that to happen right.

If you don't change the size (or position) of a window, you
can count on [update idletasks] to do the redraw right (but
geometry manager handling is something else again,
especially with deeply nested windows) but in general you
only see things up to date when you're servicing events
fully.  Note that you probably want to do that anyway, since
otherwise you can miss out on redraw notifications due to
the user popping another window on top of yours, and even
some screensavers are interpreted as other windows...
petasisplain2002-12-03 05:24:37
Logged In: YES 
user_id=92283

But what is sad is that this behaviour has been recently
adopted. There is a lot of code that assumes that update
idle does a full visual update (as this is what the manual says)
and arranges the widget layout. Now, update idle does not
even draw windows in most of the situations. So what is now 
the purpose of calling update idle? For only executing
scripts registered with after and calling variable traces?

I think that now tk misses a procedure to draw its windows,
fixing the widget layout, etc. but not process user input.
(as update idle behaved in <= 8.4a2 :-))
Placing grabs & calling update may do the trick but I consider
using grabs a problem by itself, as you can easily end up
with a grab that was not released due to an error.
petasis Ticket [645964ffff]: 2 changes [History diff]2002-12-03 05:24:38
hobbsplain2002-12-03 05:45:27
Logged In: YES 
user_id=72656

8.3.5 behaves the same as 8.4.1 on Win2K.  I suspect this is 
either something unique to XP, or that perhaps your 
recollection of the previous behavior isn't quite right ;).
vincentdarleyplain2002-12-03 18:05:28
Logged In: YES 
user_id=32170

I appreciate there may be some platform-limitations
regarding this sort of behaviour, but as far as possible
'update idletasks' should ensure the gui is as fully updated
as possible.  Perhaps we need some caveat associated with
toplevel window size changes, but I would assume that if the
size of a toplevel doesn't change, Tk should be able to
arrange for all internal widgets (including deeply nested
ones) to be update.  Currently it doesn't.  The man page says:

"The update idletasks command is useful in scripts where
changes have been made to the application's state and you
want those changes to appear on the display immediately,
rather than waiting for the script to complete.  Most
display updates are performed as idle callbacks, so update
idletasks will cause them to run. However, there are some
kinds of updates that only happen in response to events,
such as those triggered by window size changes; these
updates will not occur in update idletasks."

Under the common assumption that "window" = "toplevel
window", Tk's behaviour does not agree with the above.  (see
e.g. bug 220776).
petasisplain2002-12-03 20:15:15
Logged In: YES 
user_id=92283

Yes but how 8.4a1 behaves? (8.3.5 may has back-ported
various stuff, so I wouldn't consider it as an example)
Perhaps its my fault (:-)) but it remains a fact
that my app is now broken visually in many places
under 8.4, where it ran fine in the past (i.e. one
year ago). I use update idle in really many places
in my code and simply now I end with not drawn
windows, even when they haven't been moved
or resized. Under windows & linux, so not an
XP thing.
I can fix this mess in my app, but this does not
mean that everything is well with update idle.
I still haven't understand what exactly update idle
is supposed to do :-)

And I agree with Vincent. We must have an update option
that draws tk windows, but leaves events related to user
input for processing with a full update.
dkfplain2002-12-03 20:22:18
Logged In: YES 
user_id=79902

Your expectations are wrong.  Whenever you do [update
idletasks], Tcl drains its queue of pending idle events,
which includes internally-generated redraws of Tk windows. 
However, it processes no events from external sources, and
cannot do because there is no easy way to tell what matters
in that respect and what does not; window size and position
changes are particularly tricky, and can be triggered by
updates of content of other windows too.  And this applies
to both internal and toplevel windows; <Configure> event
handlers make things tricky, and can be set on any window,
and deeply nested collections of windows may take several
rounds of [update idletasks] for them to be laid out
correctly (in this case, it is because [update idletasks]
does not process any idle event handlers registered by idle
event handlers that are run during processing, which bounds
the amount of work that may be done; if it didn't, Tk would
have a trivial denial-of-service attack vulnerability.)

The only way to guarantee a correct redraw of all windows is
to regularly service the event queue fully (e.g. with
[update], [vwait] or [tkwait].)  If you don't do this, you
cannot guarantee that all potentially pending redraws
occur.  End Of Story.
vincentdarleyplain2002-12-03 20:54:16
Logged In: YES 
user_id=32170

In that case, the documentation for 'update idle' needs to
be changed to reflect what you describe, in particular your
image of "draining the idle event queue" is quite absent
from the documentation!  Also  'window size changes' needs
to be replaced by 'any widget size changes', and perhaps any
other common problems should be added to the list.

From what you describe, if 'update idletasks' returned some
information about whether there are any new idle events
pending, this could be implemented in Tcl (and the
possibility of a d.o.s. problem would then have to be dealt
with in Tcl), for example:

proc updateAllIdle {{iterations 10}} {
    while {[set res [update idletasks]]} {
        incr iterations -1
        if {$iterations == 0} { return $res }
    }
    return $res
}

I am disturbed by George's report of all this changing in
newer versions of Tk, however.
dkfplain2002-12-05 16:47:23
Logged In: YES 
user_id=79902

Currently, Tk does as much as it can without the full event
loop firing when you do [update idletasks].  That it isn't
as much as you would like is rather sad, but the way things
are anyway; altering things so that all updates within a
window occur correctly when [update idletasks] is done would
break things a lot more, especially the separation between
Tcl and Tk.

(And what about code that sets a <Configure> event handler
on an internal window and redraws itself in response to
that?  I've seen such stuff in operation - I've written and
used such stuff! - and there's no way that that would behave
"correctly" without full event loop servicing.  And anyway,
the manpage you quoted does mention that not all updates
will happen correctly without full [update] and it is also
specifically not normative about what won't happen.  The
docs are right, and the behaviour is unchangable; if things
aren't happening quite right, that's just the
platform-specific-ness biting you, but there's not much
anyone can do about that, especially if the system widgets
require full [update] to function correctly.)
Log in (anonymous is fine) to add a comment.