Can TogglerBar be used as multiple CheckBox in Mathematica?
Asked Answered
A

3

3

Would it be possible to have a TogglerBar instead of the 2 Check Box to show or not the different Shapes.

With Green & Red written in each Button of the TogglerBar ?

Manipulate[
Graphics[{If[thePink, {Pink, Disk[{5, 5}, 3]}], 
If[theGreen, {Green, Disk[{15, 2}, 1]}]}, 
PlotRange -> {{0, 20}, {0, 10}}], {{thePink, True, 
Style["Pink", Black, Bold, 12]}, {True, False}}, {{theGreen, True, 
Style["Green", Black, Bold, 12]}, {True, False}}]

enter image description here

The actual Manipulate object I am trying to adjust can be found there : http://www.laeh500.com/LAEH/COG.html The purpose being to replace the CheckBox by a nice TogglerBar.

Aberrant answered 9/6, 2011 at 20:59 Comment(0)
B
3

Like this?

Manipulate[
 Graphics[{
   {White, Circle[{5, 5}, r]},  (* For Mma 7 compatibility*) 
   If[MemberQ[color, "Red"],   {Pink, Disk[{5, 5}, r]}],
   If[MemberQ[color, "Green"], {Green, Disk[{4, 2}, r]}]},
 PlotRange -> {{0, 20}, {0, 10}}],
 {{r, 1, "Radius"}, 1, 5, 1, ControlType -> Setter},
 {{color, "Red", "Color"}, {"Red", "Green"}, ControlType -> TogglerBar}, 
LabelStyle -> Large]

enter image description here

Edit

Answering your comment, I think your notebook could benefit from a template like this one:

Manipulate[
 Graphics[
  {
   {White, Circle[{5, 5}, r]},(* For Mma 7 compatibility*) 
   If[MemberQ[whatToDisplay, "Circle"], {Red,   Circle   [{5, 5}, r]}],
   If[MemberQ[whatToDisplay, "Square"], {Blue,  Rectangle[{5, 5}, {r, r}]}],
   If[MemberQ[whatToDisplay, "Other"],  {Black, Line     [Tuples[{3, 4}, 2]]}],
  },
 PlotRange -> {{0, 20}, {0, 10}}
 ], 
  (* Controls follow *)
  {{r, 1,  Style["Radius", Black, Bold, 12]}, 1, 5, 1, ControlType     -> Slider
                                                     , ControlPlacement-> Top
  },  
  Control@{{whatToDisplay, True, Style["What", Black, Bold, 12]}, 
           {"Circle", "Square", "Other"}, 
           ControlType      -> TogglerBar,
           Appearance       -> "Vertical",
           ControlPlacement -> Left
  }
]

enter image description here

Bigoted answered 9/6, 2011 at 21:19 Comment(13)
@Belisarius, I want to be able to select both. I would actually implement that to show or hide different visual component of my analysis. Please let me know if you would have an alternative to the one below. Thank You.Aberrant
@ Belisarius, I have upload my notebook to the below link. If you have a minute, do you think I have hope to apply this to all my If statement to hvae a nice single bar instead of all the CheckBox ? Run all the Notebook should be all that is necessary to display the Object. thank You once again for you attention. laeh500.com/LAEH/COG.htmlAberrant
@Belisarius, this is just perfect. I hope my codes were not to ugly to your expert eye ;)Aberrant
@Belisarius. Could we adjust the the font inside ? If you think it is worth another post for the interest of the forum, I shall ask the question.Aberrant
@Aberrant Your code is OK. Sometimes you forget to use the functional constructs, but that is normal while you're learning. BTW ... what is a COG?Bigoted
@Belisarius, Center of Gravity,Aberrant
@Aberrant Oh my! And I was a physicist!Bigoted
@Belisarius, We can hardly reckon familiar things out of the context we are usually expecting them in ;)Aberrant
@Aberrant That reminds me of a Groucho Marx's joke that went something like "I met my wife at the hotel, but I didn't recognize her because she was wearing a wedding dress"Bigoted
@Belisarius, that is really funny !Aberrant
@Aberrant I've read in your profile Ph.D. Student in Cognition and I thought COG was related to cognition. Really funny!Bigoted
belisarius, the first block gives me errors on mma7. "Null is not a Graphics primitive or directive." etc...Accommodation
@Mr. Edited, but can't test it. Check now ... or upgrade! :)Bigoted
R
3

How about this?

Manipulate[
 Show[Graphics[myObject], 
  PlotRange -> {{0, 20}, {0, 10}}], {{myObject, {},""}, {{Pink, 
     Disk[{5, 5}, 3]} -> 
    Style["Pink", Black, Bold, 12], {Green, Disk[{15, 2}, 1]} -> 
    Style["Green", Black, Bold, 12]}}, ControlType -> TogglerBar]
Redo answered 9/6, 2011 at 21:34 Comment(3)
Thank You !, any way to hide the "u" ?Aberrant
@Aberrant "u" was displaying as the label for the variable; the label is an option for any of the dynamic variables. I changed "u" to myObject and gave it an empty string: "", for the label option. The empty string will not display although you can put more descriptive names instead. As an aside note that Show isn't essential in this case as Graphics could use the plot range. But Show might come in useful for future extensions of this example.Redo
Thank You ! You will find in the edited question the source to see the "real problem" if you care/have time.Aberrant
T
2

How about

Manipulate[
Graphics[{#} & /@ x,
    PlotRange -> {{0, 20}, {0, 10}}],
{{x, {}, "Colour"},
{{Pink, Disk[{5, 5}, 3]} \[Rule] "Pink",
{Green, Disk[{15, 2}, 1]} \[Rule] "Green"},
ControlType -> TogglerBar}]

it's ugly and inelegant, though! Dynamic manipulation is not my favourite use of Mathematica, so this is sort of trial and error for me too...

EDIT: Slightly less ugly now... EDIT2: Added a label

Tifanie answered 9/6, 2011 at 21:21 Comment(4)
Thank You. However I must say I don`t understand how it works yet and for I need to implement it with a quite complex Manipulate. I will try to Edit my question to show the problem :) I leave it unanswered yet to see if others have ideas !Aberrant
@Aberrant no problem. note that I've added a label now (I saw you were asking how to do it). maybe give more details about what you don't understand (or what your real problem is).Tifanie
You will find my notebook with only the relevant Manipulate Object left open. Do you think I have hope to apply this to all my If statement to have a nice single bar instead of all the CheckBox ? Command A Shift Enter should be all that is necessary to see the object ! Many thanks for your attention ! laeh500.com/LAEH/COG.html Many thanks for any help you can provide !Aberrant
@Aberrant should not be a problem, but it is late here and I'll quit. if nobody's done it by tomorrow, I will :)Tifanie

© 2022 - 2024 — McMap. All rights reserved.