Get components path

is there a way to get a components path on the screen.?

for example if I have a text box inside a container. when the value changes i would like to know that the text box can be found on the root container in a container called “Container_1” and the compoents name is txtBox_1.

Thank you,

What exactly are you trying to do? If you are creating a propertyChange script on the textbox you know the name of that component by:event.source.nameand the name of the parent by:event.source.parent.name

I am trying to come up with a way of keeping track of all the values currently on the screen. i was thinking of a normalized database table with column for the username, path to the component on the screen, and the value in the components text field.

Also along the same lines instead of my above idea is there a way to ask the user if they want to save when they close the client application (clicking the X in the corner)?

Yes, you can cancel the shutdown event and ask them if they want to save the changes. You just need to add a script under the Shutdown-Intercept. To cancel type:event.cancel = 1By the way you can loop through all of the components in the window:rc = event.source.parent for comp in rc.getComponents(): print rc.nameYou can check if the component is a container or a text box. If it is a container you can then loop through all of its components.

is there a way on the system.gui.confirm dialog box to know when the user clicks “no” versus clicking the X on the corner of the dialog box?

I don’t think so. I am pretty sure the function returns 0 in both cases.

How can I make a dialog box with three buttons? Yes, No, Cancel

We don’t have one of those as a system.gui function. You can make your own window in Ignition that you open up which can handle the yes/no/cancel. You can always cancel the shutdown script and handle the system.util.exit() from your own window.

I have made my own window with three buttons. I am now trying to center the window, but cannot use the function system.nav.centerWindow() because my window size is larger than my screen (1920x2875). I was trying to use the following code, but I cannot seem to to set the x and y of a window. how can i set the window to the center of the screen? along the same lines how can i move a container or a floating window down the screen while the user scrolls down the window?

[code]event.cancel = 1
import system

window = system.gui.getWindow(‘SalesProjections’)

changesMade = window.getRootContainer().changesMade

system.gui.warningBox("changes = "+str(changesMade))

if(changesMade == 1):
from java.awt import Toolkit

toolkit = Toolkit.getDefaultToolkit()

scrnsize = toolkit.getScreenSize()

scrnWidth = scrnsize.width
scrnHeight = scrnsize.height

widthMiddle = scrnWidth/2
heightMiddle = scrnHeight/2
system.nav.openWindow("SavePrompt")
saveWindow = system.gui.getWindow("SavePrompt")
saveWindow.x = widthMiddle-saveWindow.width/2
saveWindow.y = heightMiddle-saveWindow.height/2

else:
system.util.exit()[/code]

I found another post that explained how to set a window location

window.setLocation(x,y)

I think what i need to know for my other question is how do I get the x,y coordinates of the visible top left corner of the window? And i would also need to know how to capture the scroll bar event.

for example.
If I am at the top of the screen it would return 0,0.

if i scroll down 150 pixels it would return 0,150.

this way based on the screen size and the visible top left coordinates i can figure out where on the window the user is looking.

it looks like i can use this function to figure out the top left corner of the screen, but how do i capture the scroll bar event?

system.gui.convertPointToScreen(x, y, event)

I’m afraid I can’t think of a way to “capture” the scroll bar events. You can however figure out information about the current scroll position. The basic idea is to walk the Swing component hierarchy upwards until you find the JScrollPane.

Hopefully this is helpful:

[code]from javax.swing import SwingUtilities
from javax.swing import JScrollPane

scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane, event.source)

print scrollPane.getViewport().getViewRect()[/code]