This is going to be dependent on how you handled navigation as well. Each window instance needs its own currentWindow
property. I use these scripts for multi-window handling. If navigation is set up correctly, this works flawlessly.
def getParentDesktop(window):
'''
Get the parent desktop JFrame for supplied window.
Args:
window (obj) : window on the desktop
Returns:
desktop (JFrame) : window's parent desktop JFrame
'''
while not isinstance(window, JFrame):
window = window.getParent()
desktop = window
return desktop
def desktopIsWindowedMode(window):
'''
Determine if a desktop is in windowed mode or not.
Args:
window (ovj) : Window to determine if the parent desktop is in fullscreen or windowed mode
Returns:
isWindowMode (BOOL) : True if desktop is in window mode
'''
#undecorated = fullscreen
return not Nav.getParentDesktop(window).isUndecorated()
def openNewDesktop():
'''
Open a new desktop window
Args:
n/a
Returns:
desktop (JFrame) : newly opened desktop
'''
#base desktop handle
dHandle = 'Desktop '
#get handles
handles = system.gui.getDesktopHandles()
#no desktops open yet
if len(handles) == 0:
nextIndex = 0
#other desktops open
else:
#get list of the desktop indicies from the handle
openDesktopIndicies = [int(handle.replace(dHandle,'')) for handle in handles]
#get max index and increment for next index
nextIndex = max(openDesktopIndicies)+1
#get the current window
window = system.nav.getCurrentWindow()
#open new desktop with current window
desktop = system.gui.openDesktop(handle=dHandle+str(nextIndex),windows = [window, 'Nav'])
desktop.setAlwaysOnTop(False)
return desktop
def desktopSwapDisplayMode(desktop):
'''
Swap the selected "desktop" to windowed/fullscreen mode from fullscreen/windowed mode.
Args:
desktop (JFrame) : JFrame of desktop to be swapped to windowed mode.
Returns:
n/a
'''
window = desktop
if window.isUndecorated():
# Switch to windowed mode.
window.dispose()
window.setUndecorated(False)
window.setExtendedState(JFrame.NORMAL)
window.setVisible(True)
else:
# Switch to full screen mode.
window.dispose()
window.setUndecorated(True)
window.setExtendedState(JFrame.MAXIMIZED_BOTH)
window.setVisible(True)
Swap window mode button:
desktop = ScriptLib.getParentDesktop(system.gui.getParentWindow(event))
ScriptLib.desktopSwapDisplayMode(desktop)
Add desktop button:
ScriptLib.openNewDesktop()
If you set up navigation incorrectly (which I had, initially) the user can swap screens on subsequent desktops, but swapping screens on the main desktop swaps all desktops to that same screen.