Script Widget does not work as expected - solved

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Kangaroo SW
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 35
Joined: Sat Jan 15, 2011 10:57 am

Script Widget does not work as expected - solved

Post by Kangaroo SW » Sun May 05, 2024 11:09 am

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 ?
Attachments
button_0.3.livecodescript.zip
(2.54 KiB) Downloaded 10 times
Last edited by Kangaroo SW on Wed May 08, 2024 7:33 am, edited 1 time in total.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7257
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Script Widget does not work as expected

Post by jacque » Sun May 05, 2024 5:43 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 13863
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Script Widget does not work as expected

Post by Klaus » 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?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7257
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Script Widget does not work as expected

Post by jacque » 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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 13863
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Script Widget does not work as expected

Post by Klaus » Mon May 06, 2024 8:46 pm

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

stam
Posts: 2736
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Script Widget does not work as expected

Post by stam » Tue May 07, 2024 7:29 pm

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

Kangaroo SW
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 35
Joined: Sat Jan 15, 2011 10:57 am

Re: Script Widget does not work as expected - solved

Post by Kangaroo SW » Wed May 08, 2024 7:35 am

@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.

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”