How to build a dynamic user-option pop-up menu

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

How to build a dynamic user-option pop-up menu

Post by kresten » Fri Oct 16, 2015 2:05 pm

I am developing a new (sub)stack, where user can create, baptize decorate and delete new cards. Preliminarily, user can browse back and forth between the cards, and see their cardnames . But I want to create a pop-up menu with a scroll field, where user can see all (actual) cardnames, and by selecting one go to that card.
In order to facilitate the help I hope to find here I will quote my preliminary scripts to the 5 involved objects:

PTStack script
on openCard
put name of this card into field "PictureName"
put empty into char 1 to 4 of field "PictureName"
end openCard

PTCreate new button script
on mouseUp
go to last card of this stack
new card
ask "Give a name to this picture"
select this card
set the name of this card to it
put it into field "PictureName"
end mouseUp

PTBaptize button script
on mouseup
ask "Give a name to this picture"
select this card
set the name of this card to it
put it into field "PictureName"
end mouseup

I imagine that the "Baptize card" button should include a new handler to send the cardname to the pop-up menu, thus adding it as a selectable option, which, when clicked, will open the indicated card.

The "delete card" button should then include a handler, which would remove the corresponding option in the pop-up menu

PT Delete button script
on mouseup
delete this card
end mouseup

A complication is, that user has the option to re-baptize a card. This should of course result in the old cardname being replaced by the new cardname in the pop-up menu. I guess this should be handled through an addition to the script of the Baptize card button script.

PopUp menu script
on menuPick pItemName
switch pItemName
case 1
open card 2 of this stack
case 2
open card 1

card 3
end switch
end menuPick

So this is where I am stranded :cry:

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

Re: How to build a dynamic user-option pop-up menu

Post by dunbarx » Fri Oct 16, 2015 2:28 pm

Hi.

Hmmm.

Does "Baptize" mean to set certain properties of a card, like its name?

What does the line "select this card" do?

If you want to use a pop-up button to display the names of all cards (and I hope the list does not get too long, or this will fast become the wrong way to do it) you can, on mouseEnter, say, loop through all card names and set the contents of the pop-up to that data. Thus every time the user uses that button, the current card names will be pre-loaded. If a card is added or deleted, it does not matter, because the update will simply reflect the current suite. I suppose it is possible to update the pop-up text every time you add or delete a card, but that requires more management, and may not have any advantage over the on-the-fly method.

Is this what you were looking for?

Craig Newman

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Re: How to build a dynamic user-option pop-up menu

Post by kresten » Mon Oct 19, 2015 10:53 am

Hi Craig

The baptize just stands for "give a name to" - no religious overtones
The select card line is probably superfluos, I just use it to be sure

The description you give of a way to solve the problem sounds superfine . But I am so much a dilletant, that I couldn't formulate the script :oops:
So, please, will you - or whoever professional comes by here - write the full script to the option menu , following your explanation ?

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

Re: How to build a dynamic user-option pop-up menu

Post by dunbarx » Tue Oct 20, 2015 1:54 am

Hi.

Is a dilettante some sort of sect or cult member?

Make a new stack with a handful of cards. On card 1, put a standard button and an option button named "yourOption". In the script of the standard button (I really should make you do this):

Code: Select all

on mouseUp
   repeat with y = 1 to the number of cds
      set the name of cd y to "XYZ" && random(99)
   end repeat
end mouseUp
Click that button. Now in the script of btn "yourOption":

Code: Select all

on mouseDown
   repeat with y = 1 to the number of cds
      put the name of cd y & return after temp
   end repeat
   put temp into me
end mouseDown
The cute trick here is that the entire suite of cards is read and loaded each and every time you click on the option button. Computers do not get bored. But this relieves you of the chore of managing your card names, irrespective of whether you add or delete them, and speed is (probably) not an issue. Note that if you do indeed make a new card and do not name it, you will get the default card name.

Craig

kresten
Posts: 153
Joined: Tue Sep 30, 2008 3:01 pm
Contact:

Re: How to build a dynamic user-option pop-up menu

Post by kresten » Tue Oct 20, 2015 2:37 pm

Thank you for the instructions, but I hate to say but they are totally beside the point.

Dilettante means Amateur or un-professional.

I tried your instructions, but

Please go back to my own first question and its script and understand how cards are named by user, and shall not be renamed as your first button script will do.

I tried to create a "Your options" button - unsure of precisely what kind of button you mean pulldown menu or pop-up menu, but the handler you suggest must be a supplement to something.
I think your idea of the option button to read and load all card names every time it is clicked is fine, but on click it should open a scrolling list of card names, and , when a cardname is clicked there it should open that card ( where the grouped option button is also visible).
Can you - or other visitors - compose such a full script.

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to build a dynamic user-option pop-up menu

