22
$\begingroup$

Background: In the Mathematica tutorial 'Dynamic Interactivity' I read that there is a way of developing GUIs in Mathematica that do not use Manipulate. I want to investigate this further.

Question: What is the equivalent of Manipulate[i,{i,1,5,1}] in 'lower-level' Mathematica functions?

$\endgroup$

2 Answers 2

28
$\begingroup$

Start from

{Slider[Dynamic[x], {1, 5, 1}], Dynamic[x]}

enter image description here

Next localize control variable:

DynamicModule[{x}, {Slider[Dynamic[x], {1, 5, 1}], Dynamic[x]}]

enter image description here

And add some interface elements:

Panel@DynamicModule[{x},  Column[{Slider[Dynamic[x], 
{1, 5, 1}], Panel[Dynamic[x], ImageSize -> 200]}]]

enter image description here

Add even more

Panel@DynamicModule[{x},   Column[{Row[{"x", Spacer[10], 
Animator[Dynamic[x], {1, 5, 1}, AnimationRunning -> False, 
ImageSize -> Small]}], Panel[Dynamic[x], ImageSize -> 235]}]]

enter image description here

$\endgroup$
3
  • 3
    $\begingroup$ Good idea to build-up your answer like that. $\endgroup$ Apr 29, 2012 at 8:20
  • $\begingroup$ +1, though there is one thing it's missing: the Bookmarks/Autorun icon from the upper right corner. I have no idea how to replicate that. $\endgroup$ Apr 29, 2012 at 13:05
  • $\begingroup$ +1 I guess replicating SaveDefinitions and "Paste Snapshot" would be difficult as well? $\endgroup$
    – Ajasja
    May 24, 2012 at 19:34
10
$\begingroup$

I realize this isn't what you meant by "lower level" but nevertheless viewing the Cell Expression for various kinds of output can be interesting and informative. Based on observing that expression it is possible to craft this:

DynamicBox[
  Manipulate`ManipulateBoxes[1, StandardForm, 
   "Variables" :> {a$$ = 0},
   "ControllerVariables" :> {Hold[a$$, 0]}, 
   "OtherVariables" :> {}, 
   "Body" :> Plot[Sin[x (1 + a$$ x)], {x, 0, 6}], 
   "Specifications" :> {{a$$, 0, 2}},
   "Options" :> {}, 
   "DefaultOptions" :> {}
  ]
] // ToExpression

Mathematica graphics

Of course direct use like this isn't advisable because I have stripped out all localization etc. for this example that is normally generated automatically.


As a further point of curiosity, if you want to see the very low level Box expressions, leave off DynamicBox and ToExpression from the example above to reveal this:

PaneBox[PanelBox[
  DynamicWrapperBox[
   GridBox[{{ItemBox[
       ItemBox[StyleBox[
         GridBox[{{TagBox["a", HoldForm], 
            TagBox[PaneBox[
              DynamicModuleBox[{Typeset`open$$ = False, 
                Typeset`paused$$ = 0, Typeset`rate$$ = Automatic, 
                Typeset`dir$$ = Forward}, 
               StyleBox[
                DynamicBox[
                 FEPrivate`FrontEndResource["FEExpressions", 
                   "Manipulator04"][Dynamic[a$$], 
                  Dynamic[a$$], {0, 2}, Medium, Small, Automatic, 
                  True, Automatic, False, True, True, All, False, {}, 
                  Dynamic[Typeset`open$$], Dynamic[Typeset`paused$$], 
                  Dynamic[Typeset`rate$$], Dynamic[Typeset`dir$$]]], 
                DynamicUpdating -> True], 
               DynamicModuleValues -> Automatic], ImageMargins -> 0, 
              BaselinePosition -> Baseline], 
             Manipulate`InterpretManipulator[
              Dynamic[a$$], {0, 2}, {ContinuousAction -> True, 
               AutoAction -> False}]]}}, AutoDelete -> False, 
          GridBoxItemSize -> {"Columns" -> {{Automatic}}, 
            "Rows" -> {{Automatic}}}, 
          ColumnAlignments -> {Right, Left}], "ManipulateLabel", 
         StripOnInput -> False], Alignment -> {Automatic, Inherited}, 
        StripOnInput -> False], Background -> None, 
       StripOnInput -> False]}, {ItemBox[
       TagBox[StyleBox[PaneBox[DynamicBox[ToBoxes[Refresh[\!\(\*
TagBox[
RowBox[{"Plot", "[", 
RowBox[{
RowBox[{"Sin", "[", 
RowBox[{"x", " ", 
RowBox[{"(", 
RowBox[{"1", "+", 
RowBox[{"a$$", " ", "x"}]}], ")"}]}], "]"}], ",", 
RowBox[{"{", 
RowBox[{"x", ",", "0", ",", "6"}], "}"}]}], "]"}],
Identity,
Editable->True,
Selectable->True]\), TrackedSymbols -> Full], StandardForm], 
           SynchronousUpdating -> Automatic], ImageMargins -> 10], 
         Deployed -> False, ScriptLevel -> 0, 
         GraphicsBoxOptions -> {PreserveImageOptions -> True}, 
         Graphics3DBoxOptions -> {PreserveImageOptions -> True}, 
         StripOnInput -> False], Identity, Selectable -> False, 
        Editable -> False], Alignment -> {Left, Center}, 
       Background -> GrayLevel[1], Frame -> 1, 
       FrameStyle -> GrayLevel[0, 0.2], ItemSize -> Automatic, 
       StripOnInput -> False]}}, AutoDelete -> False, 
    GridBoxItemSize -> {"Columns" -> {{Automatic}}, 
      "Rows" -> {{Automatic}}}, ColumnAlignments -> Left, 
    GridFrame -> False, GridFrameMargins -> 1, RowSpacings -> 2, 
    RowAlignments -> Top], 
   If[CurrentValue["SelectionOver"], 
    Manipulate`Dump`ReadControllerState[(Manipulate`Dump`updateOneVar[\
#1, CurrentValue["PreviousFormatTime"], 
         CurrentValue[
          "CurrentFormatTime"]] &) /@ {Manipulate`Dump`controllerLink[
        a$$, "X1", If["DefaultAbsolute", True, "JB1"], False, {0, 2}, 
        1.]}, CurrentValue[{"ControllerData", {"Gamepad", "Joystick", 
        "Multi-Axis Controller"}}], {}]]], DefaultBaseStyle -> {}, 
  FrameMargins -> {{5, 5}, {5, 5}}], ImageMargins -> 0, 
 BaselinePosition -> Automatic]

I am rather glad we don't have to do "low level" FrontEnd programming very often!

$\endgroup$

Your Answer

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

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