Hi,
Yes, the platform: it’s the OS which will decide if the window needs
refreshing or not: you can call Refresh() a million time, but if you
don’t use Update() right before/after the Refresh() call, the OS will
not redraw your window unless it has been “damaged” or covered or
changed in size or whatever.
What do you mean? Let’s say I have some panel that’s sitting still and not
being interrupted/damaged/covered. It won’t refresh. Then some code does
panel.Refresh()
. It will cause that panel to refresh, no?
Sorry, what I meant is: Refresh will raise a request for a window
refresh to wx and to the platform, but the refreshing will not happen
until the next event loop iteration:
“”"
virtual void wxWindow::Refresh ( bool eraseBackground = true, const
wxRect * rect = NULL ) [virtual]
Causes this window, and all of its children recursively (except under
wxGTK1 where this is not implemented), to be repainted.
Note that repainting doesn’t happen immediately but only during the
next event loop iteration, if you need to update the window
immediately you should use Update() instead
“”"
Moreover, if you are using double-buffering or if the platform uses
double-buffering implicitly (like Mac and possibly Windows 7, don’t
know about Linux), I doubt it will redraw your window anyway unless
something happened to the window (content changed, resized, damaged,
whatever).
I see.
Uhm, how about:
def OnPaint(self, event):
Create wx.PaintDC or friends
if self.needs_recalculation:
self.Recalculate()
Re-draw things
?
Andrea.
This is what I have now. The problem is not there, but in the code that
raises the needs_calculation
flag. I want to have a function that checks
if we need calculation, and if so raise the flag and call refresh. But I
want to be able to “call” this function the way Refresh “calls” OnPaint.
Sorry, I am still confused: how is different to do what you ask and to
do what I posted above? You simply call Refresh(), and if there is
need for a re-calculation, the OnPaint method will take care of this
too. I used this kind of strategy myself in some of the AGW widgets,
even outside the OnPaint handler (for example, in a wx.EVT_IDLE event
handler).
Andrea.
I’ll give you more specific details. There’s a variable pseudoclock
somewhere in my program, and there’s a widget ScratchWheel
. When something changes pseudoclock
, the ScratchWheel
might need to redraw, and might not. So after every change to pseudoclock
, I want to check if ScratchWheel
needs to redraw. So I want to recalculate, but redraw only if the recalculation says we need to redraw.
So what do I do? If I just raise the recalculation flag and call Refresh
, it’s possible that no redraw is needed and the ScratchWheel
will just waste time refreshing. If I call recalculate directly after changing pseudoclock
, and then have the recalculation function call Refresh
if a redraw is needed, then this is a problem too, cause I could have many pseudoclock
changes happening rapidly, and I don’t want to run the recalculate function for every one of them. When the pseudoclock
changes, I want to call a function that is to the Recalculate
function what Refresh
is to the OnPaint
function. i.e., a function that even if it’s called 100 times, the Recalculate
function will execute only once.
Ram.
···
On Sat, Apr 10, 2010 at 6:55 PM, Andrea Gavana andrea.gavana@gmail.com wrote:
On 10 April 2010 12:01, cool-RR wrote:
On Sat, Apr 10, 2010 at 12:55 PM, Andrea Gavana andrea.gavana@gmail.com > > > wrote: