Force a component event in perspective

Is there a way to force an event to fire such as the mouseClicked event of button?

Is it on the same window, or a separate window?
And are you trying this in vision or perspective?

Components are in same window and it is in perspective.

You could use a .doclick function.

button = event.source.parent.getComponent('press me')
button.doClick()

It does not work.

AttributeError:‘NoneType’ object has no attribute ‘source’

Please post your exact code you put in. Did you change the ‘press me’? You will need to correctly address the button. and is the button directly under the main window or subbed under another component etc…?

Perspective doesn’t have a doClick() function.

Your question sounds like an XY problem. What are you trying to do on mouse click that you can’t just invoke directly from whatever scripting context you’re already in?

Any non-trivial business logic should be in custom methods, or, ideally, project library scripts that can be invoked with the required arguments. That way it’s trivial to invoke your logic from two different places, instead of trying to invoke a click handler directly.

4 Likes

I say it to all my coworkers all the time - avoid the magic pushbutton anti-pattern.

Get into the habit of writing business logic as a function first and then call that from the GUI. It will eliminate many of your problems and keep your code a lot more DRY.

DRY meaning Do not Repeat Yourself. If you’ve ever seen the same 5 lines on property changes of 10 different components, then you’ve experienced WET code - Write Everything Twice.

I am of the mindset that the GUI only exists to supply parameters to function calls. Treating it like such has saved me a lot in headaches and debugging.

Point is well taken.

Thank you.

1 Like

I actually passed down a click event on that fileupload component because the small version seemed to be bugged ([BUG] fileUpload component React error #185 - #6 by victordcq)
i did create a module that sends down a click event with just a prop for the html selector…
The small fileupload was buggy but the big one isnt so i made a small button and send the event through to the bigupload as that one triggers the fileupload immedialty instead of showing the popup ‘browse or drag’ xD What would have probably been better was to recreate/fix the fileupload component but to much work without the source code so Im just hacking my way through everything lol. I could also have waited for the bug to be fixed, but such a small component doesnt take long to make xd

But i aggree this should be avoided if possible…