Tag Info

Hot answers tagged

156

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


7

You could add a trap to Documentation`HelpLookup which is called when F1 is pressed: Unprotect[Documentation`HelpLookup]; Documentation`HelpLookup[link_String, nb_, lang_String, opts : OptionsPattern[]] := Block[{$inblock = True}, lookedup[link] = True; Documentation`HelpLookup[link, nb, opts]] /; ! TrueQ[$inblock] You can add whatever code ...


7

The reason for this behaviour is that as soon as the cursor gets away from a particular vertex marker it leaves the associated EventHandler. Here's a work-around, let's associate the event handler with the whole Graph. We just need to take care of updating the proper pos. DynamicModule[{ind = 1, pos1 = {1, 0}/2, pos2 = {1, 1}/2, pos3 = {-1, 0}/2}, ...


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

I'm not sure how to increase the mouse polling rate in Dynamic-things, but I think it has been doing really well on my computer, which is Windows 8.1 with a regular USB mouse. Here is a simple code to measure the average polling rate of Dynamic: Module[{mplst = {}, time = 10}, PrintTemporary[DynamicWrapper["Measuring...", mplst ...


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


5

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


5

Tell me if that's what you are looking for. DynamicModule[{kk = {3 <-> 2, 1 <-> 2, 3 <-> 1}, col}, col[1] = Green; col[2] = Red; col[3] = Blue; Dynamic@Graph[{1, 2, 3}, EventHandler[#, {"MouseDown" :> If[CurrentValue["MouseClickCount"] == 2, (col[#2] = col[#2] /. {Red -> Green, Green -> Red, Blue -> ...


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


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

TL;DR In order to understand why what you did doesn't work you have to read up on how Mathematica stores information internally (DownValues and OwnValues), how and when Mathematica evaluates expressions (including how attributes affects that). There's a code halfway through that will do what you want. You asked "would somebody please help and point what ...


4

Kuba's answer is brilliant, but it has a rather ugly bit in it with a lot of unnecessary fooling around with Hold and ReleaseHold in order to make assignment to variables. As is so often the case with Mathematica, this fooling around with variables can be eliminated by working with a list, so I have reworked Kuba's answer to keep the vertex coordinates in a ...


3

Add PassEventsDown -> True: {DynamicModule[{nothing = 0}, EventHandler[ ActionMenu["Set x", {"x = 1" :> (x = 1;)}, Enabled -> True], {"MouseClicked" :> (nothing++)}, PassEventsDown -> True]], Dynamic[x]}


3

EventHandler can be used to catch various mouse events (mouse up, mouse down, mouse clicked, mouse dragged). Use MousePosition to add some intelligence. Example: DynamicModule[{col1 = Green, col2 = Blue}, Graphics[ { EventHandler[ Dynamic[{col1, Disk[]}, ImageSize -> Tiny], {"MouseClicked" :> (col1 = col1 /. {Red -> ...


3

The following seems to be a little faster, most likely because it avoids AppendTo. DynamicModule[{list = {}}, EventHandler[ Dynamic @ Framed @ Graphics[{Red, list}, PlotRange -> 2], {"MouseDragged" :> (list = Flatten @ {list, Point @ MousePosition["Graphics"]})}]] However, you might find it more to your liking to use lines rather than ...


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" -> "Utils`Private`onCollectionUpdate"]]; Thanks, Leonid!


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


3

To answer the second part of your question, you can use CurrentValue["EventKey"] to get the current key that is being pressed. Modifying your example above: EventHandler[InputField[], "KeyDown" :> Print[CurrentValue["EventKey"]]]


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

Using NotebookEventActions seems to work pretty well, but you still have to click once in the window after opening. You can click anywhere though and it allows you to use Deployed to disable all selections and it still works. So modify the code like below, copy it into new notebook, evaluate, delete input cell, then export entire notebook as CDF. pos = ...


3

There is ValueFunction, documented here. It allows detecting value changes for given symbols. For example, In[1]:= Experimental`ValueFunction[x] := Print["x changed"] In[2]:= x = 6 During evaluation of In[10]:= x changed Out[2]= 6


3

Based on the discussion in chat among Kuba halirutan and Michael Hale: trajnormal = RandomFunction[PoissonProcess[1], {0, 100}]["PathFunction"]; trajdiscount = RandomFunction[PoissonProcess[5], {0, 100}]["PathFunction"]; Clear[show] show[1, t_, step_] := ListLinePlot[ {#, 50 - trajnormal[#]}\[Transpose] & @ Range[0, t, step], ...


3

pos = {}; SetOptions[EvaluationNotebook[], NotebookEventActions :> { "MouseClicked" :> If[CurrentValue["AltKey"], AppendTo[pos, MousePosition[]]], PassEventsDown -> True}] Dynamic@MousePosition[] Dynamic@pos So, while pressing Alt you can click to store your positions.


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

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

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

This is my idea. If you give them the notebook with questions just put the following code in the cell with a question text (as InlineCell Alt+9) DynamicModule[{}, DynamicWrapper["test", Refresh[ help = DeleteDuplicates @ Join[help, "WindowTitle" /. NotebookInformation /@ Select[Notebooks[], ("DocumentType" /. NotebookInformation[#]) == "Help" ...



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