[wxPython-users] When application starts or is maximized how to no take focus

Josiah Carlson jcarlson at uci.edu
Mon Apr 2 17:18:08 PDT 2007


"Geoff Skerrett" <Geoff at teammsa.com> wrote:
> Can anyone suggest a methodology that would allow our application to
> start up (or be maximized by the user from the system tray) but not have
> our application become the top window within the entire system and take
> the system focus.
[snip
> Our popup application's mainframe is constructed with the style
> parameter wx.STAY_ON_TOP
>  
> We are using WinXP SP2, wxPython 2.8.2 and Python2.4.
>  
> Any suggestions ??

The wx.STAY_ON_TOP style will force your applications to be on top of
everything, regardless of the focus, I will presume this is what you are
after.

In terms of not letting your applicaion take the system focus, I'm not
sure that is possible.  However, since your platform is Windows XP, you
may be able to use the win32gui module from pywin32 (included by default
in Python 2.5 and later I believe) to get the window that is focused in
the other application, to then perform a .SetActiveWindow() call:
    http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/PyWin32/win32gui__SetActiveWindow_meth.html

That is to say, when your application is about to raise itself, you dig
through your target application, find the focus, restore yourself, then
set the active window to the other application's window.

That may or may not work, but it seems like it should.  For information
about crawling through another application's window hierarchy, see
winAutoGui.py from Simon Brunning and his interesting series of posts on
GUI manipulation/scripting on Windows:
    http://www.brunningonline.net/simon/blog/archives/000652.html
    http://www.brunningonline.net/simon/blog/archives/winGuiAuto.py.html

Note that this is heavily Windows-centric.  I have no idea how to do
this on other platforms.


 - Josiah





More information about the wxpython-users mailing list