Opening a stack as modal and storing user input data

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Opening a stack as modal and storing user input data

Post by quailcreek » Fri Feb 09, 2007 7:16 pm

Hi all,
Is there a way to open a stack as modal and control the position to be at the center of the current stack? I have a stack that will be opened like a viewer to have the user fill in some data. That data will then be stored. I would use INI files to store this data in another development package. What is the best way to handle this in RR so that the data is available for use in some additional calculations?

Thanks in advance
Tom

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sat Feb 10, 2007 1:43 am

Hi Tom,

To go to a stack as modal window:

go stack "Foo stack" as modal

To set the position of the window, add the following to the stack script of your modal dialog window:

Code: Select all

on preOpenStack
  set the loc of me to 32,32 -- almost topleft of the screen
  -- rest of script
  pass preOpenStack -- if necessary
end preOpenStack
instead of 32,32 you can also use the screenloc or any other valid point.

To store the data, add an "Okay" button to your dialog and add a script to that button that writes your data to files. Check the docs for "write". After writing the data, the "Okay" button can close the modal dialog.

There are many ways to do this. Depending on your exact needs, this may not be the best way.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Post by quailcreek » Sat Feb 10, 2007 3:15 am

Thanks Mark,
That work great. I had to use screen loc to position the substack and after it was opend I had to show it. Is that the normal syntax?

Regards
Tom

Here is another puzzle. This script is in a group of check box buttons. What is supposed to happen is when a button is first clicked it should become checked and the text turned red and the substack, which has a cancel button to close it, apperars. Thanks to your help, that part works fine. But the second time the button is clicked - when it's red - the answer dialog should come up. Which it does but the substack comes up too, every time. What am I doing wrong?

Code: Select all

on mouseDown
  if highlight of target is TRUE then -- leave it set to true
    set highlight of target to TRUE
    answer question "What would you like to do" with "Add Data" or "Edit Data" or "Cancel" or "Uncheck Data"
     
    if it is "Uncheck Data" then
      set highlight of target to FALSE
      set textcolor of target to BLACK
      set textstyle of target to plain
    end if
  else
    set highlight of target to TRUE
  end if
end mouseDown

on mouseUp
  if highlight of target is FALSE then
    set highlight of target to TRUE
    set textcolor of target to red
    set textstyle of target to italic
    open stack "Input Stack" as modal
    show stack "Input Stack"
  else
    pass mouseUp
  end if
end mouseUp

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sat Feb 10, 2007 10:40 am

Tom,

Is the autohilite of your checkbox true or false?

If your two handlers are in the same checkbox, the mouseUp handler will always run after the mouseDown handler. The mouseDown handler sets the hilite to false, which is detected by the mouseUp handler. The mouseUp handler always runs, because the mouseDown handler always sets the hilite to false after the first time the checkbox was clicked. Thus the stack always opens.

Why don't you leave the highlighting to Revolution, using the autohilite property? If you do, you only need to check whether the hilite is true and make the handlers act accordingly.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Post by quailcreek » Sat Feb 10, 2007 3:26 pm

Thanks again Mark,
You actually pointed me in the right direction. I turned autohilight off on all of the buttons in the group and thereby took control of the highlighting. Works pretty good except for a samll kink. So... another question. What is the button property that sets the box of a check box button to be grayed? To see what I mean, if you click on a check box button -with autohilighting turned on - and hold the mouse down and then move the cursor off and then back over the button you'll see.

Many thanks
Tom

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sat Feb 10, 2007 3:42 pm

Hi Tom,

This is done by the operating system rather than Revolution. What do you need it for?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Post by quailcreek » Sat Feb 10, 2007 4:17 pm

Mark,
I needed it to fix a condition that comes with the peice of script we've been talking about. Now that I know why it happens I just added a couple of lines of code to clear it up. Thanks for all of the help. You have helped to make my evaluation of RR very plesent.

My goal here is to move an app I've been working on from toolbook to RR. So far, so good.

Regards
Tom

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sat Feb 10, 2007 4:56 pm

Hi Tom,

