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}] {...


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 = ...


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}...


6

Something, that more or less does what you asked for, can be achieved by creating a hidden InitializationCell using a DynamicWrapper DynamicWrapper["xxx", If[foo == 23, MessageDialog["You guessed it!"], MessageDialog["You've guessed the right variable name, but not the right value yet."]]] A much more elegant method is to use ...


4

Ok, I read it again and again and I think I know what you are after. Here's quick fix/adjustment to make this thing a valid controller: SetAttributes[customColorSetter, HoldFirst] customColorSetter[var_] := ( If[! MatchQ[var, _RGBColor], var = Black]; Delete[ FrontEndResource["RGBColorValueSelector"][[1, 1]], {{1, 1}} ] /. $CellContext`...


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

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

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

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

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", ...


3

Since a PopupMenu exhibits a behavior you are after, let's adjust it to act like an ActionMenu: myActionMenu[lbl_, actions_, opts___] := DynamicModule[{x = Unique[x]}, PopupMenu[Dynamic[x, (# /. actions) &], First /@ actions, lbl, opts] ] myActionMenu[ "Print Factorials", {"4!" :> Print[4!], "7!" :> Print[7!], "10!" :> Print[10!]} ]


3

Actually there is nothing you have to really do, just get some images (you can of course just as well Import your own ones): img1 = ExampleData[{"TestImage", "Tree"}]; img2 = ExampleData[{"TestImage", "Truck"}]; and use them where you'd otherwise use strings or whatever: TabView[{ img1 -> "tree", img2 -> "truck" }] it looks somewhat better if ...


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

Your problem is the Set. Set means you're assigning something to a variable (=), x2 Sin[x2] is not a variable. Try Equal[] instead, this is equivalent to ==. Vars = {{(x1) Cos[x2], Sin[x2], 0, (x3) (Sin[x2])}, {(Cos[x2]) (Sin[x4]), (x3) Cos[x4], 1, x1}}; Const = {{1, 0, 0, 1}, {0, 1, 1, 2}}; MapThread[Equal, {Vars, Const}, 2] yields the output: {{x1 ...


3

One can use $Pre to check if an input expression defines the correct variable and is doing so using the correct value. SetAttributes[check, HoldAll] check[new_Set] := (Print["You guessed it!"]; new) /; HoldForm@new == HoldForm@Set[foo, 23] check[new_Set] := (Print[ "You've guessed the right variable name, but not the right value yet."]; new) /; Extract[...



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