Hot answers tagged

9

I recently needed to do something like this. Here's a simplified version of what I came up with: DynamicModule[{elem = "Hydrogen"}, Panel[Row[{(ColorData["Atoms", "Panel"] /. HoldPattern["MouseClicked" :> rhs_] :> ("MouseClicked" :> (elem = CanonicalName[ElementData[Cases[Unevaluated[rhs], _Rule, ∞][[1, ...


8

How can I constrain the locator to stay within the region defined by RegionPlot? You can check if locator's coordinates fulfill the condition defining your region. It can be done with the second argument of Dynamic if you introduce Locator explicitly. Take a look at line with Locator[Dynamic[p, With[{... A strange behavior occurs whenever the left ...


8

To understand this, look at the typesetting: In[1]:= ToBoxes[Button["Print", Dynamic[a++]]] // InputForm Out[1]//InputForm= ButtonBox["\"Print\"", ButtonFunction :> Dynamic[a++], Appearance -> Automatic, Evaluator -> Automatic, Method -> "Preemptive"] Front end options, which includes all box options, can take Dynamic heads. That basically ...


7

This is probably not really an answer but definitely too long for a comment. First thing that seems worth mentioning is that the following part of the documentation for InheritScope can be interpreted as if the behavior you see is an intended feature: With the setting InheritScope->False, a DynamicModule will continue to inherit variable settings from a ...


7

The cause is the variable name confusion. It is true that each DynamicModule creates different symbol names. However, a new symbol name is generated again in Dynamic. For example, try running this code and slide the slider: DynamicModule[{x = 0, f}, f[] := Print[SymbolName@f]; f[]; Slider[Dynamic[x, f[] &]]] (* f$400707 *) (* Slider *) (* f$$3152 *) ...


5

This answer builds on @AlbertRetey's answer where, in the comments, you wanted some guidance as to how Wolfram creates robust controls. Think very carefully about the division of labor between the FE and the kernel. You've effectively embedded the entire implementation inside the FE by putting the update functions in DynamicModules. Generally, this is a ...


5

DynamicModule[{n = 20}, Column[{Row[{Slider[Dynamic[n], {1, 100, 1}], Dynamic[n]}], Dynamic[Legended[PieChart[Thread[Style[#[[All, 2]], #[[All, 1]] /. {True -> Red, False -> Green}] ], ChartStyle -> {Green, Red}] &@ Tally@RandomChoice[{True, False}, n], SwatchLegend[{Green, Red}, {False, True}]]]}]] ...


5

Manipulate[Show[Graphics[dottedCircle1[{0, 0}, Pi/2 + a, R]], Graphics[dottedCircle2[{R + r, 0}, -Pi/2 + s a, r]], AspectRatio -> Automatic], {a, 0, 2 Pi}, {{R, 1}, 0, 10}, {{r, .5}, 0, 10}, {{s, 0}, 0, 10, 1}]


4

Here is my take on that: EventHandler[Dynamic@Refresh[ If[0 < handAngle - clickAngle < \[Pi]/30, EmitSound[Sound@SoundNote["C"]]]; handAngle = N@Mod[15 - DateValue[Now, "Second"], 60, -30] \[Pi]/30; Show[ClockGauge[], Graphics[Point[clickPoint]]], UpdateInterval -> 1], {"MouseClicked" :> (clickPoint = ...


4

The Red/Green problem stems from the fact that Tally returns tallied values in the order each element is first encountered, and the other issue is because Tally doesn't return a 0 entry for elements not in the list. Both issues can be solved with a custom tally: explicitTally[list_,toTally_List] := {#, Count[list, #]} & /@ toTally; If you use ...


3

I suppose the it is expected and it happens because after prompting a DialogNotebook the evaluation of Module is finished and a Temporary attribute of its variables is kicking in. Why the first example works the second doesn't? I don't know but how a Temporary attribute works is not documented well. One way to make it work is to use kernel blocking ...


2

A lot of trouble can be avoided by not setting current to a Dynamic object, but assigning a value dynamically to it inside Dynamic. DynamicModule[{ds, class, sex, current}, Column[{ PopupMenu[Dynamic@class, {"1st", "2nd", "3rd"}], PopupMenu[Dynamic@sex, {"male", "female"}], Dynamic[current = ds[Select[#"class" == class ∧ #"sex" == sex &]]; ...


2

Here is a quick first draft: DynamicModule[{s = 0, pt = {0, 1}}, Column@{ClickPane[ Dynamic[Show[Refresh[Graphics[ClockGauge[]], UpdateInterval -> 1], Graphics[{Red, Point[pt]}]]], (pt = #; s = 30*(1 + ArcTan[-pt[[2]], -pt[[1]]]/Pi)) &], DynamicWrapper[Dynamic@s, If[DateValue["Second"] == Round[s], ...


2

Dynamic inside Manipulate A tip that I would like to contribute is to use Dynamic with controls such as sliders, checkboxes and input fields inside Manipulate. This enables one to place the control anywhere (even inside a figure) and to tie controls together. I typically initialize the controls by placing them in the normal spot for Manipulate but setting ...


2

Bug was fixed in version 10.4.0.0.


1

This will open a dialog notebook created by CreateDialog as soon as you "drive" over the left sideline. final = DynamicModule[{dialogQ = False}, {Graphics[{{White, Thick, Line[{{200, -500}, {200, 175000}}]}, {Yellow, Thick, Dashing[{.1, .05}], Line[{{500, -500}, {500, 175000}}]}, {White, Thick, Line[{{800, -500}, {800, 175000}}]}, ...


1

A bit simple minded: DynamicModule[{n = 3, bs}, Panel[Column[{Slider[Dynamic[n, {(n = #) &, (bs = PadRight[bs, {n, n}]) &}], {2, 100, 1}], Row[{Dynamic[Grid[Array[Checkbox[Dynamic[bs[[##]]], {0, 1}] &, ...


1

You can try with Manipulate Manipulate[Row[{SetterBar[Dynamic[y], Range[x]], Dynamic[y]}], {{x, 1,"Squares"}, InputField[#, Number] &}]



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