Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Here is the bit of code causing me issues:

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

No matter how hard I try to click the ActionMenu does not open at all.

Removing the {"MouseClicked" :> (nothing++)} allows to open the ActionMenu:

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

The aim of the code would be to Enable/Disable the ActionMenu after x = 1 is clicked in this example.

What am I doing wrong in the first bit of code?

share|improve this question
1  
DynamicModule[{x}, {EventHandler[ ActionMenu["Set x", {"x = 1" :> (x = 1;)}, Enabled -> Dynamic[x =!= 1]]], Dynamic[x]}] Simple, but not sure if this is what you want –  belisarius Dec 22 '13 at 18:01
add comment

2 Answers 2

up vote 3 down vote accepted

Add PassEventsDown -> True:

{DynamicModule[{nothing = 0}, 
  EventHandler[
   ActionMenu["Set x", {"x = 1" :> (x = 1;)}, 
    Enabled -> True], {"MouseClicked" :> (nothing++)}, 
   PassEventsDown -> True]], Dynamic[x]}
share|improve this answer
    
I forgot the PassEventsDown option... It's so natural... –  Silvia Dec 22 '13 at 18:00
    
Thanks @ both of you. MichaelE2 strictly replies the "why it does not open" question and Silvia replies the "how to disable after one click" question. Since the main issue was to answer "why it does not open anymore" I've accepted this answer. But once again, thanks for you two :) –  Öskå Dec 22 '13 at 18:37
add comment

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 it wraps around as mouse event trigger, and I think the "MouseClicked" event is hijacked by it so ActionMenu doesn't see the event.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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