Fix a bug where a context menu was only able to be spawned once and not

reusable
This commit is contained in:
cncfanatics
2010-10-07 08:00:16 +02:00
parent 9190239c61
commit a4877514b4

View File

@@ -21,7 +21,6 @@ import wx
class ContextMenu(object):
menus = []
activeMenu = {}
@classmethod
def register(cls):
ContextMenu.menus.append(cls)
@@ -29,6 +28,7 @@ class ContextMenu(object):
@classmethod
def getMenu(cls, selection, *contexts):
menu = wx.Menu()
menu.info = {}
menu.selection = selection
empty = True
for i, context in enumerate(contexts):
@@ -44,7 +44,7 @@ class ContextMenu(object):
for it, text in enumerate(texts):
id = wx.NewId()
item = wx.MenuItem(menu, id, text)
cls.activeMenu[id] = (m, context, it)
menu.info[id] = (m, context, it)
menu.Bind(wx.EVT_MENU, cls.handler)
bitmap = m.getBitmap(context, selection)
@@ -61,14 +61,14 @@ class ContextMenu(object):
@classmethod
def handler(cls, event):
stuff = cls.activeMenu.get(event.Id)
menu = event.EventObject
stuff = menu.info.get(event.Id)
if stuff is not None:
m, context, i = stuff
selection = event.EventObject.selection
selection = menu.selection
if not hasattr(selection, "__iter__"):
selection = (selection,)
cls.activeMenu.clear()
m.activate(context, selection, i)
event.Skip()