Huub Peters <[email protected]> wrote:
You need to supply the ID of the menu item, not the item itself:

Wx::Event::EVT_MENU( $self, 71000, \&OnNewReserved);
Wx::Event::EVT_MENU( $self, 72000, \&OnModReserved);

I already tried but it does not work as well. I think I'm doing something
wrong elsewhere.
I also tried to derive a custom class with menu definition and menu command
event handlers, but the result doesn't change, i.e. menu pops up and menu
command not executed.
I forgot to mention I use Activestate perl 5.10 under windows and wxperl
0.86.1
Is there any code samples available on that?

Thank you for your hint about menu IDs :)

cheers
Alessandro



2009/4/8 Huub Peters <[email protected]>

> Alessandro wrote:
>
>  # define context menu
>> $this->{ResSecCtx}     = Wx::Menu->new();
>> $this->{NewResSec}     = $self->{ResSecCtx}->Append( 71000, "New Reserved
>> Section...", "" );
>> $this->{ModResSec}     = $self->{ResSecCtx}->Append( 72000, "Modify
>> Reserved
>> Section...", "" );
>> ...
>> # bind events
>> Wx::Event::EVT_MENU( $self, $self->{NewResSec}, \&OnNewReserved);
>> Wx::Event::EVT_MENU( $self, $self->{ModResSec}, \&OnModReserved);
>>
>
> You need to supply the ID of the menu item, not the item itself:
>
> Wx::Event::EVT_MENU( $self, 71000, \&OnNewReserved);
> Wx::Event::EVT_MENU( $self, 72000, \&OnModReserved);
>
> <snip>
>
>  The context menu is correctly displayed but it seems that no event is sent
>> when I select a choice because event handlers are not executed.
>> Could you help me to understand the problem?
>>
>> Thank you
>> Alessandro
>>
>>
> As a sidenote (and a personal preference), I found that using a combination
> of constants and Wx::NewId() helps the readability of the code and avoids id
> clutter, especially when your projects get bigger.
>
> Eg:
> use constant ID_MENU_EXIT => Wx::NewId();
> use constant ID_TRANSFER_QUEUE => Wx::NewId();
> ....
> Wx::Event::EVT_MENU( $self, ID_MENU_EXIT, \&OnExit);
> Wx::Event::EVT_MENU( $self, ID_TRANSFER_QUEUE, \&OnTransferQueue);
>
> ...again, this is personal preference  :)
>
> Hope it helps,
>
> Cheers,
> Huub Peters
>

Reply via email to