Problems with popup menu in wxNotebook and wxGrid

Hi,

Currently I work on a spreadsheet like application. I have implemented a
context menu in wxGrid (cut,copy, paste) and wxNotebook(insert, delete,
remove new sheet). Strange thing is that all my commands work, but only
on second time. e.g when I right click on the wxGrid/wxNotebook, menu
appears, I do some command - nothing happens.
When I do it second time, it works. And it works afterward all right ...
What might be wrong?

Code example:

class MyNotebook(wxNotebook):
def __init__(self, parent):
wxNotebook.__init__(self, parent, -1, pos = wxDefaultPosition, size =
wxDefaultSize, style=wxBOTTOM)

self.Bind(EVT_RIGHT_DOWN, self.OnContextMenu)

def OnContextMenu(self, event):
g = self.GetSelection()
c, d = event.GetPosition() # workaround
a, b = self.GetSizeTuple()
e, f = self.HitTest((c, b-d))

if e < 0:
return

if g != e and e >= 0:
self.SetSelection(e)

contextmenu = wxMenu()
contextmenu.Append(11, "Insert")
contextmenu.Append(12, "Remove")
self.PopupMenu(contextmenu, (c, b-d))
contextmenu.Destroy()

self.Bind(EVT_MENU, self.OnInsertSheet, id = 11)
EVT_MENU(self, 12, self.OnDeleteSheet)

def OnInsertSheet(self, event):
wxBell() # beeps only on second time

def OnDeleteSheet(self, event):
wxBell()

Thanks,

jan bodnar

PS: there might be a bug in wxNotebook widget. when you create a
wxNotebook with style wxBOTTOM and implement a popupmenu the classical
way -self.PopupMenu(menu, event.GetPosition())- the popup menu appears
wrongly very high. therefore I did a workaround.