# Tag Info

22

If you pass SynchronousUpdating->False to Dynamic, it will perform operations on the main link. Note that this only works where Dynamic is displayed as a typeset result (i.e., typeset as a DynamicBox). It does not presently work where Dynamic is used to give a value to a control (such as Slider) or an option. A quick survey of other constructs... ...

16

I'm not sure if this is exactly what you need but this is what I've recently done to inform the user about ongoing calculation. Usage withProgressIndicator[proc, delay] Performs a proc, and when it lasts longer than delay (default 0), a progress indicator in dialog is created. It will be closed after finishing the proc. It should be run on Main Link, ...

16

OK, I guess I found something myself while trying to circumvent RunScheduledTask. DynamicModule[{prog = False}, Column[{ Button[ "Do heavy work", prog = True; Pause[10]; prog = False, Method -> "Queued" ], Dynamic@If[prog, ProgressIndicator[Appearance -> "Percolate"], Invisible[ProgressIndicator[Appearance ->...

15

While John Fultz gave a depressing answer concerning GUI controls, I doubted that this cannot be done in Mathematica. A bit of exploration and Rojo's extremely useful answer helped me to come up with a workaround to simulate Method -> Queued for GUI controllers other than Button. The function queued accepts any dynamic controller as its first argument ...

13

Building on Kubas code here is an alternative which solves some (minor) problems: it will not leave behind scheduled tasks when the abort button is used, it works equaly well when the Alt+. shortcut is used to abort and it might work better when aborting preemptive evaluations. Here is the code: SetAttributes[withProgressIndicator, HoldFirst]; ...

13

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

13

Why not just use the graphic in the question, or any other images that you like: Use ImageSize to control the final size of the button: An alternative, that I use in some applications, is something like this: help[$helpmessage_: "",$videolink_: ""] := ActionMenu[ Graphics[{{RGBColor[0.689647, 0.761166, 0.805478], Disk[{0, 0}, 0.1]}, {...

11

The reason is because Button actions are calculated on a preemptive link, meaning they preempt any other evaluation, but are only allowed a certain amount of time to evaluate. That indicates: the front end sends one evaluation at a time and waits for the result before continuing with its other work Tutorial / Advanced Dynamic Functionality / Synchronous ...

11

So I mentioned this in a comment but I'll get it out here for the bounty poster too. Searching for the "JLink`" in the autocomplete directory gave me this: FileNameJoin@{$InstallationDirectory, "SystemFiles", "Components", "AutoCompletionData", "Main", "documentedContexts.m"} If we look at what's inside it: FileNameJoin@{$InstallationDirectory, "...

10

A couple of images that come with Mathematica. Caveat: There's no guarantee that they will be present in all (future) versions. Button[ Import[FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd", "SystemResources", "Bitmaps", "Popups", "CodeCompletion", "MenuItemHelpTiny@144dpi.png"}] ], Beep[], (* your help dialog here *) ... 10 Here's the general way this type of thing seems to be handled in the built-in things plus code to build the type of buttons you want. First the button code: makeDisk[gradSpec_, n_] := Rasterize[ Module[{img, disk, edge}, img = RadialGradientImage[ gradSpec, n ]; Graphics[ { Inset[img, Center, Center, Scaled[1]]... 10 ClearAll[togglerMesh] togglerMesh = DynamicModule[{ m = #, ids = {}, nF = Nearest[PropertyValue[{#, 2}, MeshCellCentroid] -> "Index"]}, Dynamic@EventHandler[HighlightMesh[m, Thread[{2, Flatten@ids}]], "MouseClicked" :> If[MemberQ[ids, #], ids = DeleteCases[ids, #], AppendTo[ids, #]] &[If[MousePosition["Graphics"] === ... 10 Here are implementations for a MeshTogglerBar and MeshSetterBar based on my answer here (code below). Both implementations use Mouseover and EventHandler to handle detection of the polygon below the cursor for you. Compared to the NearestFunction approach, this is far more performant (since it is done by the front-end), it also works nicely for other types ... 9 Based on Istvans solution this should do the same thing, but is somewhat simpler in that it avoids the EventHandler which would need adoption to match the possible interactions of the gui element used. The use of the three "change functions" also makes possible to continuously update the controller variable but only trigger the long calculation when the "... 9 SeedRandom[421] points = RandomReal[{-1, 1}, {10, 2}]; mesh = VoronoiMesh[points, {{-1, 1}, {-1, 1}}]; nf = Nearest[points -> Automatic]; primitives = MeshPrimitives[mesh, {2, All}]; Dynamic[ ClickPane[ HighlightMesh[mesh, {2, #}] & @@ FirstPosition[ primitives, SelectFirst[primitives, RegionMember[#, Extract[points, ... 8 For simplicity, I'm using function downvalues as a backend (and not an array) (* Define functions *) bTable[action_, fArray_, dims_]:= Grid@Array[Button[{#1, #2}, action[fArray, #1, #2]]&, dims] action[fArray_, x_, y_] := (fArray[x, y] = fArray[x, y] + 1) (* or whatever *) (* Initialize *) dims = {3, 3}; Array[(f[#1, #2] = 0) &, dims]; (* Run *) ... 8 An alternative approach using CurrentValue["MouseOver"]: Button[Panel["Print", FrameMargins -> {{4, 4}, {4, 4}}, Background -> Dynamic@If[CurrentValue["MouseOver"], Green, Red]], Print["Print"], Appearance -> None] or, without the Panel, Button["Print", Print["Print"], Background -> Dynamic@If[CurrentValue["... 8 If you want full flexibility you should try EventHandler and graphics primitives. If you can decipher the following example you will get the idea: color = Black; positions = Position[DiskMatrix[5], 1]; disks = {color, Disk[#, 0.4]} & /@ positions; eventHandler[item : {c_, obj_: Disk[p_, _]}] := {c, EventHandler[obj, "MouseClicked" :> (disks = (... 8 Add Method -> "Queued" Button["Import File", Import[SystemDialogInput["FileOpen", ".txt"], "List"], Method -> "Queued"] From IntroductionToControlObjects So if you have an evaluation that you expect will take more than a couple of seconds to evaluate, you should use Method->"Queued". Clicking such a button will use the main link when ... 7 Another method which doesn't really use Mouseover but the EventHandler: DynamicModule[{col = Red}, EventHandler[ Button[ Panel["Print", FrameMargins -> {{4, 4}, {4, 4}}, Background -> Dynamic[col]], ... 7 One way, based on the self-delete example in the documentation for Button: Button["Start", SelectionMove[ButtonNotebook[], All, GeneratedCell]; NotebookDelete[ButtonNotebook[]]; Print[Plot[x^3, {x, -1, 1}]]] 7 The code above 9.0 is good Unfortunately, this is not true. Even in version 9 this code was not good, but it just did not warn you about it. Take this simpler example, that only prints the file-name of the selected file and try it in version 9: Button["Import File", Print[SystemDialogInput["FileOpen"]]] If you try the button and select a file quickly, ... 7 Another way is to use Grid for complex layouts. One drawback is that Delimiter does not work as in the original Manipulate, the advantage is that you can use all styling options available to Grid, plus you don´t have to fiddle with discrete ImageSize values etc.: Manipulate[ ParametricPlot[{y t^3 - u, x t^2 + z}, {t, -10, 10}, PlotRange -> {{-1.5, 2.... 7 According to the documentation, "PasteButton, evaluates its arguments in an ordinary way, so that expr is immediately evaluated" It is like you evaluate Plot[\[SelectionPlaceholder], {x, 0, 10}] which will give empty plot. This could be one solution: PasteButton["Plot", Defer[Plot[\[SelectionPlaceholder], {x, 0, 10}]]] 7 In case you want to plot in place you can use something like: Button["Plot", NotebookWrite[ InputNotebook[], ToBoxes @ Plot[ Evaluate @ ToExpression @ CurrentValue @ "SelectionData", {x, 0, 10} ] ] ] You may want to add Method -> "Queued" for more complicated plot to avoid timeout. And if you want x from ... 7 You can use two individual instances of Button Column[{ Button["\[UpArrow]", Print["up"]], Button["\[DownArrow]", Print["down"]]}, Spacings -> -1] Unfortunately Button misbehaves on some systems when it comes to changing its size to just encompass its label (see this question). You might also notice a small optical glitch (visible in the .gif above as ... 7 Details aside, TogglerBar seems to fit your needs best: fonts = {}; TogglerBar[ Dynamic@fonts , # -> Row[{Pane[#, 200], Range[0, 9]}, BaseStyle -> {FontFamily -> #, 20} ] & /@$FontFamilies[[;; 10]] , Appearance -> "Vertical" ] Dynamic[fonts]

7

Here is some code I wrote to make a palette that I use a lot. Maybe the it will work you, or at least give you ideas on how to do it. CreatePalette[ Framed @ Column[{ Button["Evaluate Cells", FrontEndExecute[FrontEndToken["EvaluateCells"]], Appearance -> "Palette", ImageSize -> 140], Button["Evaluate Notebook", ...

6

You don't have repeat yourself. You can map a pure function defining the button over a list of the background colors and then apply Mouseover Like so: Mouseover @@ (Button[Panel["Print", FrameMargins -> {{4, 4}, {4, 4}}, Background -> #], Print["Print"], Appearance -> None] & /@ {Red, Green})

6

V10 edit As of V10 it is easier to do that with a help of EvaluationBox[]. Your second concern is solved by temporarily changing DefaultDuplicateCellStyle. 78417 ButtonHold ~ SetAttributes ~ HoldFirst; ButtonHold[expr_] := Button[ Tooltip["Evaluate", HoldForm[expr]] , Module[{nb = EvaluationNotebook[], pre, opt = DefaultDuplicateCellStyle}...

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