How to show Monitor Number using the Label Display?

10-4.

I was going from memory... I'm stuck in a hotel dealing with Crowdstrike aftermath at customer's sites.

I your library script really named MonitorNumber? I typically give my library scripts generic names, and then file many functions into them:

Example:
image

Since my project has a generic library script called windowScripts and since this function involves determining which screen a window is in, I'm going to file this function somewhere in there.

This line needs to be deleted from the script library. It is the cause of your fault. Personally, I wouldn't use a run script expression for this. I would probably call this library script from the parent window's internalFrameActivated event handler if I felt like it needed to update if the window were moved to another screen.

# Provide the appropriate relative path for the label component
label = event.source.getComponentForPath('Root Container.Label')

# Set the label's text property using the library script:
label.text = windowScripts.getScreenIndex(label)

If this were a one and done, then I would just use the label's propertyChange event handler like this:

# Only occurs once when the component is first initialized
# Doesn't run in the designer unless preview mode started prior to opening the window
if event.propertyName == 'componentRunning':
	event.source.text = windowScripts.getScreenIndex(event.source)

Edit: Forgot to note that the componentRunning event won't fire in the designer unless preview mode is on prior to opening the window.

1 Like

It works now. I tried all of your suggestions and it all works but the numbering is off.
image

here is my startup script in case I need to adjust it here.

screensToOpen = {1:'AMINE/AMINE GAS TRAIN',
		2:'AMINE/AMINE INLET',
		3:'AMINE/AMINE SKID',
		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})
system.nav.openWindow('Docked/Header')
system.nav.openWindow('Docked/Footer')

# 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('Docked/Header')
    system.nav.desktop(handleName).openWindow('Docked/Footer')

My Computer display setting is aligned to what the Label is showing. So I think the startup script needs to be aligned to my computer display setting.

1-Add a custom property called 'Display' on the root container of the window you're going to use to display your monitor number. From your screenshot it looks like it's your header.


image
2-Bind your label to your new custom property.

3-Modify your script so that you send you current monitor number to the correct window.

screensToOpen = {1:'AMINE/AMINE GAS TRAIN',
		2:'AMINE/AMINE INLET',
		3:'AMINE/AMINE SKID',
		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})
system.nav.openWindow('Docked/Header')
system.nav.openWindow('Docked/Footer')

# 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('Docked/Header',{'Display':handleName})
    system.nav.desktop(handleName).openWindow('Docked/Footer')
1 Like

Thank you this is working good now. This is the script.

screensToOpen = {1:'AMINE/AMINE GAS TRAIN',
		2:'AMINE/AMINE INLET',
		3:'AMINE/AMINE SKID',
		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')
system.nav.openWindow('Docked/Header', {'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])
    system.nav.desktop(handleName).openWindow('Docked/Header', {'Display':screenText})
1 Like