How do I Make an Ignition appication get the focus?

I am desiging an application in Ignition which will be running on a PC (Win XP and/or Win7) with other applications simultaneously.
The problem I have is that I want the application to “steal the focus” (I.E. pop-up) when certain events occur (tag change or whatever), but I can’t work out how to do this.

Any help, pointers, or suggestions on how I can achieve this would be greatly appreciated

Thanks in advance.


A script like this will make the application flash on the taskbar, is that what you mean?

[code]from java.awt import Window
from javax.swing import SwingUtilities

window = SwingUtilities.getAncestorOfClass(Window, event.source)

You need an event object from a component for that script to work…upon what event did you want this to happen?

[edit] never mind, you said above - on a tag change. That script won’t work on a client-side tag change script. Hold tight…

Ok, to do this from a tag-change script is a little stranger, because you don’t have a very straight-forward hook into the windowing system. The following works, but relies on at least one window being open. This is a fairly good assumption, because a Vision client with no windows open is pretty useless.

[code]from java.awt import Window
from javax.swing import SwingUtilities

allWindows = system.gui.getOpenedWindows()

if len(allWindows)>0:
topWindow = SwingUtilities.getAncestorOfClass(Window, allWindows[0])

Thanks Carl, I’ll give it a try today & let you know if it works…

BTW I believe that since WinXP SP3 setting window.toFront() will only make it “flash” the toolbar icon on subsequent calls, but I haven’t tried that out yet. I may need to “play a bit” perhaps with the modal settings of the window (if accessible) to make the Pop-up happen consistently…

Argh!!! It’s moment like this I hate windows…

I was about to post to say It works wonderfully but it doesn’t.

I did have it swapping back to the application after several rehashes of the script but after exiting & restarting the client I’m back to “flashing the icon” :frowning:

I don’t want to have to write a dll just to call the user32 API function SetWindowPos()
Any Ideas how I can get this swapping working reliably?

Looks like you’re not alone in this request. You can read about the various ins and outs of it on this StackOverflow thread, and on this thread.

You should try setting:

window.setAlwaysOnTop(1) window.setAlwaysOnTop(0)

Thanks Carl. It worked a treat. :smiley:

This is what I ended up with

[code]#PJR 20100313
#This Script forces the Ignition App to appear if not showing.
#It works for both windowed & full screen launch modes
from java.awt import Window
from javax.swing import SwingUtilities
from java.awt import Frame

allWindows = system.gui.getOpenedWindows()
if len(allWindows)==0:
#No Windows open? open one first
allWindows = system.gui.getOpenedWindows()

topWindow = SwingUtilities.getAncestorOfClass(Window, allWindows[0])
state = topWindow.getExtendedState()
state &= ~Frame.ICONIFIED

Not sure if this is related to what I’m doing in the above script but I have had to add the code below to the “Logout” menu option

try: except: system.util.exit(1)
It is because there is a null pointer exception when you log out the 2nd time (first one always works) I can get to occur by:
1.) showing a warning box on the screen (if a particular user role tries to Exit the application - Not from Shutdown-Intercept)
2.) call the script above to “Logout”
3.) log back in.
4.) repeat from step 1 and the client app will exit on logout.
This happens in both full screen and windowed modes. If you don’t catch the exception you end up with an empty “frame”

Glad you got the bring to front script working. I’ll look into that NPE you’re describing.

We’ve identified the problem with logging out - it has been fixed for the next release, 7.0.5