Page 1 of 1

Script Widget does not work as expected - solved

Posted: Sun May 05, 2024 11:09 am
by Kangaroo SW
Greetings everyone :D ,

With a bit of spare time on my hands, I decided to dive deeper into Script Widgets.
My initial idea was to craft a simple yet practical Script Widget, and I settled on creating a Button Control.

However, navigating the creation process proved challenging, as there's scarce documentation available
online for Script Widgets :( .

Nevertheless, after much trial and error, I managed to piece together a functional button by borrowing
code snippets from an existing Script Widget I stumbled upon.

To my surprise, when I attempted to add a "mouseUp handler script" to the Script Widget in the stack, it failed to trigger :?:

I theorized that these messages might be intercepted by the Script Widget itself, necessitating the inclusion of handlers
within the Script Widget to pass along mouseUp, mouseDown,etc. and similar events to be utilized in a Widget Script.

Unfortunately, this attempt also proved unsuccessful, leaving me puzzled as to why :roll:

I had hoped to employ Script Widgets in the same intuitive manner as other Controls from the "Tools Stack" – simply dragging
them onto the stack and setting an executable script.

However, it appears this isn't the case. Could someone kindly shed light on how I might achieve this?


Attached: My widget button script widget (button_0.3.livecodescript)


This is the script inside the button:

Code: Select all

on mouseUp
   put "mouseUp"
   pass mouseUp
end mouseUp

on mouseDown
   put "mouseDown"
   pass mouseDown
end mouseDown

on mouseEnter
   put "mouseEnter"
   pass mouseEnter
end mouseEnter

on mouseLeave
   put "mouseLeave"
   pass mouseLeave
end mouseLeave

on mouseMove
   put "mouseMove"
   pass mouseMove
end mouseMove

on mouseDoubleUp
   answer "You did a mouseDoubleUp !"
   pass mouseDoubleUp
end mouseDoubleUp

You can install the Script Widget and do a double click on the button in the Widget. It will answer "You did a mouseDoubleUp!" This proves that the script is actually present in the button. However, all the other messages which are sent - don't travel up the hierarchy :roll:


Why is this and how can I achieve my goal ?

Re: Script Widget does not work as expected

Posted: Sun May 05, 2024 5:43 pm
by jacque
None of the built-in LC widgets respond to common mouse events either, the engine appears to ignore them. That's why each one has its own terminology for mouse clicks. I have no idea why they behave that way.

Re: Script Widget does not work as expected

Posted: Sun May 05, 2024 6:49 pm
by Klaus
Yes, that applies to widgets built with Livecode Builder, but does that also apply to SCRIPT (built with LC scripts) widgets?

Re: Script Widget does not work as expected

Posted: Mon May 06, 2024 6:49 pm
by jacque
Klaus wrote:
Sun May 05, 2024 6:49 pm
Yes, that applies to widgets built with Livecode Builder, but does that also apply to SCRIPT (built with LC scripts) widgets?
Apparently. Who knows.

Re: Script Widget does not work as expected

Posted: Mon May 06, 2024 8:46 pm
by Klaus
jacque wrote:
Mon May 06, 2024 6:49 pm
Klaus wrote:
Sun May 05, 2024 6:49 pm
Yes, that applies to widgets built with Livecode Builder, but does that also apply to SCRIPT (built with LC scripts) widgets?
Apparently. Who knows.
I don't! :-D

Re: Script Widget does not work as expected

Posted: Tue May 07, 2024 7:29 pm
by stam
Kangaroo SW wrote:
Sun May 05, 2024 11:09 am
To my surprise, when I attempted to add a "mouseUp handler script" to the Script Widget in the stack, it failed to trigger :?:
What do you mean by this? Do you mean adding a handler to the built widget's script window?
Or inside the scriptOnlyStack that builds the widget?

If it's the former, you probably have to send the message to the owner.
If using in a group, it needs to be handled in the parent, but in a script widget, it ends up in the widget script's left pane/list of handlers.

eg - in the scriptOnlyStack:

Code: Select all

on mouseUp
   send "mouseUp" to the owner of me
end mouseUp
After building the widget, if you open the script editor and you should see it in the left pane, and you can add to your script.
Not tested this specific code, but *should* work... I don't know if the message, being a reserved word, will be an issue, but you can replace it with whatever you want if it is...

Discussion (with some input from @livecodeali) here: viewtopic.php?t=38572

I've had 1 success with script widgets and a couple of troubled results, but it's *a lot* of deceptively hard work... It feels like it shouldn't be, but it is... to the point that I've just gone back to using groups (but having now followed the code pattern needed for SW, these are more robust).
Maybe I'll pick these up again some day, but life is busy and short...

If you are going to create a script widget with Livecode's script editor, using Bernd's code-folding solution is a must... viewtopic.php?f=9&t=38912

Re: Script Widget does not work as expected - solved

Posted: Wed May 08, 2024 7:35 am
by Kangaroo SW
@stam
@bn

The suggestion to incorporate the mouseUp handler into the build script for
the widgets works like magic :P .

Thank you, stam, this is precisely what I needed.

Interestingly, Bernd had the same idea yesterday, and it functions flawlessly :lol: .

With this resolved, I can now proceed to enhance the Script Widget and polish
the graphics.

Much appreciation to both Bernd and Stam for your assistance.