PodMaster has asked for the wisdom of the Perl Monks concerning the following question:

In wxPerl, if i use EVT_MENU($this, 123, sub{warn 1} ); to essentially "bind" that anon-sub to the 123 id, how do I go about unbinding it (is that even the right terminology)?

I've tried EVT_MENU($this, 123, sub{warn 2} ); EVT_MENU($this, 123, undef ); which doesn't work.

Is it even possible? (i suspect it's not, but I can't be sure)

If i don't get any replies, I will ask on the wxPerl mailing list.

Heere's test code

#!/usr/bin/perl use Wx; # every program must have a Wx::App-derive class package MyApp; use strict; use vars qw(@ISA); @ISA=qw(Wx::App); use Wx qw[ :everything ]; use Wx::Event qw[ EVT_MENU ]; # this is called automatically on object creation sub OnInit { my( $this ) = @_; # create new MyFrame my( $frame ) = MyFrame->new( "Accelerator Test", Wx::Point->new( 50, 50 ), Wx::Size->new( 450, 350 ) ); my $menuBar = new Wx::MenuBar(); my $menu = new Wx::Menu(); $menu->Append( 123, "&About...\tCtrl-A", "Show about dialog." ); EVT_MENU($frame, 123, sub { warn "PUCK"; print Dumper\@_; EVT_MENU($frame, 123, undef); EVT_MENU($frame, 123, sub{ die "DIFFERENT" }); } ); $menuBar->Append($menu, "Info"); $frame->SetMenuBar( $menuBar ); EVT_MENU($frame, 321, sub { warn "I'm FAKING IT, I'm FAKING IT GOOD +@_" } ); my $ACCL = new Wx::AcceleratorTable( [ wxACCEL_CTRL, 'C', ### NEEDS TO BE CAPITAL ( UNDOCUMENTED ) 123, ], [ wxACCEL_CTRL, 'Q', 321, ], ); $frame->SetAcceleratorTable($ACCL); # set it as top window (so the app will automatically close when # the last top window is closed) $this->SetTopWindow( $frame ); # show the frame $frame->Show( 1 ); 1; } package MyFrame; use strict; use vars qw(@ISA); @ISA=qw(Wx::Frame); use Wx qw(wxBITMAP_TYPE_BMP wxMENU_TEAROFF); # Parameters: title, position, size sub new { my( $class ) = shift; my( $this ) = $class->SUPER::new( undef, -1, $_[0], $_[1], $_[2] ); $this; } package main; # create an instance of the Wx::App-derived class my( $app ) = MyApp->new(); # start processing events $app->MainLoop();

____________________________________________________
** The Third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: How do i unbind a function bound by EVT_MENU ?
by PodMaster (Abbot) on Aug 11, 2002 at 16:41 UTC
    Well I went ahead and asked on the wxPerl mailing list, and this is what I got.
    Probably it should (because it DWIMs, and it is easier than what is below).
    For now:
    $frame->Disconnect( 123, -1, &Wx::wxEVT_COMMAND_MENU_SELECTED );
    
    If you need to disconnect other events, just look in lib/Wx/Event.pm
    for the definition, replace ->Connect with ->Disconnect and remove the
    last argument (the code reference).
    
    > Is it even possible? (i suspect it's not, but I can't be sure) 
    It is :-)
     
    HTH
    Mattia
    
    
    Well that works (kickass!), but I can't wait until it DWIM's as well ;)

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.