5

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

Nothingtoseehere
  • 4,518
  • 2
  • 30
  • 58
  • Ok, now I saw that I was way off in your intentions – Rojo Jul 03 '12 at 01:47
  • @Rojo no prob, In the future I'll try and post a better example. Thanks! – Nothingtoseehere Jul 03 '12 at 01: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 03 '12 at 02: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 03 '12 at 02:10
  • @MikeHoneychurch, forgot to ping you in the previous comment – Rojo Jul 03 '12 at 03:38

2 Answers2

11

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"]
Nothingtoseehere
  • 4,518
  • 2
  • 30
  • 58
Rojo
  • 42,601
  • 7
  • 96
  • 188
7

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"}]
Mike Honeychurch
  • 37,541
  • 3
  • 85
  • 158