Hot answers tagged gui-construction
49
Since Mathematica does not have a built-in plot manipulating interface, here is a gui of a plot-manipulator. Updates are indicated with bold text.
Functionality:
Should work with any plot/graphics (ArrayPlot compatibility added);
Drag anywhere in plot zooms in to selected rectangle; can be done repeatedly;
Ctrl+drag zooms in/out (along vertical axis);
...
22
One of the excellent places to look is the Wolfram Demonstration Project. There are many cases with custom controls there. You can test out controls immediately and download the source code. Because I know that site pretty well I will keep the list here.
Relief-Shaded Elevation Map
3D Waves
Potter's Wheel
Motion Blur
Contours of Algebraic ...
18
In addition to István's fine answer, there is also Experimental`Explore[] which provides almost all the functionalities in his PlotExplorer. I think it was Szabolcs who first told me of this function.
If you call the above function with no arguments, you can choose to interactively work with either Plot, ParametricPlot, Manipulate or Graphics. Alternately, ...
14
Some you can find in the Documentation Center, like the angular slider in Dynamic's documentation (under Applications), or the ValueThumbSlider in the Advanced Manipulate Functionality section (under Custom Control Appearances).
Some you can find in developer packages like the angular slider in the "Experimental`" package:
Needs@"Experimental`"; ...
14
You could do create a simple graph editing tool to create a graph from scratch by doing something like this. To add edges you just click and drag.
DynamicModule[{pt1, pt2, ind1, ind2, pts = {}, edges = {}, cedge = {}},
Manipulate[
EventHandler[
Dynamic@Graphics[
{Line[pts[[#]] & /@ edges],
cedge, {Red, PointSize[Medium], Point[pts]}}, ...
13
I'll post a function based on the title of the question. You wrap your dynamic code in profileDynamics optionally passing the option "Print"->True (defaults to False).
It should be noted that this can only profile the explicit Dynamics that are on the code. Nested dynamics that are generated at runtime are not profiled by this
ClearAll[profileDynamics];
...
12
This solution relies on putting a TagBox with a custom tag around the part to be replaced, reading the cell and replacing the tag, then writing it back. Personally I've always felt that the need to read the entire cell and write it all again seems kind of clunky, but I don't know of a better way to do this.
...
12
You want to use Grid.
Code
Panel[
Grid[
{
(* The 1st row *)
{
Row[{"Board size: ", InputField[Dynamic[max], Number, FieldSize -> 3]}],
Button["Clear Board", ImageSize -> All]
},
(* The 2nd row *)
{
Graphics[Circle[], ImageSize -> 300], SpanFromLeft
}
}, Alignment -> {{Left, Right}, Baseline}]
]
...
12
Since Input is a DialogInput, it seemed reasonable to peek into Input's structure to understand how the focus is set. After removing the ReadProtected attribute I've realized that there is no neat way to do it, as WRI itself has done the reposition of the focus via successive SelectionMove calls.
This example below is not the original but a modified ...
10
This is a bit more complicated, but I did this for a human experiment previously, so why not share it.
The code keeps track of nodes and edges of a graph that can be manipulated:
new edges can be drawn by dragging the mouse from one node to the other
edges can be deleted via right-click menu
nodes can be moved by dragging while holding Ctrl
node can be ...
10
Like this
Slider[Dynamic[y,(y=#;f[y])&],{1,4}]
You can can test using for example
f[y_]:=Print@y;
I advise you to look at the help of Dynamic that contains examples of other related features.
9
This solution illustrates using Spacer. Move the slider to place the button anywhere you want along the width of interface:
Manipulate[Panel[Column[{Row[{"Board size: ",InputField[Dynamic[max], Number,
FieldSize -> 3], Spacer[spacer], Button["Clear Board"]}], Plot[Sin[x], {x, -3, 3},
ImageSize -> 400]}]], {{spacer, 100}, 0, 220}, FrameMargins -> ...
9
The answer is that yes, you can affect the appearance of components of a control but the problem in this case is that your list of appearances
appearances = {"DialogBox", "Palette", "FramedPalette", "Frameless"};
are only valid Button appearances and that is why they have no effect of ButtonBar or TabView. When you use valid appearances it works fine:
...
8
You can also look at the GUIKit` package which allows you to create complicated widgets and panels that mimic the look and feel of the OS. The user guide/tutorial is pretty decent and has several examples too that you can learn from and modify to your needs. In fact, a lot of the additional editing/explorer functionality like GraphEdit and DatabaseExplorer ...
8
You can use the "wormhole" construct from "tutorial/AdvancedDynamicFunctionality" like this:
Manipulate[
Graphics[
Translate[
GeometricTransformation[{Blue,
Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}, {{scx, 0}, {0,
scy}}], Tuples[{Range[wi], Range[he]}] - 1],
ImageSize -> 400 {1, 1}],
OpenerView[{Button["external",
...
8
If you notice Mathematica Documentation Center search field is kind of the same thing. And search window from Ctrl-F too. It uses a similar concept to what I'll show. Important thing to know is that EventHandler can track commands from the Mathematica menu. There is an undocumented option HandleShiftReturn and here is a trick I learned from FW:
...
8
You can use a combination of MouseDown and MouseClickCount as in the following examples:
example 1: double-click increments the value of j:
j = 1; EventHandler[Panel[Dynamic[j]],
"MouseDown" :> If[CurrentValue["MouseClickCount"] == 2, ++j]]
example 2: double-click toggles the text color:
DynamicModule[{col = Green},
EventHandler[
...
8
First, let me note that 50kB for such a simple graphics is unbelievably much. In fact, I had to create large and randomized raster icons to achieve such a size. Your things on the other hand look really simple and should be extremely small as vector-graphics.
So here is what I tried:
n = 200;
MapIndexed[Export[StringJoin["tmp/", ToString[#2[[1]]], ".pdf"], ...
8
First, define PopupView with empty reference list and only substitute real reference list ref into the PopupView if it is first clicked. This is done by wrapping the PopupView in an EventHandler. The dynamically displayed list next to the initially empty PopupView shows that before clicking, it is empty, and only gains its value when first clicked.
...
7
Not 100% solution, but this may work. Define:
dialog :=
CreateDialog[{TextCell["Click OK to close"], DefaultButton[]},
Modal -> True, NotebookEventActions -> {"WindowClose" :> dialog}]
Then call:
dialog
At least, it reappears :)
7
AFAIK there is no possiblity to react to the OS drag & drop, but I would'nt be surprised if someone has found a way to get that work. Anyway, the following is roughly what I'd do:
guidefinition = Deploy@Panel@DynamicModule[{
num1 = 100, num2 = 10,
path = FileNameJoin[{$HomeDirectory, "Desktop", "file.xls"}],
year = Null, month = Null, ...
7
The behaviour is indeed inconsistent: CreateDialog uses the option WindowSize -> All, where All (god knows why) causes the unexpected behaviour with dynamic content. See resolution of the problem at the end of the post.
The following even more simple example clearly shows that something fishy is going on: only path2 can be set via the second button but ...
7
Assign your input in DialogReturn, e.g. to a variable return. Apart from from this, and omitting your Dynamic@x at the end, your code is unchanged:
DynamicForm[row_, col_] :=
DynamicModule[{x = ConstantArray[0, {row, col}], a},
a = {Column[(Row[#] & /@
Table[With[{i = i, j = j},
InputField[Dynamic[x[[i, j]]], Number,
...
7
You can always create your own custom controls. This is a lot of work, but it also gives you unlimited flexibility. You can even create completely new kinds of control.
Scroll down to the last section here to see an example.
If you're aiming for a custom TabView-like control, I'd start with PaneSelector.
Here's a primitive example (just a start, not ...
7
You could always try a gauge:
gf[{{xmin_, xmax_}, {ymin_, ymax_}}, ___] :=
{Black,
Rectangle[{xmin, -0.01}, {xmax, 0.01},
RoundingRadius -> .01]}
HorizontalGauge[Dynamic[n], {1, 9},
ScaleDivisions -> None,
ScaleRanges -> All,
ScaleRangeStyle -> None,
GaugeFaceElementFunction -> gf,
GaugeMarkers -> Placed[
Graphics[{Black, ...
7
If pre-version-9 (no gauges yet), one has to rely on custom built controllers.
Here is a slider implementation using LocatorPane (I prefer lines with rounded caps instead of rectangles because of aspect ratio issues):
slider[Dynamic[var_], {min_, max_}] := Module[{x = 0},
LocatorPane[
Dynamic[{x, 0}, (x = First@#; var = Rescale[x, {-1, 1}, {min, ...
6
ExpressionCell[Panel@DynamicModule[{input = ""}, InputField[Dynamic[input], String]]]
Content added:
ShiftReturn pressed:
Learned this here.
6
Here's one way to do it. In this example I've used one list of points for the vertices of the two shapes. The inner EventHandler sets the flag drag which indicates which shape should be moved. The outer EventHandler actually moves the shape. Releasing the mouse resets drag to 0 again. I'm using PassEventsDown -> True in the outer event handlers to make ...
6
Here's my first stab at a solution based on the idea of a closure. Maybe it has some elements that you can draw on for inspiration.
Function to create a timer function
makeTimer[] := Module[{start = AbsoluteTime[]}, Switch[#,
"now", AbsoluteTime[] - start,
"lap", AbsoluteTime[] - start,
"reset", (start = AbsoluteTime[]; 0)]
&]
Timers ...
6
I think these questions being indeed basic, are rather important. I cannot answer the first two myself, though would love to see some methods that can deal with them. As always, there are other ways to solve the remaining two questions.
Since Mathematica is not designed to produce standalone ("executable") files, you need to have either Mathematica or the ...
Only top voted, non community-wiki answers of a minimum length are eligible

