Possible to detect if control is on the screen or not?

22 views
Skip to first unread message

Paul

unread,
May 18, 2012, 11:21:55 AM5/18/12
to wxpytho...@googlegroups.com
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

Robin Dunn

unread,
May 18, 2012, 1:05:45 PM5/18/12
to wxpytho...@googlegroups.com
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.

--
Robin Dunn
Software Craftsman
http://wxPython.org

Paul Wiseman

unread,
May 21, 2012, 6:54:55 AM5/21/12
to wxpytho...@googlegroups.com
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

Gadget/Steve

unread,
May 21, 2012, 7:19:50 AM5/21/12
to wxpytho...@googlegroups.com

--
To unsubscribe, send email to wxPython-user...@googlegroups.com
or visit 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

Paul Wiseman

unread,
May 21, 2012, 7:56:32 AM5/21/12
to wxpytho...@googlegroups.com
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?

Steve Barnes

unread,
May 21, 2012, 8:07:55 AM5/21/12
to wxpytho...@googlegroups.com
You could try, in the timer handler, setting the timer duration based on the results of wx.GetApp().IsActive()

Gadget/Steve

-----Original Message-----

Paul Wiseman

unread,
May 21, 2012, 8:16:03 AM5/21/12
to wxpytho...@googlegroups.com
On 21 May 2012 13:07, Steve Barnes <gadge...@live.co.uk> wrote:
You could try, in the timer handler, setting the timer duration based on the results of wx.GetApp().IsActive()

Gadget/Steve


Hm, I wouldn't known when to change it though unless I checked that every time the timer event is fired which I'd rather avoid. Hoping there will be a an event.

When's EVT_ACTIVATE supposed to fire? is it based on the app focus?

Gadget/Steve

unread,
May 21, 2012, 2:04:59 PM5/21/12
to wxpytho...@googlegroups.com
On 21/05/2012 1:16 PM, Paul Wiseman wrote:
On 21 May 2012 13:07, Steve Barnes <gadge...@live.co.uk> wrote:
You could try, in the timer handler, setting the timer duration based on the results of wx.GetApp().IsActive()

Gadget/Steve


Hm, I wouldn't known when to change it though unless I checked that every time the timer event is fired which I'd rather avoid. Hoping there will be a an event.

When's EVT_ACTIVATE supposed to fire? is it based on the app focus?
 
Yes it is/should be see the demo for splitter window - that logs every time the focus moves from the window(s) of the application to something else.

Gadget/Steve

Reply all
Reply to author
Forward
0 new messages