Perspective Property binding and scripting parse error

Hi, I’m having trouble with my scripting to change the background color of some components.
I am a beginner at python so any advice would be greatly appreciated!

My goal is to turn the background color of each of the Red/Yel/Grn components 1 of 2 colors.
If the custom property “Light_On” is true,then turn the background color to “Light_Color_On” (#0000FF)
If the custom property “Light_On” is false,then turn the background color to “Light_Color_Off” (#0000FF80)

Currently, I have tried the following script after a Property binding, but I keep getting an error:

                   Error_Configuration("Parse Error in script transformation")
def transform(self, value, quality, timestamp):
	newcolor = self.custom.Light_Color_On    #  "#FFFF00"
	oldcolor = self.custom.Light_Color_Off   #  "#FFFF0080"
	if value:
		returncolor = newcolor
		returncolor = oldcolor
	return returncolor

Not sure what my error is or how to fix it.

Please and thank you!

You are missing the colon after you else.

If value:
    #do something
    #do something else

Thank you! As I said, I am very beginner level.

No problem, though the more Pythonic way to write this script would be:

if value:
    return self.custom.Light_Color_On
return self.custom.Light_Color_Off

The better way to do this in Ignition would be to use an expression binding with this expression:

if(self.custom.Light_On,self.custom.Light_Color_On, self.custom.Light_Color_Off)

Better yet would be to use CSS theme variables so that you don’t have hard coded “magic” colors.

1 Like