# Tag Info

## Hot answers tagged eventhandler

127

Well, the answer seems to be YES :) Here is my implementation of Minecraft classic game in Mathematica. Let’s start with some screenshots which were taken during the construction of the final scene which will be displayed an the end of this post. Features Blocks are creatable and removable One texture per block Player automatically jumps to the ...

6

Yes, it is possible. Have you read the tutorials about Dynamic? Here is a simple example of a continuously updated time which changes color on Mouseover Dynamic[Refresh[ Mouseover[DateString[],Style[DateString[],20,Blue]], UpdateInterval->1]] Here the slightly more complex example with two buttons. DynamicModule[{bold=False,blue=False}, Column[{ ...

5

Your code seems to intend to do something a little different than what I understood from the question - so I hope this is right. :) Fixing the code require two changes, remove Deploy -- it makes the EventHandler inoperative; and put Dynamic around the argument pt -- one of the important attributes of Dynamic is that it is HoldFirst, which allows the ...

4

For version 9 or above, one can use CellPrint (or simply Print, as it is a specific case of CellPrint) which does not move the selection and thus preserves the focus on the InputField. EventHandler[InputField["", String], {"ReturnKeyDown" :> CellPrint[Cell["test", "Output"]]} ] Since the above code only works in v9, here is an equivalent with ...

4

Check what The Futz just said. However, you can go the ugly workaround way. Not recommended, since I don't think you have any guarantees that your code will be evaluated exactly once only when you click the button, but up to you. Try this Print@"I dare you to move the slider after pressing the button"; \ Slider[] EventHandler[Framed["Benjamin Button"], ...

4

You want to create an independent DynamicModule for each EventHandler. Otherwise, the single variable col will control the color for all of the disks, as you're witnessing. Your code can be rearranged as follows: radius = 1; numDisks = 3; Graphics[Table[ DynamicModule[{col = Red}, EventHandler[{Dynamic[col], Disk[{2.5*(i - 1), 0}, ...

3

As your code doesn't appear to run and presents so much to decipher before anyone could usefully help you with it, consider this simpler alternative: Manipulate[ Graphics3D[{Red, Cylinder[]}, ImageSize -> iSize, ViewAngle -> vAngle \[Degree]], {{iSize, 250}, 50, 500, 25}, {{vAngle, 40}, 50, 10, 1}] A couple of screen shots of the output ...

3

As Leonid suggested, I added the full path to the event handler, and it gets called now from inside the package: observer@addMessageHandler[ ImplementJavaInterface["me.kutrumbos.examples.MessageHandler", "update" -> "UtilsPrivateonCollectionUpdate"]]; Thanks, Leonid!

3

I was just working along the lines of @Rojo's comment: DynamicModule[{i = 0, state = False}, Dynamic[If[ControllerState["Button 1"], If[state, i = i + 1; state = False], If[! state, state = True]]; i] ] Sometimes it appears that the mouse action is intercepted by Mathematica. You may find that unnacceptable.

3

The objective of the question was to clarify whether EventHandler should work with DateListPlot (work arounds were not sought). Wolfram tech support confirmed that EventHandler does not work with DateListPlot. This is not a bug it is just that this capability is not available for DateListPlot.

3

I couldn't get the mouse to change appearance while being pressed, so I think you'll need a work-around. What I would suggest is to simulate the mouse with a graphics Inset that looks like an arrow and follows the mouse, while making the actual mouse cursor invisible for the entire time the mouse is inside the object. This works only if the object is ...

2

What you need is, instead of MouseDown, "MouseClicked". MouseDown is always true, for left and right mouse button (stupid me)... DynamicModule[{pt = {0, 0}}, EventHandler[ Graphics[{Disk[Dynamic[pt], .1]}, PlotRange -> 1], {"MouseClicked", 1} :> (pt = MousePosition["Graphics"]), PassEventsDown -> True]]

2

Edit: Updated to register any key presses Whenever an EventHandler does not handle something continuously, one can set up a listener manually using scheduled tasks. Here, the task task is initiated when the InputField is displayed, that scans the state of the Shift key. You can put whatever code you want to be evaluated on keypress in the update function. ...

2

Simple solution is: you have to use Method->"Queued" as option to button vars = {0, 0, 0, 0}; {Button["DO STUFF", (data = { {+0.18, -0.13}, {+0.84, -0.06}, {+0.05, +0.88}, {+0.24, -0.63}, {+0.67, +0.93}, {+0.05, +0.88}, {+0.65, +0.92}, {+0.01, +0.99}, {+0.17, -0.04}, {+0.23, -0.55}}; model[{a_, k_, w_, p_}] = a Exp[-k x] Sin[w x + p]; ...

2

Here is the minimal example what you are probably looking for. Switching between zooming and rotating is handled in two places: If stops zooming unless zoom==True. PassEventsDown->!zoom prevents rotating when zooming is enabled. DynamicModule[{y = .5, zoom}, EventHandler[ Column[{ Row[{Checkbox[Dynamic@zoom], ...

2

data = Table[{i, 5 Sin[i/10] + RandomReal[]}, {i, 100}]; data2 = {Log[#], #2} & @@@ data; In case when you don't know how both axes are related to each other but only have point sets you can do something like: Deploy@With[{opts = {Axes -> False, Frame -> True, ImageSize -> {300, 300/GoldenRatio}, AspectRatio -> ...

2

Using Scaled coordinates can be quite helpful: DynamicModule[{ loc = Scaled[{0.5, 0.5}]}, Column[{ Plot[ x, {x, 1, 2}, Epilog -> Dynamic[ Point[Scaled[{loc[[1, 1]], loc[[1, 1]]}]] ]], Plot[ x^2, {x, -1, 2}, Epilog -> Dynamic@Locator[Dynamic[loc]]] }] ] See how the point in the first coordinates follows quite nicely ...

1

Figured this one out. It is basically the same problem described here and essentially answered here. The actions in the EventHandler are calculated on the preemptive link. In order to make the EventHandler act as a Button when Method->"Queued", DynamicWrapper can be used: DynamicModule[{thing="foo",returnkeydown=False},nb = ...

1

Original (incorrect) answer When you press in the white area and drag into the green square, you begin a selection just like when you select objects for copy-paste operations. The workaround I propose is to prevent the selection process to begin in the first place. First way: Create the cell with the option Selectable -> False ...

1

Using @Jagra's suggestion I was able to make a Manipulate function that was FAR neater than what I previously had (again, apologies for the unnecessarily long and messy code). Manipulate[ Graphics3D[{Red, Cylinder[]}, ViewAngle -> Dynamic[vAngle \[Degree]], ViewCenter -> {{1/2, 1/2, 1/2}, Dynamic[cen]}], {{vAngle, 30, "Zoom"}, 90, 10, 1}, {{cen, ...

1

@Kuba The mouse defaults to rotation, but I'm trying to use the mouse work for zoom by default, with a checkbox that would make it go back to rotation. I have my zoom function working nicely now, but when I try to put it into a Manipulate function, the checkbox makes it lose all functionality. Any ideas on implementing DynamicModule[{frac = 0, viewval = ...

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