Tag Info

Hot answers tagged

5

Update. Thanks to Eldo, Dynamic is needed outside the InputField. DynamicModule[{a = 1, b = 20, fuc = "1"}, Deploy[Style[Panel[Grid[Transpose[ { {"Input Format", "Value"}, {PopupMenu[Dynamic[fuc], {"1", "2"}], Dynamic@InputField[ If[fuc == "1", a, b], Number, Enabled -> Dynamic[fuc == "1"] ...


4

shape1 := Graphics[{#, Circle[{0, 0}, 1.5], Disk[]}, ImageSize -> 10] &; shape2 := Graphics[{Lighter@#, Disk[]}, ImageSize -> 10] &; ClearAll[lOF]; lOF[nOfOverlays_, colors_List, opts : OptionsPattern[]] := DynamicModule[{layer = 1, pts = ConstantArray[{{100, 100}, {700, 700}}, nOfOverlays], col = ...


4

Edit: This is a rewrite. The original answer was more or less an extended comment containing some seemingly relevant clues. I've tracked down two probable issues, each related to a system variable, and there may be others. At least in either case, the crashing can be triggered or prevented.* It turns out that Dynamic@RegionPlot[..] depends on the ...


4

Modifying last example in Manipulate>Neat Examples (also the second example in this answer): Manipulate[ ArrayPlot[Take[data, n, n]], {{data, RandomInteger[{0, 1}, {20, 20}]}, ControlType -> None}, {{n, 5}, 1, 20, 1}, Dynamic[ Panel[Grid[Outer[Checkbox[Dynamic[data[[#1, #2]]], {0, 1}] &, Range[n], Range[n]]]]]]


3

Fundamental problem Pardon me if I miss some points of your question as I didn't attempt to understand what your code is intended to do, because I think I understand what the problem is from the title alone. Please consider: SetAttributes[f, {HoldFirst, Listable}]; f[x_] := foo[x] f[{1, 2, 3}] {foo[1], foo[2], foo[3]} bar = {1, 2, 3}; f[bar] ...


3

The x and y of the ContourPlot are interfering with the x and y inside of Dynamic. If you use for example ContourPlot[Total[Log[Clip[b-a.{x2,y2},{10^-10,\[Infinity]}]]],{x2,-2,2},{y2,-2,2},PlotRange->{-10,0}] it'll not crash. I guess this shouldn't be necessary.


3

When a Symbol is "tracked" it means that when its value changes the Dynamic expression is refreshed, therefore your input updates as fast as possible because every refresh changes the value of t which causes a refresh which... you get the picture. Compare: Clear[t]; t = 1; Dynamic[Refresh[t++, UpdateInterval -> 1, TrackedSymbols -> {}]]


3

Something like that? list = Range[0, 9]; DynamicModule[{nr, val}, Column[{ Dynamic@list, Dynamic@list[[ nr]], Slider[Dynamic@nr, {1, 10, 1}], Slider[Dynamic[list[[ nr]]], {0, 10, 1}] }] ] Manipulate version: list = Range[0, 9]; Manipulate[ Column[{list, list[[nr]]}], Column[{ Control[{{nr, 1}, 1, 10, 1}], ...


3

Here are two ways. One of them may be what the OP alluded to in a comment; in any case, I'll give a complete solution below. First, using If inside one InputField: The trick here is to use the second argument of Dynamic. DynamicModule[{a = 1, b = 20, fuc = "1"}, Deploy[Style[ Panel[Grid[ Transpose[{{"Input Format", "Value"}, ...


2

EDIT: I decided this was simple enough a question that this should have more controls to make it an answer and not a comment. Manipulate[Pane[Grid[Partition[ConstantArray[1, {elems}], cols, cols, 1, ""], Frame -> All], {200, 100}, Scrollbars -> {horizScroll, vertScroll}], {{elems, 5, "Elements"}, 5, 100, 1}, {{cols, 4, "Columns"}, 4, 20, 1}, ...


2

simple version With a single codeline, ColorData["Atoms", "Panel"], can be transformed in a click panel for ElementData[]. {ColorData["Atoms", "Panel"] // ReplaceAll[#, RuleDelayed[ "MouseClicked", $_] :> (RuleDelayed["MouseClicked", atomClicked = Part[RuleDelayed["MouseClicked", $], 2, 2, 2, 1, 1, 1]])] &, Dynamic[atomClicked, Initialization :> ...


1

The more general solution to this problem is to make use of the Option SynchronousUpdating->False: pts=Flatten[Table[Through[{Cos,Sin}[\[Alpha]]] r,{\[Alpha],0.,360 \[Degree]-10^-5,60 \[Degree]},{r,1,2}],1]; LocatorPane[Dynamic[pts], Dynamic[Show[ Graphics[{Arrow /@ Partition[pts, 2]}], {a, b} = Transpose[Map[Module[{p1, p2, d}, {p1, p2} = #; ...


1

I classify your question as "Serious" thus, here is my answer. In many cases I have found myself in situations where a "canonical solution" does not seem to exist for a given problem found while creating Mathematica solutions. In those cases I tend to create a reasonable enough solution. When I read your question I remembered that a couple of years ago I ...


1

From tutorial/InteractiveGraphicsPalette you can see that quite a few of the lowercase keys are used by DrawingTools which becomes active once the cursor focus is on the graphics. So, the easiest work-around is to use uppercase letters in your EventHandler as suggested by pjc42. When the first argument of EventHandler does not contain a graphics object, ...


1

another idea but not an answer... DynamicModule[{keyList = {}, pts = {}, input = Null}, EventHandler[ {LocatorPane[Dynamic[pts], Graphics[Circle[], ImageSize -> 500], LocatorAutoCreate -> True, Appearance -> {Graphics[{Red, Disk[]}, ImageSize -> 10], Graphics[{Blue, Disk[]}, ImageSize -> 10]} (*LocatorPane**)], ...


1

This is only a partial answer but may help. See here for related case, it is probable that KeyDown "a" is reserved like "c". This does not work: DynamicModule[{someList = {}}, EventHandler[Graphics[{Blue, Disk[]}, ImageSize -> 100], {{"KeyDown", "a"} :> (AppendTo[someList, 1]; Print[someList])}]] (** doesn't work **) But changing "a" to ...


1

Refresh only sets a limit on how long expression can go without being updated. To keep t form being updated more often add a pause. t = 1; Dynamic[Refresh[Pause[1]; t++, UpdateInterval -> 1, TrackedSymbols :> {t}]] or do what Mr.Wizard indicated, which is better. But this sort of thing is best done by higher level constructs such as Clock or ...


1

I believe the jump in value of asd happens because you're dragging the indicator with the mouse when the range is reset. Here is a way that does what you want, I think. It interrupts the mouse-dragging by creating a new Slider when the boundary is reached. {Dynamic@asd, Dynamic@Slider[Dynamic[asd], Which[asd < 10, {1, 10}, asd >= 10, {9, 50, ...


1

Dynamic is sometimes too aggressive for some purposes. You need to make sure Dynamic updates only when you are ready for new results. Besides, to ensure that Dynamic will have enough time to process your request it is sometimes a good idea to use SynchronousUpdating option. In the solotuion below you will see that instead of calculating the menu options ...


1

Edit: In order to set initial values in a dynamical system one has to use DynamicModule. Anyway, if you now change slightly your code in the following way: Slider[Dynamic[n], {0, 5}] DynamicModule[{p1 = 200}, Dynamic[Plot[n (x - n)^2, {x, 0, 5}, ImageSize -> Dynamic[p1]]]] the image should remember its size.


1

I'd say it's a bug worth reporting. In the meantime you can work around it using Refresh. Perhaps something like the following Unprotect[RegionNearestFunction]; Module[{inside}, rnf : _RegionNearestFunction[___] /; ! TrueQ[inside] := Block[{inside = True}, Refresh[rnf, None]] ] Protect[RegionNearestFunction];


1

One potential solution to this would be using PreemptProtect to prevent interruption. For the example from the main question, PreemptProtect@Block[{x}, Pause[5]]


1

Finally, I discovered that the combined program works fine as long as the dragging just begin from the point close to the node (not right on the top of it). Thanks.



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