Ignition 8.1 PowerTable header background color

Using @PGriffith's direction, I have developed a script that will accomplish the goal of globally changing all power table header configurations from the designer. The script opens every vision window, then loops through getting all of the components from each window's root container. Then it checks each component list for power tables and nested containers. If there is a nested container, it repeats the process until there are no more nested containers.*

*For each power table found, if the configureHeaderStyle extension function does not exist or is not enabled, the script applies a configureHeaderStyle extension function that changes the color of the header to white. No other preexisting extension functions are altered or affected. The applied extension function string is in line three, so if a different color or additional properties are needed, this is where it will need to be changed.

Here is the script:

def processHeader(subComponent):
	from com.inductiveautomation.vision.api.client.components.model import ExtensionFunction
	script = 'def configureHeaderStyle(self, colIndex, colName):\n	return {\'background\': \'white\'}'
	try:
		extensionFunctions = subComponent.getExtensionFunctions()
		if "configureHeaderStyle" in extensionFunctions:
			configureHeaderStyle = extensionFunctions['configureHeaderStyle'] 
			if not configureHeaderStyle.enabled:
				updatedExtensionFunction = ExtensionFunction(True, script)
				extensionFunctions['configureHeaderStyle'] = updatedExtensionFunction
				subComponent.setExtensionFunctions(extensionFunctions)
		else:
			updatedExtensionFunction = ExtensionFunction(True, script)
			extensionFunctions['configureHeaderStyle'] = updatedExtensionFunction
			subComponent.setExtensionFunctions(extensionFunctions)
	except:
		from java.util import HashMap
		updatedExtensionFunction = ExtensionFunction(True, script)
		Map = HashMap()
		Map.put('configureHeaderStyle', ExtensionFunction(True, script))
		subComponent.setExtensionFunctions(Map)
def containerProcessor(components):
	for subComponent in components:
		if 'VisionAdvancedTable' in str(type(subComponent)):
			processHeader(subComponent)
		elif 'Container'in str(type(subComponent)):
			containerComponents = subComponent.getComponents()
			loopThroughComponents(containerComponents)
def loopThroughComponents(components):
	for subComponent in components:
		if 'VisionAdvancedTable' in str(type(subComponent)):
			processHeader(subComponent)
		elif 'Container'in str(type(subComponent)):
			containerComponents = subComponent.getComponents()
			containerProcessor(containerComponents) 
for name in system.gui.getWindowNames():
	system.nav.openWindow(name)
	components = system.gui.getWindow(name).getRootContainer().getComponents()
	loopThroughComponents(components)
	system.nav.closeWindow(name)

Edit: Everything in the above script now works correctly. The initial version seemed to work, but when I attempted to save the changes, the designer threw an exception due to unhashable dictionaries. This was fixed by removing all dictionary casts and methods, and by setting up exception handling that creates a hashmap for power tables that return a null value during the getExtensionFunctions method because they have never had any extension functions enabled.

Subsequent Edit: It occurred to me that opening 1800 windows in the designer would probably be a bad idea. I added a line of code to close each window upon edit completion.

5 Likes