Disabling all controls in stack..

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
tasdvl9
Posts: 94
Joined: Fri Dec 06, 2013 3:55 am

Disabling all controls in stack..

Post by tasdvl9 » Wed Jan 07, 2015 4:18 pm

Hi All,

I'm trying to implement a timeout feature which will disable all of the controls in a specific stack once the time has elapsed.
Is there a way to do this?

I was hoping to just disable the stack and that would also disable my controls but I don't think this is the case.

Thanks!

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

Re: Disabling all controls in stack..

Post by Klaus » Wed Jan 07, 2015 4:26 pm

Hi tasdvl9,

you cannot disable stacks or cards!

You'd need to:
1. loop over all controls in your stack/card and disable them.
Or
2. Simply create a filled graphic, with any blendlevel set, in the size of your card,
that you simply show in your stack on top of all controls 8)


Best

Klaus

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2515
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Disabling all controls in stack..

Post by jmburnod » Wed Jan 07, 2015 4:28 pm

Hi tasdvl9,
You can of course disable all controls like this:
1. Building a list of all controls of each cd of your stack
2. Launch a loop to disable each control

but display a button transparent at the rect of cd will be easier
Best regards
Jean-Marc

tasdvl9
Posts: 94
Joined: Fri Dec 06, 2013 3:55 am

Re: Disabling all controls in stack..

Post by tasdvl9 » Wed Jan 07, 2015 4:42 pm

Thanks, All.

I'll give that a go!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7954
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Disabling all controls in stack..

Post by FourthWorld » Wed Jan 07, 2015 5:51 pm

An overlay object is a good solution to prevent mouse clicks, but may not prevent keyboard access for any controls whose traversalOn property is set.

To truly disable all controls (and have their appearances updated accordingly) you can group them and then enable/disable the group.

To group them, in the IDE choose Edit->Select All, then Object->Group Selected. You may want to name the group in the Property Inspector.

At runtime, enabling or disabling them is just one line:

Code: Select all

disable group "MyGroup"
...or:

Code: Select all

enable group "MyGroup"
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

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

Re: Disabling all controls in stack..

Post by Klaus » Wed Jan 07, 2015 10:25 pm

Hi Richard,
FourthWorld wrote:An overlay object is a good solution to prevent mouse clicks, but may not prevent keyboard access for any controls whose traversalOn property is set.
ah, yes, good catch!


Best

Klaus

uelandbob
Posts: 72
Joined: Mon Dec 29, 2014 3:28 pm

Re: Disabling all controls in stack..

Post by uelandbob » Thu Jan 15, 2015 11:26 am

Would it be possible to create a frontScript that trapped all mouse and keyDown events? Just a thought*.

Here is a little experiment you can do. Create a stack and on a card, add two buttons called "answer" and "myFront". Make their scripts look like this:

Code: Select all

-- answer
on mouseUp
   answer "How are you?"
end mouseUp

Code: Select all

-- myFront
on mouseUp
   put "trapped mouseUp"
end mouseUp

on mouseDown
   put "trapped mouseDwn"
end mouseDown
in the card script write a handler

Code: Select all

-- card
on commandKeyDown theKey
   if  (the shiftKey is down)  then
      if theKey = "a" then
         beep
           insert script of button "myFront" into front
        else
           beep 2
         remove the script of btn "myFront" from front
      end if
   else 
      pass commandKeyDown theKey
   end if
end commandKeyDown
Test that it works

1. Click on the answer button. A dialog box should appear. Dismiss it.
2. Press Cmd+Shift+a. This will activate the frontScript.
3. Click on the answer button. Nothing happens, proving that frontScript swallows the mouseDown and mouseUp.
4. Press Cmd+Shift+r. This will remove the frontScript.
5. Click on the answer button. A dialog box should appear. Dismiss it.


You could do similar things for keyDown, and other events that you want to trap.

Warning: I am not super familiar with frontScript yet, and it is little tricky. In theory it sounds nice, but in practice it could prove to be more complicated than it appears at first glance. So always experiment in a new stack or if you experiment in an existing stack, make sure to take a copy. Things could lock themselves up and drive you crazy :evil:

*The overlay solution is easier and more elegant, and in a real situation I would use it. But to play with and get familiar with frontScript is also good, because you'll never know when you'll need it. :wink:
uelandbob@gmail.com

Post Reply

Return to “Talking LiveCode”