Switch Desktop Focus

I have an application that makes heavy use of ignitions multiple “desktop” feature for multi monitor clients. All of the windows in this application are opened as separate desktops.

I’ve run into a couple of issues, and I was wondering if anyone out there had solutions:

Situation: A button on desktop A opens desktop B with vision window B. A button in vision window B swaps the contents of desktop B to vision window C. Now, I want to press the button on desktop A again (to view vision window B and C at the same time on two separate desktops). This fails because I can’t have two desktops with the same handle.

Question: Is it possible to change the handle of a desktop while it is open?

Situation: I have multiple desktops open on one monitor; some are large and some are small. I open a small desktop (“popup”) and then click back to the large desktop (“main”). Now the small desktop is hidden behind the large desktop. sifting through the microsoft window manager to get my popup is a pain, so I want to just click the button that I originally used to bring up the popup. This fails because you can’t have duplicate desktops open, and the button has a specific handle that it uses. That’s ok, though, because I don’t want multiple instances of the same information.

Question: How do I bring an open desktop to the front of the microsoft window manager (change focus), by means of a script in ignition.


With regards to point 2, why are you not opening the popup in another window on the main desktop? This would be simpler than using separate desktops and there are workarounds to make the popup window modal.

You’re right that it would be simpler, but I want the user to have the option to drag the popup to another desktop if he wants.Also, there are instances where I have smallish windows opening other smallish windows, and to drop them on the same desktop (or on another desktop) would upset the contextualization scheme I’m working on.

In any case, the ability to bring a desktop to the front would be really cool :wink:

Some code that may or may not work (and should be compatible with the Desktop object returned by the openDesktop function) is available here:

However, it does look like it’s not always possible depending on the OS, version, and various other factors. But that’s probably your best bet.

1 Like

Cool find! I’ll have to experiment with that a bit. Thanks!

Hi @zacslade, It would be nice to hear about the results of your experiments!

This was a while ago, so I don’t completely remember what came of it (and, in fact, I don’t have access to the solution anymore). Also, Ignition may have made some improvements to the desktop/vision window system since then. I haven’t had an application which made such in-depth use of it in a while. But I remember having a bit of difficulty getting the info in PGriffith’s link to work (mostly because I wasn’t very comfortable with Java back then). Also, having the window close and then reopen in the same script brought about inconsistent results at first.

I think that what I finally did for the first problem was I wrote a thing to dynamically generate handles for the windows based on the context. I don’t remember if I actually went through with this, but I might have even used a try-catch loop to dynamically generate indexed handles for some of the windows, to avoid duplicate handles. This meant that the dynamically-handled windows were hard to keep track of, but in some cases that was ok.

For the second problem, I think the key was to close the hidden desktop and open a new one with a different handle (and I might have had to play with invokeasynch and a short delay timer to get the new desktop to work the way I wanted). The issue here is that you lose whatever contents you had in the hidden desktops. In my case, it didn’t matter.

For both situations, the necessity of the issue was mitigated slightly by some careful sizing and positioning for the ignition desktops. That application opened several desktops on startup and arranged them so the user could see everything, but still move it around if he/she wanted.

I hope this helps!

Thanks a lot for your reply!
It gives me an idea how deep I need to go to get an independent windows popup.
Unfortunately, this problem still exists in version 7.9.X. If you open a popup screen from some desktop, there is no way to move it slightly off this desktop, for example leaving visible only part of this popup. It is useful when operator needs temporally see some other areas of this desktop and keep the popup screen opened. You can implement “Infiniti” feature, but with thing enabled the scroll bars appear when move the popup screen really deep out of the desktop.

Actually, I found a solution for my application - using “setAlwayOnTop(True)”. It was not so deep as I expected.
Wondering why Inductive Automation does not include this function in the manual. They might have some better built-in solutions for situation like this in coming soon version 8.
here is a code which I place under Script Library [project]:

def PopupDesktop(desktopTitle, desktopWidth, desktopHeight, desktopX, desktopY, windowToOpen, windowToOpenParam, handleToOpen):

handleList = system.gui.getDesktopHandles()

if handleToOpen in handleList:
	PopupWindow = system.nav.desktop(handleToOpen).openWindow(windowToOpen, windowToOpenParam)
	PopupFrame = system.gui.openDesktop(screen=0, handle = handleToOpen, title = desktopTitle, width = desktopWidth, height = desktopHeight, x = desktopX, y = desktopY)
	PopupWindow = system.nav.desktop(handleToOpen).openWindow(windowToOpen, windowToOpenParam)

Good find! Yeah, that’s really helpful, thanks!