Message Boards Message Boards

GROUPS:

Complicated hiding control

Posted 5 months ago
550 Views
|
14 Replies
|
4 Total Likes
|

Hi everyone, I'm developing a wave laboratory which will grow a lot in the following weeks. Things are going fine and fast, except by the system of hiding controls. I can make them work fine, but when some disapeaers Null stay in their places. I can make to hide Null by adding an extra line with nothing inside. But this is not a solution because blank lines replaces the Null lines.

It seems to me that the problem comes from the combination of

Dynamic[
  If[menu == 1,
   Grid[{

with

 If[quantOndas == 1,
        Invisible,
        Identity]@

In the code below the first Grid has a blank line, which acts as a separator. Not a problem.

I would like to make the Null go home and left nothing in its place.

I'll appreciate any help.

Manipulate["Hi",

 Grid[{
   {Control@{{menu, 1 , "Menu:"}, {1 -> "Menu 1", 2 -> "Menu 2"}, 
      ControlType -> RadioButtonBar}},
   {""}
   }],

 Dynamic[
  If[menu == 1,
   Grid[{
     {Control@{{menuInterf, 1, "Operation mode:"}, {1 -> "Manual", 
         2 -> "Automatic"}, ControlType -> RadioButtonBar}}
     }]
   ]
  ],

 Dynamic[
  If[menu == 1 && menuInterf == 1,
   Grid[{
     {Control@{{quantWaves, 1, "Number of waves:"}, {1, 2}, 
        ControlType -> RadioButtonBar},
      If[quantOndas == 1,
        Invisible,
        Identity]@
       Control@{{showSumWaves, False, "Show sum of waves:"}, {True, 
          False}, ControlType -> Checkbox}}
     }]
   ]
  ],

 Dynamic[If[menu == 2,
   Grid[{
     {Control@{{menuOndasEstac, 1, 
         "Stationary waves:"}, {1 -> "Two nodes", 
         2 -> "Node and antinode", 3 -> "Two antinodes"}, 
        ControlType -> RadioButtonBar}},

     {Control@{{harmDispon, 1, "Harmonics:"}, Dynamic@harmonics, 
        ControlType -> PopupMenu},
      Control@{{mostrOndasOrig, True, "Show original waves:"}, {True, 
         False}, ControlType -> Checkbox}}
     }]
   ]
  ]

 ,
 Initialization :> (
   menuInterf = 1;
   harmonics = Range[10];
   )
 ]
14 Replies

If[] statement is not complete, I set "?" where there is Null.

Manipulate["Hi", 
 Grid[{{Control@{{menu, 1, "Menu:"}, {1 -> "Menu 1", 2 -> "Menu 2"}, 
      ControlType -> RadioButtonBar}}, {""}}], 
 Dynamic[If[menu == 1, 
   Grid[{{Control@{{menuInterf, 1, "Operation mode:"}, {1 -> "Manual",
          2 -> "Automatic"}, ControlType -> RadioButtonBar}}}], "?"]],
  Dynamic[If[menu == 1 && menuInterf == 1, 
   Grid[{{Control@{{quantWaves, 1, "Number of waves:"}, {1, 2}, 
        ControlType -> RadioButtonBar}, 
      If[quantOndas == 1, Invisible, Identity]@
       Control@{{showSumWaves, False, "Show sum of waves:"}, {True, 
          False}, ControlType -> Checkbox}}}], "?"]], 
 Dynamic[If[menu == 2, 
   Grid[{{Control@{{menuOndasEstac, 1, 
         "Stationary waves:"}, {1 -> "Two nodes", 
         2 -> "Node and antinode", 3 -> "Two antinodes"}, 
        ControlType -> RadioButtonBar}}, {Control@{{harmDispon, 1, 
         "Harmonics:"}, Dynamic@harmonics, ControlType -> PopupMenu}, 
      Control@{{mostrOndasOrig, True, "Show original waves:"}, {True, 
         False}, ControlType -> Checkbox}}}], "?"]], 
 Initialization :> (menuInterf = 1;
   harmonics = Range[10];)]

I understand. Thank you. There is a post in Stack Exchange about this, but I could not make any of the "solutions" to work. The Which command should work, but not. Any idea?

I do not understand the logic and structure of this menu. If you explain what you want to express then I'll try to help.

Ok. As I said, I'm building a wave laboratory which has at least five experiments (you can see two of them in my code: "menu 1" and "menu 2", which mean "Interference" and "Stationary waves"). For every one of these experiments there are a set of controls that are different for every menu. In order to prevent a huge complicated set of controls shown at the same time, I decided to to show only the controls related to the chosen experiment. Every time the user change the experiment, the shown controls disapear and new ones come up. If I don't do what I am trying to do, there will be a lot of empty space in the control system, which is not convenient. Remember that I can make the annoyng Null to be hidden by adding an extra line with nothing inside (empty line) in the Else part of the If function.

Anderson,

You should also consider the TabView or the MenuView. See the tutorial here. Then you can have different controls for each menu.

Regards,

Neil

I still do not understand but check it out

Manipulate["Hi", 
 Grid[{{Control@{{menu, 1, "Menu:"}, {1 -> "Menu 1", 2 -> "Menu 2"}, 
      ControlType -> RadioButtonBar}}, {""}}], 
 Dynamic[If[menu == 1, 
   Grid[{{Control@{{menuInterf, 1, "Operation mode:"}, {1 -> "Manual",
          2 -> "Automatic"}, ControlType -> RadioButtonBar}}}], 
   Grid[{}]]], 
 Dynamic[If[menu == 1 && menuInterf == 1, 
   Grid[{{Control@{{quantWaves, 1, "Number of waves:"}, {1, 2}, 
        ControlType -> RadioButtonBar}, 
      If[quantWaves == 1, Invisible[xxxx], Grid[{}]], 
      Control@{{showSumWaves, False, "Show sum of waves:"}, {True, 
         False}, ControlType -> Checkbox}}}], Grid[{}]]], 
 Dynamic[If[menu == 2, 
   Grid[{{Control@{{menuOndasEstac, 1, 
         "Stationary waves:"}, {1 -> "Two nodes", 
         2 -> "Node and antinode", 3 -> "Two antinodes"}, 
        ControlType -> RadioButtonBar}}, {Control@{{harmDispon, 1, 
         "Harmonics:"}, Dynamic@harmonics, ControlType -> PopupMenu}, 
      Control@{{mostrOndasOrig, True, "Show original waves:"}, {True, 
         False}, ControlType -> Checkbox}}}], Grid[{}]]], 
 Initialization :> (menuInterf = 1;
   harmonics = Range[10];)]

Alexander,

I was suggesting something like this. I made two changes. First, I used MenuView to create the two menus. Next I Changed Grid[{}] to a spacer to keep the spacing in your If[]. I only did this in one place but it places a 12 x 20 point space to hold the vertical and horizontal spacing.

Spacer[{12,20}]

The background colors need some touchup to match but it should give you an idea of the menuView approach.

Manipulate["Hi",

 MenuView[{"Menu 1" -> 
    Grid[{{Dynamic[
        Grid[{{Control@{{menuInterf, 1, 
              "Operation mode:"}, {1 -> "Manual", 2 -> "Automatic"}, 
             ControlType -> RadioButtonBar}}}]]}, {Dynamic[
        If[menuInterf == 1, 
         Grid[{{Control@{{quantWaves, 1, "Number of waves:"}, {1, 2}, 
              ControlType -> RadioButtonBar}, 
            If[quantWaves == 1, Invisible[xxxx], Grid[{}]], 
            Control@{{showSumWaves, False, 
               "Show sum of waves:"}, {True, False}, 
              ControlType -> Checkbox}}}], Spacer[{12, 20}]]]}}, 
     Alignment -> Left, ItemSize -> {60, 1}, 
     Background -> GrayLevel[0.92]], 
   "Menu 2" -> 
    Grid[{{Dynamic[
        Grid[{{Control@{{menuOndasEstac, 1, 
              "Stationary waves:"}, {1 -> "Two nodes", 
              2 -> "Node and antinode", 3 -> "Two antinodes"}, 
             ControlType -> RadioButtonBar}}, {Control@{{harmDispon, 
              1, "Harmonics:"}, Dynamic@harmonics, 
             ControlType -> PopupMenu}, 
           Control@{{mostrOndasOrig, True, 
              "Show original waves:"}, {True, False}, 
             ControlType -> Checkbox}}}]]}}, Alignment -> Left, 
     ItemSize -> {60, 1}, Background -> GrayLevel[0.92]]}, 
  Background -> GrayLevel[0.92]], Initialization :> (menuInterf = 1;
   harmonics = Range[10];)]

Regards,

Neil

Dear Neil, I liked very much your suggestion, which is a combination of MenuView and Spacer. This is new for me and I appreciated very much your help. Thanks a lot, Anderson

Thanks Neil, it looks very good. I showed the simplest solution to the problem, but the design of the menu remains an open question for me.

Hi Neil, It looks good. You should check how this works with the waves.

Hi Alexander, Thanks for your help too. I believe the solution proposed by Neil, which I didn't find in my search through the internet, will be very useful for many other Mathematica users. Best Regards, Anderson

I'm glad I could help.

Alexander -- good catch picking up the problem with the "If[]". I did not notice that issue when I first looked at the problem. Sorry I mixed your name up with Anderson in my post -- I guess all "A" names look alike!

The one thing I could not quickly figure out was how to get the backgrounds to blend. If you leave off the background specifications in the grid, everything is white except for the Manipulate dialog box -- which actually looks Ok. Another option is to use the TabView instead of MenuView and delete all the gray backgrounds. (and fixed the spacing problem caused by the other Grid[{}] that I just noticed)

Manipulate["Hi",

 TabView[{"Menu 1" -> 
    Grid[{{Dynamic[
        Grid[{{Control@{{menuInterf, 1, 
              "Operation mode:"}, {1 -> "Manual", 2 -> "Automatic"}, 
             ControlType -> RadioButtonBar}}}]]}, {Dynamic[
        If[menuInterf == 1, 
         Grid[{{Control@{{quantWaves, 1, "Number of waves:"}, {1, 2}, 
              ControlType -> RadioButtonBar}, 
            If[quantWaves == 1, Invisible[xxxx], Spacer[{30, 12}]], 
            Control@{{showSumWaves, False, 
               "Show sum of waves:"}, {True, False}, 
              ControlType -> Checkbox}}}], Spacer[{12, 20}]]]}}, 
     Alignment -> Left, ItemSize -> {60, 1}], 
   "Menu 2" -> 
    Grid[{{Dynamic[
        Grid[{{Control@{{menuOndasEstac, 1, 
              "Stationary waves:"}, {1 -> "Two nodes", 
              2 -> "Node and antinode", 3 -> "Two antinodes"}, 
             ControlType -> RadioButtonBar}}, {Control@{{harmDispon, 
              1, "Harmonics:"}, Dynamic@harmonics, 
             ControlType -> PopupMenu}, 
           Control@{{mostrOndasOrig, True, 
              "Show original waves:"}, {True, False}, 
             ControlType -> Checkbox}}}]]}}, Alignment -> Left, 
     ItemSize -> {60, 1}]}], Initialization :> (menuInterf = 1;
   harmonics = Range[10];)]

Background color is not too much important for me, although it can be for many people. Another thing is that when I corrected my code by using your suggestion I changed MenuView by TabView, which I found to be more interesting and professional. Thanks again.

Thanks Neil, it looks very good. I showed the simplest solution to the problem, but the design of the menu remains an open question for me.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract