I got this script from the manual and it works. The only thing I would like to do is show a different display on the 3rd and 4th monitor.
# Get the screen information for all of your monitors.
screensDataset = system.gui.getScreens()
# Open the first window of the project in the (current) primary monitor.
screenIndex = screensDataset[0][0]
monitorNum = screenIndex + 1
primaryScreenText = 'This is Monitor %d' %monitorNum
system.nav.swapTo('AMINE/AMINE GAS TRAIN', {'Display':primaryScreenText})
# Step through all of the screen information, starting with index 1 instead of 0.
for screenDetails in screensDataset[1:]:
# unpacks the tuple that is returned for each of the monitors present. Consists of screen index, width, and height of the screen.
screenIndex, screenWidth, screenHeight = screenDetails
monitorNum = screenIndex + 1
screenText = "This is Monitor %d" %monitorNum
# Open an empty frame on the next monitor.
# Assign a handle and apply the width/height for the monitor you are opening on
handleName = "Monitor %d" %monitorNum
system.gui.openDesktop(screen=screenIndex, handle=handleName, width=screenWidth, height=screenHeight)
# Open the Main Window on this new desktop and pass the parameters needed.
system.nav.desktop(handleName).swapTo('AMINE/AMINE INLET',{'Display':screenText})
Try using a dictionary to store your display paths so you can use your monitorNum or screenIndex to retrieve the correct one for each monitor:
screensToOpen = {1:'AMINE/AMINE GAS TRAIN'
2:'AMINE/AMINE GAS TRAIN',
3:'Paste your path to the screen you want to open on monitor 3 here',
4:'Paste your path to the screen you want to open on monitor 4 here'}
# Get the screen information for all of your monitors.
screensDataset = system.gui.getScreens()
# Open the first window of the project in the (current) primary monitor.
screenIndex = screensDataset[0][0]
monitorNum = screenIndex + 1
primaryScreenText = 'This is Monitor %d' %monitorNum
system.nav.swapTo('AMINE/AMINE GAS TRAIN', {'Display':primaryScreenText})
# Step through all of the screen information, starting with index 1 instead of 0.
for screenDetails in screensDataset[1:]:
# unpacks the tuple that is returned for each of the monitors present. Consists of screen index, width, and height of the screen.
screenIndex, screenWidth, screenHeight = screenDetails
monitorNum = screenIndex + 1
screenText = "This is Monitor %d" %monitorNum
# Open an empty frame on the next monitor.
# Assign a handle and apply the width/height for the monitor you are opening on
handleName = "Monitor %d" %monitorNum
system.gui.openDesktop(screen=screenIndex, handle=handleName, width=screenWidth, height=screenHeight)
# Open the Main Window on this new desktop and pass the parameters needed.
system.nav.desktop(handleName).swapTo(screensToOpen[monitorNum],{'Display':screenText})
So your code would look something like this (replace the AMINE/AMINE GAS TRAIN windows with what ever default window you want on all monitors or use a mix of this and what @leonardo.godoi posted if you want different defaults per desktop - I usually just set them all the same since we're restoring last used and the default only matters the first time the client is ran):
# Get the screen information for all of your monitors.
screensDataset = system.gui.getScreens()
# Retrieve our previously opened windows
windowList = system.tag.readBlocking(['OpenedWindows'])[0].value
# Open the first window of the project in the (current) primary monitor.
screenIndex = screensDataset[0][0]
monitorNum = screenIndex + 1
primaryScreenText = 'This is Monitor %d' %monitorNum
windowToOpen = windowList[0] if len(windowList[0]) > 0 else 'AMINE/AMINE GAS TRAIN'
system.nav.swapTo(windowToOpen, {'Display':primaryScreenText})
# Step through all of the screen information, starting with index 1 instead of 0.
for screenDetails in screensDataset[1:]:
# unpacks the tuple that is returned for each of the monitors present. Consists of screen index, width, and height of the screen.
screenIndex, screenWidth, screenHeight = screenDetails
monitorNum = screenIndex + 1
screenText = "This is Monitor %d" %monitorNum
# Open an empty frame on the next monitor.
# Assign a handle and apply the width/height for the monitor you are opening on
handleName = "Monitor %d" %monitorNum
system.gui.openDesktop(screen=screenIndex, handle=handleName, width=screenWidth, height=screenHeight)
# Open the Main Window on this new desktop and pass the parameters needed.
windowToOpen = windowList[monitorNum] if len(windowList[monitorNum]) > 0 else 'AMINE/AMINE GAS TRAIN'
system.nav.desktop(handleName).swapTo(windowToOpen,{'Display':screenText})
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)
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.
On your for loop that goes through each desktop, just add a system.nav.openWindow for that desktop. system.nav.desktop(handleName).openWindow('PathToYourDockedWindow_Here')
So,
screensToOpen = {1:'AMINE/AMINE GAS TRAIN'
2:'AMINE/AMINE GAS TRAIN',
3:'Paste your path to the screen you want to open on monitor 3 here',
4:'Paste your path to the screen you want to open on monitor 4 here'}
# Get the screen information for all of your monitors.
screensDataset = system.gui.getScreens()
# Open the first window of the project in the (current) primary monitor.
screenIndex = screensDataset[0][0]
monitorNum = screenIndex + 1
primaryScreenText = 'This is Monitor %d' %monitorNum
system.nav.swapTo('AMINE/AMINE GAS TRAIN', {'Display':primaryScreenText})
# Step through all of the screen information, starting with index 1 instead of 0.
for screenDetails in screensDataset[1:]:
# unpacks the tuple that is returned for each of the monitors present. Consists of screen index, width, and height of the screen.
screenIndex, screenWidth, screenHeight = screenDetails
monitorNum = screenIndex + 1
screenText = "This is Monitor %d" %monitorNum
# Open an empty frame on the next monitor.
# Assign a handle and apply the width/height for the monitor you are opening on
handleName = "Monitor %d" %monitorNum
system.gui.openDesktop(screen=screenIndex, handle=handleName, width=screenWidth, height=screenHeight)
# Open the Main Window on this new desktop and pass the parameters needed.
system.nav.desktop(handleName).swapTo(screensToOpen[monitorNum],{'Display':screenText})
system.nav.desktop(handleName).openWindow('PathToYourDockedWindow_Here')