Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to construct a GUI that changes depending on what's chosen in certain popup menu's. For example: The default state of the menu is condition one, but when the first PopupMenu is selected other menu configurations are displayed. To keep the GUI simple each popup menu has a function attached and the menu change allows the user to use a different set of functions. Data input is done by importing so non of these menus provide variable input to functions. I have reviewed this code: Manipulate with a variable number of sliders but have not been able to figure out how to modify it to produce the results I need. Thanks very much for your help! Bad code example follows:

DynamicModule[{n = 1}, 
Column[{Dynamic[
Grid[Table[
  With[{i = i}, {i, 
    PopupMenu[
     Dynamic[data[[i]]], {a -> "one menu" , 
      b -> "Add another Menu" }], Dynamic[data[[i]]]}], {i, 
   n}](*Table*)]](*Dynamic*)}, Center](*Column*)]

I would like the menu to produce a second menu when "Add another Menu" is selected. So for example "Add another menu" is selected and it produces a "New Menu" Popup Menu below it, but remains showing the "Add another menu" selection and does not revert back to "one menu".

share|improve this question
    
Ok, now I saw that I was way off in your intentions –  Rojo Jul 3 '12 at 1:47
    
@Rojo no prob, In the future I'll try and post a better example. Thanks! –  R Hall Jul 3 '12 at 1:55
    
@Rojo your answer had been deleted but just to follow up -- I am not rejecting the use of tagging rules per se -- I use them often -- just noting that they can be a bottleneck if you have a lot of them and it wasn't clear how big E Halls actual GUI is -- so worth the caveat. –  Mike Honeychurch Jul 3 '12 at 2:01
    
Mike, I had totally misinterpreted his question, my bad. I thought he wanted a separate dialog in which to choose from certain functions that would be available to him in another separate dialog. Somehow I read popup and thought dialog. So, I thought that if I used dynamic module wormholes, I would still need the generating notebook to link those dialogs... –  Rojo Jul 3 '12 at 2:10
    
@MikeHoneychurch, forgot to ping you in the previous comment –  Rojo Jul 3 '12 at 3:38
add comment

2 Answers

up vote 8 down vote accepted

Let's see if now I got it better...

DynamicModule[{var = False}, 
Dynamic@Column[{PopupMenu[ 
Dynamic[var], {False -> #, 
True -> "Add another Menu"}],   
If[var, #0["new menu"], ## &[]]}]] &["one menu"]
share|improve this answer
1  
+1 for #0 and ##&[] :-) –  Mr.Wizard Jul 3 '12 at 2:28
1  
@Mr.Wizard, I already used him once earlier today, which is weird because I never use it, check this. –  Rojo Jul 3 '12 at 2:30
    
@Rojo nicely done! Thanks! –  R Hall Jul 3 '12 at 2:30
1  
One more thing to add to the long list of code samples I need to work through. –  Mr.Wizard Jul 3 '12 at 2:30
1  
@Rojo actually that makes it of interest to me; after all "I code perverse Mathematica" according to Simon. –  Mr.Wizard Jul 3 '12 at 2:44
show 9 more comments

Some generic examples:

DynamicModule[{var = 3, var2 = 1, var3 = "hello"},

 Column[{
   PopupMenu[
    Dynamic[var], {1 -> "Display Popup", 2 -> "Display Input field", 
     3 -> "None"}],

   PaneSelector[{
     1 -> PopupMenu[Dynamic[var2], Range[4]],
     2 -> InputField[Dynamic[var3]],
     3 -> Spacer[0]
     }, Dynamic[var]]

   }]
 ]

Alternatively use Join and If | Switch | Which to determine what gets displayed:

DynamicModule[{var = 3, var2 = 1, var3 = "hello"},

 Dynamic[
  Column[
   Join[
    {PopupMenu[
      Dynamic[var], {1 -> "Display Popup", 2 -> "Display Input field",
        3 -> "None"}]},

    Switch[var,
     1, {PopupMenu[Dynamic[var2], Range[4]]},
     2, {InputField[Dynamic[var3]]},
     3, {}
     ]
    ]

   ],
  TrackedSymbols :> {var}]
 ]

And you can set other variables based on what gets chosen in your "starting" popup e.g.:

PopupMenu[
 Dynamic[var, (var = #; If[var==1,var2 = 2; var3 = "something"]) &], {1 -> 
   "Display Popup", 2 -> "Display Input field", 3 -> "None"}]
share|improve this answer
    
Very cool solution Mike. Works great! Thanks for the help! –  R Hall Jul 3 '12 at 1:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.