Window path template property

Hi All
Using the following post, I have made a simple button which updates a historical chart with the latest data on the click of a button.

I've made this into a template since I plan to use it in multiple places through a project. I currently pass two custom property strings into the template, ChartName and WindowPath. The following script is fired by "actionPerformed" on the button within the template.

> # Load the chart name
> ChartName = event.source.parent.ChartName
> 
> # Get a reference to the window containing the chart
> window = system.gui.getWindow(event.source.parent.WindowPath)
> 
> # Build a reference to the chart
> chart = window.rootContainer.getComponent(ChartName) 
> 
> # Set the chart end date to the current date
> chart.endDate = system.date.now()

This works perfectly but is there a nicer way to get a reference to the window containing the template that was clicked? I've looked at the system.gui functions. Ideally, I'd like to not have the window path as a property since I will always be updating the chart on the same window as the button (template). Note, there may be pop up windows open at the time the user clicks the button in question.

Cheers

Should just be able to use system.gui.getParentWindow

Thanks for the reply. I tried that but I think it returns the root container for the template, not the window.

Are you sure? I just tried it now and am getting the window itself. Version 7.9.12

I get an error stating that root container does not exist in the window (I think).

Any ideas? Thanks for your help.

image

You aren’t passing anything to getParentWindow, no parentheses even, so the variable window holds a reference to the function, un-executed, not the return value from the function. A function object would not have the properties of a window.

1 Like

Got it. Thanks for the pointer. This code now works and I am able to pass only the chart name to the template.

# Load the chart name
ChartName = event.source.parent.ChartName

# Get a reference to the window containing the chart
window = system.gui.getParentWindow(event)

# Build a reference to the chart
chart = window.rootContainer.getComponent(ChartName)

# Set the chart end date to the current date
chart.endDate = system.date.now()