I am having a hard time finding out why when i apply an expression to background color element it will change in the preview on property editor but not in the view itself. Expression :
This is looking at the name of the of the component and finding the tag and then gradient between the two limits. Like I stated I see the color change in the preview but the buttons color in the view dont change.
Perspective does not use Java colors, which is what your binding is returning. As a result, you’ll see no change. Perspective uses CSS for displaying components, so any returned color needs to be in a CSS-supported format. This limits you to a select subset of formats, including RGB, Hex, and HSL.
Yes i figured that after posting … is there a way to convert to Hex ?? i need the gradient function as the numbers range between 3600 and 0 . i have tried the tohex() with no luck .
It's telling you that value is a String (unicode), and therefore does not have functions like getRed() available to invoke upon it. Earlier posts are receiving a Color object, which is why that transform works there. You ca either convert your String to a Color through some manner, or you can act upon it as a string:
values = value.split("(")[-1]
values = values.split(")")[0]
values = values.split(",")
red = values[0]
green = values[1]
blue = values[2]
alpha = values[3] if len(values) > 3 else None
pretty clear to me, the first output of the expression above is returning a string (unicode). Make sure to always return a Color, then the script transform would work.
or try this
from java.lang import String
from java.awt import Color
color = value
hexformat = '#%02X%02X%02X%02X'
if isinstance(color,(str,unicode)):
colors = color.replace('(','').replace(')','').replace('color','').split(',')
r,g,b = [int(c) for c in colors[0:3]]
a = int(colors[-1]) if len(colors) == 4 else 255
return String.format(hexformat,r,g,b,a)
elif isinstance(color,Color):
return String.format(hexformat,color.getRed(),color.getGreen(),color.getBlue(),color.getAlpha())
else: return color
found a much simpler expression solution, and it works fine for me:
replace('color(0,255,0,255)', 'color', 'rgba')
I get from OPC UA the different states of a device as an int and I defined in a custom UDT a derived variable that reads from a memory dataset the corresponding meaning as TextDescription and and color as colorDataType. so I searched for the same solution, but found this quick way. especially that in UDT expresions I saw no way of using scripts only expressions