I'm glad to knwo that my replies were helpful. I'm still a little puzzled, though, why one wouldn't let Revolution deal with hilites and even "gray" states by itself. Even though you say it works now, aren't you making it more complex than necessary, I wonder.

Best,

mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Post by quailcreek » Sat Feb 10, 2007 5:45 pm

I comes down to what I need to happen to a button that's already checked. If it's checked then leave it checked and do some stuff. If it's not check then check it and do some other stuff. Create a group of check box buttons and turn autohilight off. Put the script in the group and you'll see what happens.

Tom

Code: Select all

on mouseDown
  put name of target into tButtonName
  if highlight of target is TRUE then -- leave it set to true
    set highlight of target to TRUE
    set textcolor of target to RED
    set textstyle of target to italic
    answer question "What would you like to do" with "Add Data" or "Edit Data" or "Cancel" or "Uncheck Selection" titled "Here is the data"
     
    switch it
    case "Uncheck Selection"
      set highlight of target to FALSE
      set textcolor of target to BLACK
      set textstyle of target to plain
      break
    case "Add Data"
      set highlight of target to TRUE
      break
    case "Edit Data"
      set highlight of target to TRUE
      break
    case "Cancel"
      set highlight of target to TRUE
      break
    end switch
    
  end if
end mouseDown

on mouseUp
  if highlight of target is FALSE then
    set highlight of target to TRUE
    set textcolor of target to red
    set textstyle of target to italic
    answer "Do some stuff" with "OK" -- this is where the substack is opened an modal
  end if
end mouseUp

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Post by quailcreek » Sat Feb 10, 2007 6:21 pm

Well, now it doen't work. I'm back to the grayed box thing again. The fix I put in - setting the hilight to true - worked and now it doesn't.

I'm very confussed!

Tom

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sat Feb 10, 2007 6:42 pm

Hi Tom,

I don't think this is good interface design. Why don't you simply use two check boxes next to each other or create a button with three different icons?

It is quite inconvenient to have to click buttons in an answer dialog after clicking in a checkbox. It is just a click too many.

Could you explain more about the purpose of this? What is the difference between a button that is checked and a button that has been checked already and is clicked on again? What is supposed to happen if all buttons are checked but none has been clicked on a second time? If you can explain this, I'm sure I can come up with a better interface.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Post by quailcreek » Sat Feb 10, 2007 7:38 pm

Mark,
A differnt interface is OK with me. I was just trying to do things the way I have done them in toolbook. I don't know any difffernt at this point. This works in TB but then three icon would be a bit a of a hassle in TB. So if you're willing to help me out I'm good with it. I'll take a few minutes and try to put what I'm trying to accomplish into words.

Thanks
Tom

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Post by quailcreek » Sat Feb 10, 2007 7:53 pm

Mark,
This is more less a way of keeping track of ones collection. The difference is that, based upon the collected items, one receives awards for certain levels of achievement. This means that item “Aâ€

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sat Feb 10, 2007 9:36 pm

Hi Tom,

I have crated a simple example of what I think your interface might look like. Download it here:

http://economy-x-talk.com/software/buttonsample.rev.zip

The stack will stay on-line for a few days. This is just one of many possibilities of what an interface, whose behaviour of buttons is different depending on the state of other buttons, may look like.

Just try clicking on the most left frame in the blue-gray button. Then try clicking in the other frames.

The gray-blue button with three tiny frames is just a background picture and doesn't to anything. On top of that, there are three transparent buttons.

The most left button is a transparent checkbox. The other two buttons are normal transparent buttons.

Revolution handles the hilited of all three buttons. Revolution also takes care of the icons, which is different depending on their state (enabled, hilited, disabled). So far, we didn't need one single line of script.

The group contains a script, which checks the name of the target (the button clicked on) and acts accordingly.

You can change the icons and the background as you like. The blue rectangle only serves to make the white icons visible on the otherwise white background.

Best regards,

Mark

P.S. I have updated the stack about two hours after uploading it for the first time. The new stack included a mouseRelease handler, which restores the original state of all buttons if the user clicks in the checkbox and moves the mouse away before releasing it.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Talking LiveCode”