Is it possible to detect if a panel for instance is visible on the screen or not? (eg. not behind another non-wx window, not visible on the current view of the app, or if the app is minimised)
I’m doing some drawing on a panel and it would be great if I could skip it if the user isn’t watching and safe some cpu
There is IsShownOnScreen(), but I don't think it accounts for the window being covered by another application.
OTOH, if you do your drawing only in the EVT_PAINT handler and don't force redraws with things like Update() then you will probably get close to what you want as the system should optimize away paint events when the window is not visible.
···
On 5/18/12 8:21 AM, Paul wrote:
Is it possible to detect if a panel for instance is visible on the
screen or not? (eg. not behind another non-wx window, not visible on the
current view of the app, or if the app is minimised)
I'm doing some drawing on a panel and it would be great if I could skip
it if the user isn't watching and safe some cpu
Is it possible to detect if a panel for instance is visible on the
screen or not? (eg. not behind another non-wx window, not visible on the
current view of the app, or if the app is minimised)
I’m doing some drawing on a panel and it would be great if I could skip
it if the user isn’t watching and safe some cpu
There is IsShownOnScreen(), but I don’t think it accounts for the window being covered by another application.
OTOH, if you do your drawing only in the EVT_PAINT handler and don’t force redraws with things like Update() then you will probably get close to what you want as the system should optimize away paint events when the window is not visible.
As far as I can tell I’m not seeing that behaviour on mac 10.7.3. I put a print in the draw method and I still get it when the window is behind a window, on another desktop and even minimised. I still get all the print statements coming through if I only call Refresh if IsShownOnScreen as well so I dont know if that doesn’t work as expected on mac as well.
Am I right in thinking that the refresh shouldn’t be firing the EVT_PAINT or am I not testing this properly with a print statement if perhaps none of the drawing statements are getting performed because the os/wx knows that the window isn’t visible?
Also is there a way I can tell if this changes, like anything I can bind to when the window becomes visible/non visible? I expect not but would be really nice as I have a timer running sending 25 events a second to update an offset and call Refresh. If I could tell when the window wasn’t displayed I could Stop the timer and Start it again when it becomes visible again.
Have you tried wx.EVT_ACTIVATE and/or wx.EVT_ACTIVATE_APP while it
wouldn’t tell you if the window is (fully) visible or not it would
at least tell you if the user is actively using the application
allowing you to drop the update rate when the user is not actively
interested in/using your application. I would suggest using a lower
polling rate rather than stopping altogether when the user is on
another application.
Is it possible to detect if a panel for instance is
visible on the
screen or not? (eg. not behind another non-wx window, not
visible on the
current view of the app, or if the app is minimised)
I'm doing some drawing on a panel and it would be great if
I could skip
it if the user isn't watching and safe some cpu
There is IsShownOnScreen(), but I don't think it accounts for
the window being covered by another application.
OTOH, if you do your drawing only in the EVT_PAINT handler and
don’t force redraws with things like Update() then you will
probably get close to what you want as the system should
optimize away paint events when the window is not visible.
As far as I can tell I'm not seeing that behaviour on mac
10.7.3. I put a print in the draw method and I still get it
when the window is behind a window, on another desktop and
even minimised. I still get all the print statements coming
through if I only call Refresh if IsShownOnScreen as well so I
dont know if that doesn’t work as expected on mac as well.
Am I right in thinking that the refresh shouldn't be firing
the EVT_PAINT or am I not testing this properly with a print
statement if perhaps none of the drawing statements are
getting performed because the os/wx knows that the window
isn’t visible?
Also is there a way I can tell if this changes, like
anything I can bind to when the window becomes visible/non
visible? I expect not but would be really nice as I have a
timer running sending 25 events a second to update an offset
and call Refresh. If I could tell when the window wasn’t
displayed I could Stop the timer and Start it again when it
becomes visible again.
--
Robin Dunn
Software Craftsman
[http://wxPython.org](http://wxPython.org)
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit [http://groups.google.com/group/wxPython-users?hl=en](http://groups.google.com/group/wxPython-users?hl=en)
or visit [http://groups.google.com/group/wxPython-users?hl=en](http://groups.google.com/group/wxPython-users?hl=en)
Have you tried wx.EVT_ACTIVATE and/or wx.EVT_ACTIVATE_APP while it
wouldn’t tell you if the window is (fully) visible or not it would
at least tell you if the user is actively using the application
allowing you to drop the update rate when the user is not actively
interested in/using your application. I would suggest using a lower
polling rate rather than stopping altogether when the user is on
another application.
Gadget/Steve
Thats a good idea, just had a play but I can’t get either of those events to fire. I’ve tried binding both to the panel that does the drawing and to the main frame but I’ve not seen 1 event fire after minimising, moving focus to other windows etc. am I doing something wrong?