I want to bind a parameter from the return of a python script.
But my script does not get evaluated, as you can see, I put "1" on expression and use a script transform - I used to do this but just found that this is bad strategy.
How can I get the script evaluated, when each parameters used on the script changes.
Transforms are only evaluated if their parent is re-evaluated. A static expression value like 1 is only evaluated once at first load. You need to use an expression structure binding and bind to all of your props you want to monitor for this to evaluate when these props change
I think You can also include all your props in a group (object/array) and just monitor the group prop itself
@Eugene49 Just to be clear, you generally should not be assigning "magic" values like colour hex's directly to style properties like backgroundColo(u)r if you want to have any hope of maintaining a theme throughout your project. Ditch these in favour of Perspective Styles, as @lrose suggested
do you guys mean. If you want to set label's font color to green. you would rather create a style, set font color to green and apply the style?
Hypothetically, Say I have 4 layers of nested flex container.
Each layer uses different background color.
You would rather create 4 styles. Layer1 .. Layer4 styles. Apply these style to each flex container respectively.
What I did, I created 4 global variables in python, and pass those variables to background of each flex? To remain consistent project wide.
What is wrong with this?
Also, if I decided to create a css theme file.
Would I able to distinguishly identify the 4 flex container above and set different color to them?
Or theme can only be applied as per component type.
Anyway, my problem is not about the strategy above nor the choice to use expression vs python script.
Python is more readable for me. Is there an advantage favoring the use of expression?
My problem is, for some reason, the parameter forgets the value that was set to it, during saving/closing/reopening of view.. and since the binding does not get triggered, it returns an error.
Expressions are more performant than script transforms and will reduce the load on your gateway. This is especially important for larger systems
The whole scripting engine restarts every time you save the project.
Using Perspective Styles are far more performant than reading variables from script libraries within a script transform, they're also far more obvious and user friendly for other engineers when maintaining or extending a project. Design for performance and user experience first; script transforms should only ever be the last option if you can't achieve the same thing via other methods (e.g. tag / expression bindings)
Yes, I would create 4 styles in that case, assuming they're used in more than one place.