Post by Klaus » Tue Oct 20, 2015 4:26 pm

Hi Kresten,

you could add a handler that will fill your menu button everytime the user changes the card name!

Like this:

Code: Select all

command update_navigationmenu
   repeat with i = 1 to the num of cds
    put the short name of cd i & CR after tCardNames
  end repeat
  delete char -1 of tCardNames
  set the text of btn "your menu button here..." to tCardNames
end update_navigationmenu
Then put it in all your "mouseuo" handlers as the last line:

Code: Select all

on mouseUp
  go to last card of this stack
  new card
  ask "Give a name to this picture"
  set the name of this card to it
  put it into field "PictureName"
  update_navigationmenu
end mouseUp
Same for the other "mouseup" handler.

Then put this into the script of that namely menu button:

Code: Select all

on menupick tItem
  go cd tItem
end menupick
At least this is how I understood your problem :D


Best

Klaus

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

Re: How to build a dynamic user-option pop-up menu

Post by jacque » Tue Oct 20, 2015 5:01 pm

No need to loop through all the cards to collect the names, there's a property for that. See "cardnames" in the dictionary. It's fast enough to use in the mouseDown handler as in Craig's example. The script becomes very simple that way.

Code: Select all

on mouseDown 
  put the cardnames of this stack into me
end mouseDown 

on menuPick pName
  go card pName
end menuPick
LiveCode will keep track of the cards for you so the names will always be current. The option button is one of the specific types in the tool palette, watch the tool tips to find it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to build a dynamic user-option pop-up menu

Post by Klaus » Tue Oct 20, 2015 5:10 pm

Ah, yes, "the cardnames of stack xyz", thanks for the heads-up!

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

Re: How to build a dynamic user-option pop-up menu

Post by dunbarx » Tue Oct 20, 2015 5:45 pm

Hi.

My sense of humor keeps getting misread. I know what a dilettante is. I also know how to spell it. :D

I only gave you that first handler so you did not have to name your cards by hand. It was a throw-away.

The handler I gave you works fine. Jacque's comment about the native property is an improvement. But in order to navigate to the indicated card, you need to use the "menuPick" handler, pre-loaded in every menu button, option or whatever. Can you do this? Write back if you need help. About three lines ought to do.

Craig

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

Re: How to build a dynamic user-option pop-up menu

Post by dunbarx » Tue Oct 20, 2015 11:14 pm

OK. Try this in the script of the button, of whatever menu style:

Code: Select all

on menuPick pItemName
      go pItemName
end menuPick

on mouseDown
      repeat with y = 1 to the number of cds
            put the name of cd y & return after temp
      end repeat
      put temp into me
end mouseDown
Do what you need?

Craig

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: How to style a pop-up menu button

Post by marksmithhfx » Wed Sep 07, 2016 3:48 am

Is there a way to style a pop-up menu button? I can't see anything like the style options provided for regular buttons (and I want my pop-up to look like a regular button).

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: How to build a dynamic user-option pop-up menu

Post by marksmithhfx » Wed Sep 07, 2016 3:50 am

Sorry, I shouldn't be so rude. First, a big thanks to Craig and Jacque for all of the tips you provided in this thread. From the various responses I was able to pull together exactly what I was looking for. Now I just need to get that strange looking piece of text (Select a table...) to look like a button.

Cheers,

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

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

Re: How to build a dynamic user-option pop-up menu

Post by bn » Wed Sep 07, 2016 11:07 am

Hi Mark,

good to see you.

If I understand correctly what you want you could try this:

make a regular button set its label to "select a table..."
set its script to

Code: Select all

on mouseDown
   popup btn "pop"
end mouseDown
now make a popUp button, set its name to "pop"
set the script of button "pop" to

Code: Select all

on menuPick pItemName
   put pItemName
   -- or whatever
end menuPick
that should do it. Once you selected a table: bon appetit :)

Kind regards
Bernd

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: How to build a dynamic user-option pop-up menu

Post by marksmithhfx » Wed Sep 07, 2016 3:30 pm

Bernd, delicious! Thank you :)

The advantage with your solution is you get a fixed label "Select a table..." that doesn't change with each new choice. I think we should add it to the documentation... it's a clever hack.

Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: How to build a dynamic user-option pop-up menu

Post by marksmithhfx » Wed Sep 07, 2016 3:34 pm

Also, here's a nice refinement. If you want your popup to have dynamic choices, in the first (regular button) include the following:

Code: Select all

on mouseDown
   put myChoices into btn "pop"
end mouseDown

on mouseUp
   popup btn "pop"
end mouseUp
In may case, I load the table names of whatever database the user is browsing into the pop up and when they select a table it displays the table attributes. I'll send you a copy when I've got it working.

Cheers,

M
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

Post Reply