diff --git a/gui/builtinContextMenus/damagePattern.py b/gui/builtinContextMenus/damagePattern.py index 352340204..29a029389 100644 --- a/gui/builtinContextMenus/damagePattern.py +++ b/gui/builtinContextMenus/damagePattern.py @@ -24,7 +24,7 @@ class DamagePattern(ContextMenu): self.fit = sFit.getFit(fitID) self.patterns = sDP.getDamagePatternList() - self.patterns.sort(key=lambda p: (p.name not in ["Uniform","Selected Ammo"], p.name)) + self.patterns.sort(key=lambda p: (p.name not in ["Uniform", "Selected Ammo"], p.name)) self.patternIds = {} self.subMenus = OrderedDict() @@ -71,7 +71,6 @@ class DamagePattern(ContextMenu): def getSubMenu(self, context, selection, rootMenu, i, pitem): msw = True if "wxMSW" in wx.PlatformInfo else False - rootMenu.Bind(wx.EVT_MENU, self.handlePatternSwitch) # this bit is required for some reason if self.m[i] not in self.subMenus: # if we're trying to get submenu to something that shouldn't have one, @@ -79,10 +78,11 @@ class DamagePattern(ContextMenu): # our patternIds mapping, then return None for no submenu id = pitem.GetId() self.patternIds[id] = self.singles[i] + rootMenu.Bind(wx.EVT_MENU, self.handlePatternSwitch, pitem) if self.patternIds[id] == self.fit.damagePattern: bitmap = bitmapLoader.getBitmap("state_active_small", "icons") pitem.SetBitmap(bitmap) - return None + return False sub = wx.Menu() diff --git a/gui/contextMenu.py b/gui/contextMenu.py index 41bbca392..4ed09f9c1 100644 --- a/gui/contextMenu.py +++ b/gui/contextMenu.py @@ -73,18 +73,25 @@ class ContextMenu(object): rootMenu.info[id] = (m, fullContext, it) sub = m.getSubMenu(srcContext, selection, rootMenu, it, rootItem) + if sub is None: # if there is no sub menu, bind the handler to the rootItem rootMenu.Bind(wx.EVT_MENU, cls.handler, rootItem) - else: + elif sub: + # If sub exists and is not False, set submenu. + # Sub might return False when we have a mix of + # single menu items and submenus (see: damage profile + # context menu) + # # If there is a submenu, it is expected that the sub - # logic take care of it's own binding. No binding is - # done here + # logic take care of it's own bindings, including for + # any single root items. No binding is done here # # It is important to remember that when binding sub - # menu items, bind them to the rootMenu for proper - # event handling, eg: - # rootMenu.Bind(wx.EVE_MENU, self.handle, menuItem) + # menu items, the menu to bind to depends on platform. + # Windows should bind to rootMenu, and all other + # platforms should bind to sub menu. See existing + # implementations for examples. rootItem.SetSubMenu(sub) if bitmap is not None: