Hot answers tagged

23

Edit: getting rid of FilledCurve to speed things up. Here's something fun: g = Normal @ Show @ CommunityGraphPlot[ ExampleData[{"NetworkGraph", "DolphinSocialNetwork"}] ]; dist = Normalize[#] (2./Pi ArcTan[Norm[5 #]]) &; DynamicModule[{drag,pts,prims} , pts = Union@Cases[g, {_?NumericQ, _?NumericQ}, \[Infinity]]; prims = ( First[g] /...


22

I have finished a project where widgets like this have been useful so I thought I would share. By combining InputField and PopupMenu a searchable popup selection table can be created. searchPopup[Dynamic[selection_], list_List] := DynamicModule[{x = ""}, Grid[{{ InputField[Dynamic[x], String, Appearance -> "Frameless", ...


21

If you are serious about using this extensively, consider making a function based on CreateDocument... Here is one way to pursue Szabolcs's line of thought. What follows is a function based on CreateDocument[] that can be used in conjunction with the (now somewhat neglected) option DisplayFunction, which handles where the output of graphics functions ...


20

You can do this using Show and PlotRange which can be used in combination with graphs. To determine the full PlotRange of the original Graph you could use AbsoluteOptions to determine the values of the VertexCoordinates of the graph. The function CoordinateBoundingBox, introduced in V10.1, is helpful here: SeedRandom[1110]; g = RandomGraph[{70, 200}] {...


18

In this case I don't know how to post something helpful without providing full code so I'll just do that and hope this wasn't homework. My emphasis is on clarity (hopefully) rather than brevity or peak efficiency. flip = # /. {LightRed -> LightBlue, LightBlue -> LightRed} &; flipNeighbors[i_, j_] := (color[##] = flip @ color[##];) & @@@ ...


17

You can always create a new notebook and put things in it. If you are serious about using this extensively, consider making a function based on CreateDocument that sets the appropriate options for the notebook to look good. Check what CreateDocument@Plot[Sin[x],{x,0,10}] does. Or use a quick-and-dirty hack based on CreatePalette: fig = CreatePalette[#, ...


15

Intro One day I was playing with Developer` package and found DateSetter which uses some kind of floating elements that I found useful. After taking a look at a source code I found out it was FrontEnd`AttachedCell. From the code one could learn enough to create something useful: Usage FrontEnd`AttachCell[ parentObject, (*Box or Cell ...


14

Based on undocumented FrontEnd`AttachCell: What is FrontEnd`AttachedCell? And Experimental`Autocompletebut this can be replaced with Mike's approach. Need to work on style, automatic scrolling and some edge cases, but already works quite well. Feedback appreciated. Column[{ searchPopup2[Dynamic[selection], list], Graphics@Disk[] }] Code ...


12

I would suggest using the second argument of Dynamic: DynamicModule[{shape = Disk[], targets = RandomPoint[Disk[], 10]}, Panel@Column@{ Item[ RadioButtonBar[Dynamic[ shape, (targets = RandomPoint[#, 10]; shape = #) & ], {Disk[] -> "Disk", Rectangle[] -> "Rectangle"}], Alignment -> Center ], Dynamic@...


10

Quick fix is to use e.g. Inactivate and friends: Manipulate[ Column[{ Activate @ #, Panel @ ExpressionCell[ # /. Inactive -> Defer, "Notebook", "Input" ] }] & @ Inactivate @ Plot[Sin[x], {x, -3, 3}, AxesLabel -> {xlabel, ylabel}, Ticks -> {tics, tics}] , Control[{{tics, Automatic, ""}, {Automatic -&...


10

Whole ListPlot is recalculated at each click because clicks value has changed, you can isolate Dynamic parts of graphics in Epilog to avoid that. Using EventHandlers there will allow you to drop clicked points. testdata = Array[{#, 1 + #^2*RandomReal[]} &, 100]; clicks = {testdata[[1]], testdata[[-1]]}; ListPlot[ Button[Tooltip @ #, AppendTo[...


10

You are almost there but Graphs are not mutable so: DynamicModule[{graph}, Dynamic[graph] , Initialization :> ( graph = Graph[ {1 -> 3, 2 -> 3, 3 -> 6, 4 -> 6, 1 -> 5, 5 -> 4, 6 -> 2}, VertexLabels -> "Name", VertexShapeFunction -> ( EventHandler[ Disk[#1, .1], "MouseClicked" :> (graph = ...


10

Do you mean Button[ Tooltip["click", Column[{"Click this button to select a ColorScheme.", "This button will be replaced with ColorData"}]], With[{box = EvaluationBox[]}, SelectionMove[box, All, Expression]; FrontEndExecute@ FrontEnd`AttachCell[box, FrontEndResource["ColorSchemeSelector"], {1, {Right, Top}}, {Left, Top}, "...


9

Edit Can you think of another way to accomplish the same thing [...]? It would be nice to have a solution that didn't involve duplicating each slider. -nibudd DynamicModule[{a = 1, tempA = 1, auto = True} , ifAuto = Dynamic[ If[auto, Identity, Setting]@#, TrackedSymbols :> {auto} ] &; Column[{ ifAuto @ Dynamic @ Plot[Sin[...


8

You can overwrite specific NotebookEventActions which are responsible for that: CreateDialog[ Overlay[{DefaultButton[], CancelButton[], InputField[]}, {3}, 3], NotebookEventActions -> { "EscapeKeyDown" :> {}, "ReturnKeyDown" :> {}, PassEventsDown -> True } ] PassEventsDown -> True allows "\[AliasDelimiter]" to appear in the ...


7

A simple example of one popup depending on the selection of another: DynamicModule[{x, y, list}, {PopupMenu[ Dynamic[x, (x = #; list = Switch[#, "A", {1, 2, 3}, "B", {4, 5, 6}, "C", {7, 8, 9}]; y = First[list]) &], {"A", "B", "C"}], Dynamic[PopupMenu[Dynamic[y], list], TrackedSymbols :> {list}]} ]


7

Here's beta version, basic functionality is delivered. I have to polish it but probably I won't have time for that this year. It has to be packed into self contained module and styling options have to be enabled. I will update a nice description of an approach too, but meanwhile, if anything is not clear, feel free to ask. ActionNestedMenu[ "Test menu" -&...


7

If you leave ContourPlot outside you can get quite nice performance: static = ContourPlot[45 x^2 + 20 y^2 == 45, {x, -2, 2}, {y, -2, 2}, Frame -> False]; dynamic = ContourPlot[8 x^2 + 4 x y + 5 y^2 == 9, {x, -2, 2}, {y, -2, 2}, Frame -> False, ContourStyle -> Orange]; Manipulate[ Graphics[{ First@static, Dynamic[Rotate[...


7

How about FlipView: FlipView[{ Button@"Show hint", Column[{ TextCell[ "You can plot a function using:", "Notebook", "Text" ], ExpressionCell[ Defer@Plot[Sin[x], {x, 0, 1}], "Notebook", "Input" ] }] }] alternatively, born from comments under Karsten's answer: FlipView[{ Button["Show hint"], Tooltip[ ...


7

A modification of the answer provided by Kuba that uses an AttachedCell to give the hint: Button[ "Show hint", With[{box = EvaluationBox[]}, SelectionMove[box, All, Expression]; FrontEndExecute@FrontEnd`AttachCell[box, Cell[BoxData[GridBox[ { {Cell["You can plot a function using:", "Text"]}, {Cell[BoxData["Plot[Sin[x],{x,0,1}...


7

What is going on By default the Dynamic, EventHandlers and various controllers like Button and Slider use a PreemptiveLink to communicate with the kernel. Synchronous versus Asynchronous Dynamic Evaluations about the PreemptiveLink: [...] There is no queue; instead, the front end sends one evaluation at a time and waits for the result before ...


7

Here is a modification of Karsten's answer attempting to get the behavior you described in a comment. The selected value is assigned to Global`$color (as shown by Dynamic) I made the picker wider to get rid of the annoying bottom scroll bar Code: Button["Pick a color", Module[{picker, box = EvaluationBox[]}, picker = FrontEndResource["...


6

I think you should change your setup a little bit. Including procedures inside Dynamics is useful somethimes, for better events handling, but nothing fancy is going on here. Thus it is better schedule calculations in a more stable way, by moving the Grid generation outside Dynamic. Your exporting procedure clearly expects myplots to have an up to date ...


4

Ad i. PasteButton[RawBoxes @ "myList"] Ad ii. I've put there a fixed size of the window and additional pane to scroll through Ad iii. Prepare plot button opens a dialog to pick lists to plot. You can pick one or two, if two are picked then Transpose@{list1, list2} is used. I'm not checking correctness of the input. CreateWindow[PaletteNotebook[ ...


4

Here is a possible coding for the next step: DynamicModule[{x = 0, s = 6, bkgs}, col1 = Lighter@Lighter@Green; col2 = Lighter@Lighter@Blue; col3 = Lighter@Lighter@Red; bkgs = Table[col1, {s^2}]; Grid@Map[Button[ToString@#, x = #, Background -> Dynamic[ If[bkgs[[#]] == col1, If[x == #, bkgs[[#]] = col2, If[MemberQ[...


4

Something like this is a good start. I tried to write it in a way to make it easy to expand. ruleListQ[{r__Rule}] = True; (* JSON won't have RuleDelayed *) ruleListQ[_] = False; formatJSON[json_] := Switch[json, _?ruleListQ, (* dictionary *) Column@Replace[json, HoldPattern[a_ -> b_] :> OpenerView[{a, formatJSON[b]}], {1}], _?(ArrayQ[#, _, ...


4

This does a targeted overwrite of just the Panel...well, technically, of the DynamicModuleBox with which I'm wrapping the PanelBox: DynamicModule[{box}, Panel[Column[{Style["What's the gender?", FontFamily -> "Calibri", FontSize -> 14], PopupMenu[Dynamic[x], optionsGender], " ", Style["What's the academic title?", FontFamily -> "...


4

Shortly, use a SelectorPane and hide EventHandler as soon as the condition is met: pt = {0, .05}; pane = "dynamic"; graphics = Framed[Graphics[ {{Red, Disk[Dynamic[pt], .1]}}, PlotRange -> 1, Axes -> True] ]; eh = EventHandler[#, { "LeftArrowKeyDown" :> (pt -= {0.05, 0}; check@pt), "RightArrowKeyDown" :> (pt += {0.05, 0}; ...


3

In the documentation of Button, under Options -> Method, it says: By default, button functions are evaluated on a preemptive link and time out after 5 seconds: DynamicModule[{a = "start"}, {Button["does time out", Pause[6]; a = "end"], Dynamic[a]}] Use Method->"Queued" to evaluate button functions on the main link, which never times out: ...


3

A modified version of the solution provided by Kuba, that behaves like an ActionMenu with the option setting Method -> "Queued" popupActionMenu[lbl_, actions_] := DynamicModule[{x, trigger}, Row[{PopupMenu[Dynamic[Refresh[x, TrackedSymbols :> {}], (trigger =.; trigger = #) &], First /@ actions, lbl, BaseStyle -> "ActionMenu", ...



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