Hot answers tagged

13

This? {Slider[Dynamic[x], {0, 10}], Slider[Dynamic[2 x, Set[x, #/2] &], {0, 20}]} The documentation explains, under More Information, that "Dynamic[expr,f] makes interactive operations not change expr except by virtue of the evaluation of f[val,expr]. ". Otherwise, Mathematica attempts to assign a value to 2x.


12

If you look at underlying code: ListAnimate[Table[Plot[Sin[n x], {x, 0, 10}], {n, 25}]] // InputForm at the end you'll find: which leads to a trick: ListAnimate[Table[Plot[Sin[n x], {x, 0, 10}], {n, 25}]] /. HoldPattern[AppearanceElements -> _] -> (AppearanceElements -> None) In the spirit of @Mr.Wizard comment you can also do something ...


11

CurrentValue["ControlsFontFamily"] (* "Segoe UI" on Version 9 / Windows 8 *) (* "Lucida Grande" on OS X 10.6.8 -- thanks: m_goldberg *) (* "Bitstream Vera Sans" on Fedora 20 -- thanks Oska *) CurrentValue["ControlsFontSize"] (* 12 on Version 9 / Windows 8 *) Style[StringJoin[CharacterRange["a", "z"]], FontFamily :> CurrentValue["ControlsFontFamily"], ...


10

I am not sure why you can't just use Grid? Manipulate[Plot[Sin[x], {x, -lim, lim}], Grid[{ {Control[{{lim, Pi, "limit"}, Pi/10, 2 Pi, Pi/10, ImageSize -> Tiny}], Button["A", ImageSize -> 100]}, {Button["B", ImageSize -> 100], Button["C", ImageSize -> 100]}, {Button["D", ImageSize -> 100], Button["E", ImageSize -> 100]} }...


10

I want to give an answer using SyntaxQ and SyntaxLength. SyntaxQ takes a string and returns True, when the string has correct Mathematica syntax. On the other hand SyntaxLength returns an integer which shows up to what character the string is correct syntax. If the integer is larger than the length of the input string it indicates, that more input is needed. ...


10

You have to study the documentation carefully, but I agree that help-pages like the one of Manipulate are very densely packed with information. In the Details and Options section you find how to set options for controls: {{u,...},...,opts} control with particular options The non-obvious part is, that you have to set the ControlType as well to make ...


10

Dynamic has this build into it. You can take advantage of the Dynamic second and third arguments. The second argument of evaluate as the dynamic is being updated. The third argument is evaluated when the mouse is released. Which is what you want. To illustrate, here is an example, where f[r] and g[r] are inside the arguments of the slider itself. This is ...


9

The answer is that yes, you can affect the appearance of components of a control but the problem in this case is that your list of appearances appearances = {"DialogBox", "Palette", "FramedPalette", "Frameless"}; are only valid Button appearances and that is why they have no effect of ButtonBar or TabView. When you use valid appearances it works fine: ...


9

ControlActive is useful for this purpose: DynamicModule[{r = 1, old = 1} , Grid[ { {Slider[Dynamic[r]], SpanFromLeft} , {Dynamic[f[r]], Dynamic[g[ControlActive[r, old = r]; old]]} } ] ] The variable old has been introduced to hold the "old" value of r. The key expression is ControlActive[r, old = r]; old, which always returns the value of ...


8

SetterBar[Dynamic[buttonValue], {"1", "2", "3", "dsf"}, BaseStyle -> Red, Alignment -> {Center, Center}, ImageSize -> {100, 50}]


8

You can always create your own custom controls. This is a lot of work, but it also gives you unlimited flexibility. You can even create completely new kinds of control. Scroll down to the last section here to see an example. If you're aiming for a custom TabView-like control, I'd start with PaneSelector. Here's a primitive example (just a start, not ...


7

You can use the Style setting ControlRendering to display controls in their generic form: Rotate[Style[Button["Toto", Null], ControlsRendering -> "Generic"], 0] If you don't see the bottom line you need to set the Buttons ImageMargins: Rotate[Style[Button["Toto", Null, ImageMargins -> 1], ControlsRendering -> "Generic"], 0.0]


7

If I use the option Method->"Queued" within Button, this works Button["Export", Export[SystemDialogInput["FileSave"], Plot[Cos[x], {x, 0, Pi}], "PDF"], Method -> "Queued"] Otherwise, "Preemptive" will be the default, making it possible that not enough time is allocated for the Button action to complete. See the reference docs on ...


7

Perhaps this? Manipulate[ {names, slide, setter, cases}, Dynamic@Switch[cases, "custom", Control[{{names, True}, {True, False}}], "a", Control[{{slide, 0}, 0, 1}], "b", Control[{{setter, "das"}, {"das", "der", "die"}}]], {{cases, "custom"}, {"custom", "a", "b"}}] The variables seem to get localized properly even though the syntax ...


7

One difficulty in using Manipulate is that it rewrites your code for you in ways that are not clearly explained in the documentation. The thinking is that this rewriting achieves the dynamic interactions described in the documentation without burdening the programmer with some of the tedious details involved. For instance, expressions that contain ...


7

There are a lot of different ways to do this. My current favorite is Manipulate[{a, b}, {a, 1, 10}, {b, 1, 10, TrackingFunction -> (b = #; a = 10; &)}]


7

An adaption of this answer for an ActionMenu and to your styling: assnMenuK[slowF_, a_Association, title_: "Choose"] := DynamicModule[{done = False, lastSelection = ""}, Grid[{{ ActionMenu[title, KeyValueMap[#2 :> (lastSelection = #2; done = "working"; slowF[#1]; done = True) &, a], Method -> "Queued"], Dynamic@Style[...


6

DynamicModule[{n = 3, prefTable = ConstantArray[0, {3, 20, 7}], lastName = ConstantArray["", {3}], firstName = ConstantArray["", {3}], ws = ConstantArray[0, {3}], wsAmount = ConstantArray[Null, {3}], wkndPref = ConstantArray[Null, {3}], tabLabel = Array["Worker " <> ToString[#] &, {3}], hours = DateString[DatePlus[{2012, 1, 1, 7, 0, ...


6

One way to achieve this would be to define a "clipping" function that applies the constraints to the points: clip[pts_] := ReplacePart[pts /. {x_, y_} /; y > x :> {x, x}, {-1, 1} -> 1] We can then invoke that function whenever the set of points is changed. To use this strategy, it is convenient to use a single locator control for all points: ...


6

Computing Processes are the number of main kernels you can use at the same time. Therefore, you can have on the same computer two Mathematica sessions running and while one computation is running, you can use the other one to do something else. It has nothing to do with your license which is valid for only one computer. The probably easiest method if you ...


6

I think you've got to take over placement manually. First declare the variable setter with no control (None). Next add a SetterBar. Put this inside a Pane so you can control placement. The ImageSize of the Pane needs to be determined by hand. You can use ImageSize -> Full, which makes it fill the width of the notebook window -- perhaps desirable or ...


6

This is what I find more intuitive: circle[] := DynamicModule[{a = {0, 0}, b = {1, 0}, r = 1, w}, { Dynamic@Circle[a, r], Locator[Dynamic[a, {(w = b - a) &, (a = #; b = a + w) &, None}]], Locator[Dynamic[b, (b = #; r = Norm[b - a]) &]] }] Graphics[circle[], Frame -> True, PlotRange -> 2] And this is what fits well OP'...


6

I do nor know how to implement what you want to do in a Manipulate expression using locators, because I don't know how to handle mouse events in a Manipulate expression. However, if you are willing to accept an answer using EventHandler, the behavior you ask for isn't very difficult to implement. With[{δ = .2}, DynamicModule[{p1 = {0, 0}, p2 = {2, 2}, ...


6

Less ambitious: addbutton[manipulate_] := With[{box = ToBoxes@manipulate}, With[{proc = Cases[box, HoldPattern["Variables" :> _], ∞]}, With[{button = Button["Reset", CompoundExpression["Variables"] /. proc]}, Composition[ToExpression, BoxData][ box /. {("Body" :> x_) :> "Body" :> Column[{button, x}]}]]]] addbutton@Manipulate[...


6

I do this all the time, but use small buttons next to the slider. This is handy when one wants to jump to specific value, and sometimes it is hard to get the slider to go there exactly without few hits and misses and one ends up opening the slider using "+" and typing in the value in the small window which is not very efficient sometimes. Here is an example ...


6

There's no way to do this that conforms fully to UI guidelines (at least not for OS X). For example, your "disabled" items will still highlight as you hover over them and will still react to selection (thought they will do nothing). This is as close as you can get: Manipulate[ {filter, list} , {{filter, 1, "Filter:"}, {1, 2, 3, 4, 5, 6}, ControlType -&...


6

Something like this? Manipulate[ Plot[Sin[x] + a, {x, -3, 3}], OpenerView[{"open to control ", Control[{{a, 1, "a"}, 0, 10, 1}]}] ]


6

Manipulate[None, Grid[{ {Dynamic@ListPlot[{a, b, c, d}], Grid[{ {Style["a and b in a column on the right", Orange, Bold]}, {Control[{{a, 1, "a->"}, 0, 5, Appearance -> "Open"}]}, {Control[{{b, 1, "b->"}, 0, 5, Appearance -> "Open"}]} }], Grid[{ {Style["c and d in a column on the more right", Blue, Bold]},...


6

I'm not sure about all the arguments, but maybe this will get you started: Clear[MultiSlider]; MultiSlider[Dynamic[xs_], {st_, end_}] := LocatorPane[Dynamic[xs], Graphics[{LightGray, Thickness[0.015], Line[{{st, 0}, {end, 0}}]}], {{st, 0}, {end, 0}}] Manipulate[ x, {{x, Table[{2 i, 0}, {i, 5}]}, 0, 12, MultiSlider[##] &}] You can constrain ...


6

It seems that Control is just a wrapper for Manipulate`Control, and that function expects a Symbol as its first argument: Control[]; (*preload*) ClearAttributes[Manipulate`Control, {Protected, ReadProtected}] Block[{$Context = "Manipulate`Dump`"}, Definition[Manipulate`Control] // Print; ] Manipulate`Control[var_, Manipulate`Dump`opts___Rule, ...



Only top voted, non community-wiki answers of a minimum length are eligible