3
$\begingroup$

my problem is with combining EventHandler and MouseAppearance. I want to change cursor appearance if I have primary button pressed over on item. But only then, after releasing it should be "Arrow" back.

I thought it should work:

Dynamic@MouseAppearance[#, mysz]&@EventHandler[
  Framed["A"], {"MouseUp" :> (mysz = "Arrow"), "MouseDown" :> (mysz = "A")}]

but it doesn't. The strange thing is, using "MouseClicked" it works, of course effect is different, it works like it should. Second thing is variable "mysz" is updated to "A" while button is pressed... but appearance doesn't change.

$\endgroup$

1 Answer 1

3
$\begingroup$

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 changed from your simple Framed to a Graphics object, and the code is certainly a bit more complicated that I would have liked:

DynamicModule[{
  mysz,
  mouse = 
   Graphics[{Arrowheads[1.4], Arrow[{{0, 0}, {-.5, 1}}]}, 
    ImageSize -> 8], n},
 mysz = mouse;
 Dynamic[MouseAppearance[#, " "] &@EventHandler[
    Graphics[{Orange, Rectangle[{0, 0}, {1, 1}], Black, Inset["A"], 
      Inset[mysz, MousePosition["Graphics", {-1, -1}]]}, 
     ImageSize -> 30, PlotRange -> {{0, 1}, {0, 1}}],
    {"MouseUp" :> (mysz = mouse),
     "MouseDown" :> (mysz = "A";)}]
  ]
 ]

The EvenetHandler logic is essentially the same as what you had already, but instead of mysz determining the appearance of the mouse, it sets the Inset that follows the MousePosition. This seems to work fine in principle, except for a new glitch that sometimes happens when the mouse position isn't correctly tracked as you enter the Graphics from the bottom. I just asked a separate question about this, and it could be that it's localized to version 9 of Mathematica and Mac OS X.

But apart from that, when I press the mouse it causes the simulated cursor to change to A immediately, and the A can also follow while dragging.

$\endgroup$
5
  • $\begingroup$ Yes, Your way works. But it won't help me. General idea is to have many items with this function on the field, those items will differ with size, position and mousegraphic. I had similar to Yours solution earlier but it is not convinient to use standard positioning. I want to set things buy Grid or sth. Thats why I left Graphics way. $\endgroup$
    – Kuba
    Jan 21, 2013 at 10:41
  • $\begingroup$ But what is even more important than the solution is WHY it does not work? :) In my opinion it should, something is wrong with MouseAppearance :/ $\endgroup$
    – Kuba
    Jan 21, 2013 at 16:14
  • $\begingroup$ Sorry it won't work for you, but I don't have any better insight into the mouse appearance while it's being pressed. I tried using the drag event instead, but that didn't work either (for mouse appearance). $\endgroup$
    – Jens
    Jan 21, 2013 at 17:06
  • $\begingroup$ Don't be sorry :) thank You for Your time. $\endgroup$
    – Kuba
    Jan 21, 2013 at 17:44
  • $\begingroup$ I decided to accept your answer finally because even though it is a workaround I couldn't find better then mine previous and I believe yours will be useful for future visitors. $\endgroup$
    – Kuba
    Sep 11, 2013 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.