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

You could try, in the timer handler, setting the timer duration based on the results of wx.GetApp().IsActive()

Gadget/Steve

···

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

From: Paul Wiseman

Sent: 21 May 2012 11:56:40 GMT

To: wxpython-users@googlegroups.com

Subject: Re: [wxPython-users] Possible to detect if control is on the screen or not?

On 21 May 2012 12:19, Gadget/Steve GadgetSteve@live.co.uk wrote:

On 21/05/2012 11:54 AM, Paul Wiseman wrote:

On 18 May 2012 18:05, Robin Dunn robin@alldunn.com wrote:

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

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

To unsubscribe, send email to
wxPython-users+unsubscribe@googlegroups.com

or visit
http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, send email to
wxPython-users+unsubscribe@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

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?

To unsubscribe, send email to
wxPython-users+unsubscribe@googlegroups.com

or visit
http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

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?

···

On 21 May 2012 13:07, Steve Barnes gadgetsteve@live.co.uk wrote:

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

From: Paul Wiseman

Sent: 21 May 2012 11:56:40 GMT

To: wxpython-users@googlegroups.com

Subject: Re: [wxPython-users] Possible to detect if control is on the screen or not?

On 21 May 2012 12:19, Gadget/Steve GadgetSteve@live.co.uk wrote:

On 21/05/2012 11:54 AM, Paul Wiseman wrote:

On 18 May 2012 18:05, Robin Dunn robin@alldunn.com wrote:

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

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

To unsubscribe, send email to
wxPython-users+unsubscribe@googlegroups.com

or visit
http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, send email to
wxPython-users+unsubscribe@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

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?

To unsubscribe, send email to
wxPython-users+unsubscribe@googlegroups.com

or visit
http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

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
···

On 21/05/2012 1:16 PM, Paul Wiseman wrote:

On 21 May 2012 13:07, Steve Barnes gadgetsteve@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?