Problems with popup menu in wxNotebook and wxGrid

First of all, apologies for sending this request one more time and not
replying in time. I thought it did not come to this mailing list. And I
was checking several times. Novice mistake.

It works!

You don't bind the menu event to a handler until after you popup the
menu. self.PopupMenu is modal so it doesn't return until after a menu
item has been selected or the menu has been dismissed. So you need to
bind the menu event handlers before you popup the menu, and you probably
only want to bind them once otherwise you'll be adding a new binding to
the event table each time you show the menu.

No I fully understand why my app behaved so weirdly. And I also understand the meaning of the
code in Demo application. It was there!

def OnRightClick(self, event):
        self.log.WriteText("OnRightClick\n")

        # only do this part the first time so the events are only bound once
        
        if not hasattr(self, "popupID1"):
            self.popupID1 = wx.NewId()

Which platform and version?

To the bug:

Version:

from wxPython.wx import wxVERSION
print wxVERSION

(2, 5, 3, 2, 'pre')

Platform:
vronskij@spartan:~$ uname -a
Linux spartan 2.6.10-5-386 #1 Tue Apr 5 12:12:40 UTC 2005 i686 GNU/Linux
(Ubuntu Linux)

I booted into the Windows XP system and have tried the code there. Version 2.5.5.1. Here I could not
even change the wxNotebook position. Here it might be my error, cause I do not program in windows that much.
Last change in wxNotebook was in 2.5.5.1 version as per recent changes record.

jan bodnar wrote:

It works!

No I fully understand why my app behaved so weirdly. And I also understand the meaning of the
code in Demo application. It was there!

def OnRightClick(self, event):
        self.log.WriteText("OnRightClick\n")

        # only do this part the first time so the events are only bound once
                if not hasattr(self, "popupID1"):
            self.popupID1 = wx.NewId()

I found the code in the demo to be pretty clunky. I don't like how it re-creates everything if you want similar menus to be popped up on different windows. Check out the enclosed demo. try right-clicking on the colored panels.

-CHB

Popup.py (2.55 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Chris Barker wrote:

Check out the enclosed demo. try right-clicking on
the colored panels.

OOPS. I cleaned it up a fixed a little bug. Use this one instead.

-CHB

Popup.py (1.67 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov