3

In my wxWidgets (wxPython) app, I am using a 50 ms timer to do some polling and update a window if there are any changes. If changes are detected it calls wxWindow.Refresh to update the window, and the actual updating of the widgets is done in the EVT_PAINT handler. It would be nice if I could disable the painting and/or the timer if the user is not looking at the window anyway. However EVT_PAINT is still being fired even if the window is iconized or hidden behind a different window.

Is there any way to detect if the window is not currently visible on screen, or to prevent EVT_PAINT events from firing unnecessarily?

There is the IsActive method and the EVT_ACTIVATE event to test whether the window has focus, but I want to keep updating the window if it is unfocussed but still visible. The wxWindow.IsShown family of functions doesn't help, they still return True for hidden/iconized windows.

JanKanis
  • 6,346
  • 5
  • 38
  • 42
  • I have the same problem: a widget is updated repeatedly with a wxTimer, but it should not be updated if the window is not visible, for example when placed in an inactive wxNotebook tab. I could use IsShownOnScreen in the event handler to stop any further events, but there is no way to start it again once it becomes visible to the user. – Jonatan Feb 10 '14 at 21:26

1 Answers1

0

IsShownOnScreen() could help with the iconized case. Edit: But actually does not.

Or you could trap wxEVT_ICONIZE to detect when the window is minimized.

But to be honest I'm rather surprised that refreshing a window hidden behind another one still results in a repaint. If the window in front is not transparent, this really shouldn't happen.

VZ.
  • 21,740
  • 3
  • 39
  • 42
  • Does not work. It's exactly what I tried for the refresh timer. – Tomáš Zato Nov 05 '13 at 16:25
  • IsShownOnScreen does only check if alement and all it's parents are hidden or not. It does not check the state of the window. – Tomáš Zato Nov 05 '13 at 22:56
  • Sorry, `IsShownOnScreen()` indeed doesn't work correctly (at least IMHO it should work like I wrote, but, again, currently it doesn't) in this case. `wxEVT_ICONIZE` definitely does though. – VZ. Nov 05 '13 at 23:46