modal stack in the centre o stack calling it

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

modal stack in the centre o stack calling it

Post by jalz » Wed Jan 15, 2014 11:37 pm

Hi Guys,

I've got a Main stack sized something like 600 x 600. I have created a substack called myForm which is approximately 350x350 which I want popping up as a modal dialog. Ive figured out how to do this with little scripting, however to take this further I would like the modal box appear in the centre of the stack that called it. Is there an easy LiveCode way to achieve this, or do I need to pass over the location, height and Width to a handler in myForm and then using on opencard try and centre the modal box using location?

Code: Select all

on opencard
modal stack "myForm"
end opencard


open card

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: modal stack in the centre o stack calling it

Post by bn » Thu Jan 16, 2014 12:32 am

Hi Jalz,

please be very careful when using modal. If anything goes wrong you lock yourself out of LiveCode and no way back.

Always script a button on the substack to become modal a button or something to get out of modal. I would close everthing that is not necessary to have around and save often before testing modal.

Attached is the simplest stack showing a substack at the location of the mainstack as modal. (with a button on the substack that hides the substack and topLevels it)

Kind regards
Bernd
Attachments
main.livecode.zip
(994 Bytes) Downloaded 261 times

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: modal stack in the centre o stack calling it

Post by jalz » Thu Jan 16, 2014 10:26 pm

Thankyou bn

Exactly what I wanted, I'll experiment with modal and take on board on what you said about being careful with modal.

All the best

Jalz

ps323
Posts: 1
Joined: Fri Jan 17, 2014 6:11 pm

Re: modal stack in the centre o stack calling it

Post by ps323 » Fri Jan 17, 2014 6:13 pm

bn wrote:Hi Jalz,

please be very careful when using modal. If anything goes wrong you lock yourself out of LiveCode and no way back.

Always script a button on the substack to become modal a button or something to get out of modal. I would close everthing that is not necessary to have around and save often before testing modal.

Attached is the simplest stack showing a substack at the location of the mainstack as modal. (with a button on the substack that hides the substack and topLevels it)

Kind regards
Bernd
No way back? So if using modal there isn't any back door?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: modal stack in the centre o stack calling it

Post by bn » Sat Jan 18, 2014 1:03 am

Hi ps323,

welcome to the forum.
No way back? So if using modal there isn't any back door?
there is s a way back it you change the ("mode" -> dicitonary), back to something else. E.g. toplevel = mode 1,

you just have to be aware of it and take it into account. See the example stack.

kind regards
Bernd

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: modal stack in the centre o stack calling it

Post by jalz » Mon Jan 20, 2014 12:19 am

Hi all, I've got another query regarding modals.

I'm calling my modal dialog with from stack A with the following code.

Code: Select all

on mouseUp
   set the loc of stack "EditForm" to the loc of this stack
   modal stack "EditForm"
   show stack "EditForm"
   -- answer "hello"
   --RefreshMyGrid
end mouseUp
After I complete my form and click on continue, I want to call a script called RefreshMyGrid which resides in the main stack(the stack that calls the modal).

I've been experimenting on how best to call this script, I'd assumed that when I've called the modal stack "EditForm" and show stack "EditForm", the script pauses, until the user exits out of the modal. However this isn't true, my testing seems to indicate the script runs all the way through.

I've tried calling RefreshMyGrid from the modal dialog, but this doesn't work because the script isn't in the in EditForm stack.

Whats the best way to call the RefreshMyGrid handler, after I have entered in my details

Thanks

Jalz

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: modal stack in the centre o stack calling it

Post by bn » Mon Jan 20, 2014 1:36 pm

Hi Jalz,

assuming a handler called "RefreshMyGrid" lives in the card script of the current card your mainstack, the one from which you call the modal stack then

put

Code: Select all

  send "RefreshMyGrid" to the current card of  stack the mainstack of this stack in 1 milliseconds
this as the last line of code into the closing button of your modal stack.
This will release the modal stack (since it is send in time) and your mainstack can proceed with updating the dataGrid.

In case "RefreshMyGrid" resides somewhere else you can address that object instead of the card.

Kind regards
Bernd

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: modal stack in the centre o stack calling it

Post by jalz » Mon Jan 20, 2014 10:39 pm

Thank you Bernd

That works a treat :)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

Re: modal stack in the centre o stack calling it

Post by dunbarx » Mon Jan 20, 2014 11:39 pm

Bernd.
there is s a way back it you change the ("mode" -> dicitonary), back to something else. E.g. toplevel = mode 1,
What can one do to change the mode of a dialog or modal stack if that stack is already in front? I would have said what you did at first, that you are locked out completely if you do not provide a way to dismiss such a thing from within the stack or dialog itself, no other object being able to receive any action while this is the case.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

Re: modal stack in the centre o stack calling it

Post by dunbarx » Mon Jan 20, 2014 11:48 pm

The only way out is to create a kluge (I thought) perhaps having something like this in the modal stack:

Code: Select all

on opencard
   send "closeup" to me
end opencard

on closeUp
   if the optionKey is down then close this stack
   send "closeUp" to me in 10
end closeUp
An interrogative process can obviously run in a modal stack, but events are locked out totally (again, I thought).

Of course, better, as you warned, to make sure to put a button in the stack that closes that stack.

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: modal stack in the centre o stack calling it

Post by bn » Tue Jan 21, 2014 12:28 am

Hi Craig,
I tried your suggestion. It works. I made a slight modification to your script

Code: Select all

on opencard
   send "closeup" to me
end opencard

on closeUp
   if the optionKey is down then
      close this stack
      exit closeUp
   end if
   send "closeUp" to me in 10
end closeUp
without "exit closeUp" send in time never stops and repeatedly opening and closing the substack piles up the "closeUp" messages.

Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10332
Joined: Wed May 06, 2009 2:28 pm

Re: modal stack in the centre o stack calling it

Post by dunbarx » Tue Jan 21, 2014 3:43 am

Bernd.

Sure. I just threw that together to see if in fact it was possible to "access" a modal stack in that way. A "back door". I was surprised to find it worked. But in hindsight, I suppose the "lock-out" pertains to mouse and keyboard actions directed to objects on the card, not running in the background. Anyway, it was a nice thing to know, but of no help at all unless previously arranged. And again, in that case, just make an escape button.

So did you have another way in mind?

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: modal stack in the centre o stack calling it

Post by bn » Tue Jan 21, 2014 9:47 am

Hi Craig,
So did you have another way in mind?
No, other than what I wrote not. Actually modal scares me a bit. I don't use it except for answer and ask. It is a bit forcing the user and locking the machine and probably should be used only rarely.

Kind regards
Bernd

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: modal stack in the centre o stack calling it

Post by jacque » Tue Jan 21, 2014 9:59 am

In the IDE you can hold down option-command-shift and right click to get the contextual menu. There's an option there to set the stack to another mode.

In a standalone though you're locked out.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: modal stack in the centre o stack calling it

Post by bn » Tue Jan 21, 2014 10:05 am

Hi Jacque,
In the IDE you can hold down option-command-shift and right click to get the contextual menu. There's an option there to set the stack to another mode.
That is good to know, thanks for reminding.

Kind regards
Bernd

Post Reply