5
$\begingroup$

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".

$\endgroup$
5
  • $\begingroup$ Ok, now I saw that I was way off in your intentions $\endgroup$
    – Rojo
    Commented Jul 3, 2012 at 1:47
  • $\begingroup$ @Rojo no prob, In the future I'll try and post a better example. Thanks! $\endgroup$ Commented Jul 3, 2012 at 1:55
  • $\begingroup$ @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. $\endgroup$ Commented Jul 3, 2012 at 2:01
  • $\begingroup$ 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... $\endgroup$
    – Rojo
    Commented Jul 3, 2012 at 2:10
  • $\begingroup$ @MikeHoneychurch, forgot to ping you in the previous comment $\endgroup$
    – Rojo
    Commented Jul 3, 2012 at 3:38

2 Answers 2

11
$\begingroup$

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"]
$\endgroup$
14
  • 1
    $\begingroup$ +1 for #0 and ##&[] :-) $\endgroup$
    – Mr.Wizard
    Commented Jul 3, 2012 at 2:28
  • 1
    $\begingroup$ @Mr.Wizard, I already used him once earlier today, which is weird because I never use it, check this. $\endgroup$
    – Rojo
    Commented Jul 3, 2012 at 2:30
  • $\begingroup$ @Rojo nicely done! Thanks! $\endgroup$ Commented Jul 3, 2012 at 2:30
  • 2
    $\begingroup$ One more thing to add to the long list of code samples I need to work through. $\endgroup$
    – Mr.Wizard
    Commented Jul 3, 2012 at 2:30
  • 1
    $\begingroup$ @Rojo actually that makes it of interest to me; after all "I code perverse Mathematica" according to Simon. $\endgroup$
    – Mr.Wizard
    Commented Jul 3, 2012 at 2:44
7
$\begingroup$

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"}]
$\endgroup$
1
  • $\begingroup$ Very cool solution Mike. Works great! Thanks for the help! $\endgroup$ Commented Jul 3, 2012 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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