Pass a script as custom property

I am trying to create a custom template that has the functionality of a generic button.
I have a certain style which has been set using a ButtonStyle dataset tag that gets bound to my button.

The last piece of the puzzle to make my template truly customizable is to somehow pass through a script as a custom property.

Is there anyway to do this? I’ve created a string custom property on by template called “Script”. But simply referencing this property in the scripting of my button with:


doesn’t work at all.

I tried a workaround where i would add as script to the template once i’ve added it to a window. However it only executes when i click on an area of the template NOT taken up by the button. If i click directly on the button, then the script inside the template is executed.

Can you post some images please? Is the script changing in different situations? What is the button for ?

I haven’t used them in jython myself, but you are looking for the python ‘exec’ statement, the ‘eval()’ function, and if speed matters, the ‘compile()’ function. They are well-documented for python, less so for jython.

I’ve managed to make a custom button where the template has a custom string property called Script. In the template scripting when the mouse is clicked it will run ‘project.Buttons.Script(event)’ meaning that in my project script library I have a script called Buttons and a single function in the script called Script. The event is passed as a parameter to this function. When making an instance of the button template on a window you then type the buttons intended script name into the custom string property. You can then define the buttons script function in the project script library. If fx. your script name is called Start you can use ‘if event.source.Script == ‘Start’: do stuff’. You can then use other script names in other buttons and define their scrips in the project.Buttons.Script library by using a new if confition.

I’m no expert so I don’t know if this solution is considered best practise, but I really like this approach personally as first of all of course it works but also that I only have to maintain the scripts of my buttons in one place - the script library.

Not entirely sure if this made sense or if it was what you needed, but hope it helps.