Confused about wxWindow::Update() vs Refresh()

Vadim Zeitlin vadim at wxwidgets.org
Fri Feb 15 04:57:45 PST 2008


On Fri, 15 Feb 2008 11:31:27 +0100 Paul Melis <paul at science.uva.nl> wrote:

PM> I have a situation in which an event handler (File -> Open) starts the 
PM> processing of some data by an external library. The library provides 
PM> progress callbacks which I'm using to drive a progress bar.
PM> But how can I force redrawing of the progress bar immediately without 
PM> using Yield()? Is this possible at all?

 It's possible to redraw it without using wxYield() but it's not possible
to handle the clicks on the (optional) "Cancel" button without it. So if
you use this button you have no choice but to call wxYield() unfortunately.

PM>  From the description of wxWindow::Update() and wxWindow::Refresh() in 
PM> the 2.8 docs (see below) I get a confused picture of what to do.
PM> 
PM> For Refresh() it says
PM> "Causes this window, and all of its children recursively [...], to be 
PM> repainted. Note that repainting doesn't happen immediately but only 
PM> during the next event loop iteration, if you need to update the window 
PM> immediately you should use Update instead."
PM> 
PM> So this would seem to suggest that calling Update() would force an 
PM> immediate update (repaint), but for Update() it reads:
PM> "Calling this method immediately repaints the invalidated area of the 
PM> window and all of its children recursively while this would usually only 
PM> happen when the flow of control returns to the event loop. Notice that 
PM> this function doesn't refresh the window and does nothing if the window 
PM> hadn't been already repainted. Use Refresh first if you want to 
PM> immediately redraw the window unconditionally."
PM> 
PM> The second part of the sentence "Notice that this function doesn't 
PM> refresh the window and does nothing if the window hadn't been already 
PM> repainted." is extremely confusing. Update() does nothing if there has 
PM> NOT already been a repaint?? Should I actually read this as "This 
PM> function doesn't refresh the window (call Refresh() for that first). 
PM> This function does nothing if the window already has been repainted"?

 It should, and it has been corrected some time ago, see

http://www.lpthe.jussieu.fr/~zeitlin/wxWindows/docs/wxwin_wxwindow.html#wxwindowupdate

PM> It seems that calling Refresh() on the progress first, to force it to 
PM> repaint, followed by a call to Update() would do the trick but it 
PM> doesn't (i.e. no redrawing takes place).
PM> 
PM> This is with wxGTK (2.6) b.t.w.

 Please try 2.8 as I don't think anybody is going to look at 2.6. But if it
still doesn't work in 2.8 it's a bug which needs fixing.

 Regards,
VZ

-- 
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/





More information about the wx-users mailing list