This commit is contained in:
blitmann
2015-01-04 17:19:53 -06:00
parent 18c86daea6
commit 487f65d62b
2 changed files with 16 additions and 9 deletions

View File

@@ -24,7 +24,7 @@ class DamagePattern(ContextMenu):
self.fit = sFit.getFit(fitID) self.fit = sFit.getFit(fitID)
self.patterns = sDP.getDamagePatternList() 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.patternIds = {}
self.subMenus = OrderedDict() self.subMenus = OrderedDict()
@@ -71,7 +71,6 @@ class DamagePattern(ContextMenu):
def getSubMenu(self, context, selection, rootMenu, i, pitem): def getSubMenu(self, context, selection, rootMenu, i, pitem):
msw = True if "wxMSW" in wx.PlatformInfo else False 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 self.m[i] not in self.subMenus:
# if we're trying to get submenu to something that shouldn't have one, # 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 # our patternIds mapping, then return None for no submenu
id = pitem.GetId() id = pitem.GetId()
self.patternIds[id] = self.singles[i] self.patternIds[id] = self.singles[i]
rootMenu.Bind(wx.EVT_MENU, self.handlePatternSwitch, pitem)
if self.patternIds[id] == self.fit.damagePattern: if self.patternIds[id] == self.fit.damagePattern:
bitmap = bitmapLoader.getBitmap("state_active_small", "icons") bitmap = bitmapLoader.getBitmap("state_active_small", "icons")
pitem.SetBitmap(bitmap) pitem.SetBitmap(bitmap)
return None return False
sub = wx.Menu() sub = wx.Menu()

View File

@@ -73,18 +73,25 @@ class ContextMenu(object):
rootMenu.info[id] = (m, fullContext, it) rootMenu.info[id] = (m, fullContext, it)
sub = m.getSubMenu(srcContext, selection, rootMenu, it, rootItem) sub = m.getSubMenu(srcContext, selection, rootMenu, it, rootItem)
if sub is None: if sub is None:
# if there is no sub menu, bind the handler to the rootItem # if there is no sub menu, bind the handler to the rootItem
rootMenu.Bind(wx.EVT_MENU, cls.handler, 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 # If there is a submenu, it is expected that the sub
# logic take care of it's own binding. No binding is # logic take care of it's own bindings, including for
# done here # any single root items. No binding is done here
# #
# It is important to remember that when binding sub # It is important to remember that when binding sub
# menu items, bind them to the rootMenu for proper # menu items, the menu to bind to depends on platform.
# event handling, eg: # Windows should bind to rootMenu, and all other
# rootMenu.Bind(wx.EVE_MENU, self.handle, menuItem) # platforms should bind to sub menu. See existing
# implementations for examples.
rootItem.SetSubMenu(sub) rootItem.SetSubMenu(sub)
if bitmap is not None: if bitmap is not None: