Tag Info

Hot answers tagged

149

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

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


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


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

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


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

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

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

After trying to solve it for a day. I came to the point that looking for source code is necessary. The most interesting files I found here: /home/sh/po/mathematica_installed/AddOns/Packages/GUIKit/GUI/AuthorTools (i.e. you need check this path "/AddOns/Packages/GUIKit/GUI/AuthorTools" in the folder where Mathematica is installed to) These files have ...


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


2

Is this what you want? {DynamicModule[{flag = True}, ActionMenu["Set x", {"x = 1" :> ( flag = Not@flag; x = 1;)}, Enabled -> Dynamic[flag] ] ], Dynamic[x]} The EventHandler will take whatever ...


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


1

Something along the lines of ... a /: Set[a,x_]:=((OwnValues[a]={HoldPattern[a]:>x}; Print[{"a was set to:",x}]); a) a = 1 prints {a was set to:,1} a on its own is now 1. Extends what set does with an additional action which here is Print but ,in principle, could be anything.


1

Here's a way, using the built-in event handler Button: DynamicModule[{list = {{0, 0}, {2, 0}}, res}, Dynamic@{res, Graphics[{Red, Button[Dynamic@Disk[#, 1], res = #] & /@ list}]} ] An illustration of the use-case in the OP's comment to the question: DynamicModule[{list = {{0, 0}, {2, 0}}, r}, (r[#] = 1) & /@ list; Graphics[ {Red, ...


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

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

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



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