7
$\begingroup$

I understand how I can select a bookmark from the "+" menu of a Manipulate. Is there a way to select a bookmark from an arbitrary control, or define a control that implements bookmark functionality?

For example, if I have something like

Manipulate[{x, y, z},
 {x, 0, 10}, {y, 0, 10}, {z, 0, 10},
 Bookmarks -> {"Center" :> {x = 5, y = 5, z = 5},"Zero" :> {x = 0, y = 0, z = 0}}]

Can I add a control that does the same thing as selecting the bookmark from the menu? For example, can I add something similar to {preset, {"Center", "Zero"}}, to create something that looks like

enter image description here

where choosing one of the setters performs assignments to collections of Manipulate variables?

Specifically: is there

  1. a way to implement bookmark-like functionality by specifying a control that sets several Manipulate variables at once; is there
  2. a way to explicitly select a bookmark from an arbitrary control (e.g. is there something like an"SelectBookmark[bookmark]")?

I'd have thought that

Manipulate[{x, y, z}, {x, 0, 10}, {y, 0, 10}, {z, 0, 10},
 {{preset, 
   Which[# === "Center", (x = 5; y = 5; z = 5),
         # === "Zero",   (x = 0; y = 0; z = 0)] &}, {"Center", "Zero"}}]

would at least achieve (1), but it has no apparent effect; I see no way to do (2).

$\endgroup$
2
  • 2
    $\begingroup$ This needs some more thought but the dynamic values of the bookmarks can be displayed: Manipulate[Column[{Dynamic@Typeset`bookmarkList,{x, y, z}}],{x, 0, 10},{y, 0, 10},{z, 0, 10},Bookmarks -> (opts = {"Center" :> {x = 5, y = 5, z = 5},"Zero" :> {x = 0, y = 0, z = 0}})] so the task is how to convert that information into a dynamic setterbar. $\endgroup$ Dec 7, 2012 at 22:23
  • $\begingroup$ @NasserM.Abbasi: Yes, that would be relevant to (1). I've extended the question accordingly. $\endgroup$
    – orome
    Dec 8, 2012 at 17:47

1 Answer 1

2
$\begingroup$

Will this work for you? (I did this with radio button bar. I like to do this myself with pulldown menu. But the idea is the same)

Manipulate[
 {x, y, z},

 (*controls*)
 {x, 0, 10},
 {y, 0, 10},
 {z, 0, 10},

 (*bookmark control*)
 Grid[{
   {Style["bookmarks", Bold],
    RadioButtonBar[Dynamic[bookMark, {bookMark = #;

        Which[
         bookMark == "center", x = 5; y = 5; z = 5,
         bookMark == "zero", x = 0; y = 0; z = 0
         ]

        } &], {"center", "zero"}, Appearance -> "Horizontal"]

    }}, Spacings -> {.5, 1}, Frame -> True, 
  FrameStyle -> Directive[Thickness[.005], Gray]],

 {{bookMark, "zero"}, None}     
 ]

enter image description here

$\endgroup$
3
  • $\begingroup$ Why doesn't my approach to (1) work? In particular, I'm confused about the difference between {{preset {preset = #; Which[preset === "Center", (x = 5; y = 5; z = 5), preset === "Zero", (x = 0; y = 0; z = 0)]} &} and Dynamic[bookMark, {bookMark = #; Which[bookMark == "center", x = 5; y = 5; z = 5, bookMark == "zero", x = 0; y = 0; z = 0]} &], {"center", "zero"}]. $\endgroup$
    – orome
    Dec 8, 2012 at 19:02
  • $\begingroup$ I've suggested an edit to a form that parallels the form in the question, to focus on this aspect. I'd have thought that the approach I tried to do (1) in the question would have had the same effect, since the documentation for Manipulate says: "In the form {u,func}, Dynamic[u] is given as the first argument to func."; but there's something about either Manipulate or Dynamic I'm not grasping here. $\endgroup$
    – orome
    Dec 8, 2012 at 20:45
  • $\begingroup$ What happens when you add another bookmark after clicking "+"? I assumed what he was after was something that dynamically reads stored bookmarks? $\endgroup$ Dec 9, 2012 at 0:35

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.