Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 26 down vote accepted

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

share|improve this answer
3  
Good idea to build-up your answer like that. –  Sjoerd C. de Vries Apr 29 '12 at 8:20
    
+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. –  István Zachar Apr 29 '12 at 13:05
    
+1 I guess replicating SaveDefinitions and "Paste Snapshot" would be difficult as well? –  Ajasja May 24 '12 at 19:34

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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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