Merge pull request #621 from blitzmann/context-menu-ids
Context menu ids
This commit is contained in:
@@ -60,7 +60,7 @@ class ChangeAffectingSkills(ContextMenu):
|
||||
else:
|
||||
label = "Level %s" % i
|
||||
|
||||
id = wx.NewId()
|
||||
id = ContextMenu.nextID()
|
||||
self.skillIds[id] = (skill, i)
|
||||
menuItem = wx.MenuItem(rootMenu, id, label, kind=wx.ITEM_RADIO)
|
||||
rootMenu.Bind(wx.EVT_MENU, self.handleSkillChange, menuItem)
|
||||
@@ -72,7 +72,7 @@ class ChangeAffectingSkills(ContextMenu):
|
||||
sub = wx.Menu()
|
||||
|
||||
for skill in self.skills:
|
||||
skillItem = wx.MenuItem(sub, wx.NewId(), skill.item.name)
|
||||
skillItem = wx.MenuItem(sub, ContextMenu.nextID(), skill.item.name)
|
||||
grandSub = wx.Menu()
|
||||
skillItem.SetSubMenu(grandSub)
|
||||
if skill.learned:
|
||||
|
||||
@@ -48,7 +48,7 @@ class DamagePattern(ContextMenu):
|
||||
return self.m
|
||||
|
||||
def addPattern(self, rootMenu, pattern):
|
||||
id = wx.NewId()
|
||||
id = ContextMenu.nextID()
|
||||
name = getattr(pattern, "_name", pattern.name) if pattern is not None else "No Profile"
|
||||
|
||||
self.patternIds[id] = pattern
|
||||
|
||||
@@ -20,7 +20,7 @@ class FighterAbility(ContextMenu):
|
||||
|
||||
def addAbility(self, menu, ability):
|
||||
label = ability.name
|
||||
id = wx.NewId()
|
||||
id = ContextMenu.nextID()
|
||||
self.abilityIds[id] = ability
|
||||
menuItem = wx.MenuItem(menu, id, label, kind=wx.ITEM_CHECK)
|
||||
menu.Bind(wx.EVT_MENU, self.handleMode, menuItem)
|
||||
|
||||
@@ -42,7 +42,7 @@ class ImplantSets(ContextMenu):
|
||||
self.idmap = {}
|
||||
|
||||
for set in implantSets:
|
||||
id = wx.NewId()
|
||||
id = ContextMenu.nextID()
|
||||
mitem = wx.MenuItem(rootMenu, id, set.name)
|
||||
bindmenu.Bind(wx.EVT_MENU, self.handleSelection, mitem)
|
||||
self.idmap[id] = set
|
||||
|
||||
@@ -67,11 +67,11 @@ class MetaSwap(ContextMenu):
|
||||
|
||||
if thisgroup != group:
|
||||
group = thisgroup
|
||||
id = wx.NewId()
|
||||
id = ContextMenu.nextID()
|
||||
m.Append(id, u'─ %s ─' % group)
|
||||
m.Enable(id, False)
|
||||
|
||||
id = wx.NewId()
|
||||
id = ContextMenu.nextID()
|
||||
mitem = wx.MenuItem(rootMenu, id, item.name)
|
||||
bindmenu.Bind(wx.EVT_MENU, self.handleModule, mitem)
|
||||
self.moduleLookup[id] = item
|
||||
|
||||
@@ -98,7 +98,7 @@ class ModuleAmmoPicker(ContextMenu):
|
||||
return map(self.numericConverter, parts)
|
||||
|
||||
def addCharge(self, menu, charge):
|
||||
id = wx.NewId()
|
||||
id = ContextMenu.nextID()
|
||||
name = charge.name if charge is not None else "Empty"
|
||||
self.chargeIds[id] = charge
|
||||
item = wx.MenuItem(menu, id, name)
|
||||
@@ -112,7 +112,7 @@ class ModuleAmmoPicker(ContextMenu):
|
||||
return item
|
||||
|
||||
def addSeperator(self, m, text):
|
||||
id = wx.NewId()
|
||||
id = ContextMenu.nextID()
|
||||
m.Append(id, u'─ %s ─' % text)
|
||||
m.Enable(id, False)
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class TacticalMode(ContextMenu):
|
||||
|
||||
def addMode(self, menu, mode):
|
||||
label = mode.item.name.rsplit()[-2]
|
||||
id = wx.NewId()
|
||||
id = ContextMenu.nextID()
|
||||
self.modeIds[id] = mode
|
||||
menuItem = wx.MenuItem(menu, id, label, kind=wx.ITEM_RADIO)
|
||||
menu.Bind(wx.EVT_MENU, self.handleMode, menuItem)
|
||||
|
||||
@@ -39,7 +39,7 @@ class TargetResists(ContextMenu):
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
|
||||
def addPattern(self, rootMenu, pattern):
|
||||
id = wx.NewId()
|
||||
id = ContextMenu.nextID()
|
||||
name = getattr(pattern, "_name", pattern.name) if pattern is not None else "No Profile"
|
||||
|
||||
self.patternIds[id] = pattern
|
||||
@@ -89,7 +89,7 @@ class TargetResists(ContextMenu):
|
||||
# Items that have a parent
|
||||
for menuName, patterns in self.subMenus.items():
|
||||
# Create parent item for root menu that is simply name of parent
|
||||
item = wx.MenuItem(rootMenu, wx.NewId(), menuName)
|
||||
item = wx.MenuItem(rootMenu, ContextMenu.nextID(), menuName)
|
||||
|
||||
# Create menu for child items
|
||||
grandSub = wx.Menu()
|
||||
|
||||
@@ -29,7 +29,7 @@ class WhProjector(ContextMenu):
|
||||
sub.AppendItem(subItem)
|
||||
|
||||
for swData in sorted(effdata[swType], key=lambda tpl: tpl[2]):
|
||||
wxid = wx.NewId()
|
||||
wxid = ContextMenu.nextID()
|
||||
swObj, swName, swClass = swData
|
||||
self.idmap[wxid] = (swObj, swName)
|
||||
grandSubItem = wx.MenuItem(grandSub, wxid, swClass)
|
||||
|
||||
@@ -18,9 +18,14 @@
|
||||
#===============================================================================
|
||||
|
||||
import wx
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class ContextMenu(object):
|
||||
menus = []
|
||||
_ids = [] #[wx.NewId() for x in xrange(200)] # init with decent amount
|
||||
_idxid = -1
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
@@ -44,6 +49,8 @@ class ContextMenu(object):
|
||||
(('marketItemGroup', 'Implant'),)
|
||||
(('fittingShip', 'Ship'),)
|
||||
"""
|
||||
cls._idxid = -1
|
||||
debug_start = len(cls._ids)
|
||||
|
||||
rootMenu = wx.Menu()
|
||||
rootMenu.info = {}
|
||||
@@ -68,7 +75,7 @@ class ContextMenu(object):
|
||||
bitmap = m.getBitmap(srcContext, selection)
|
||||
multiple = not isinstance(bitmap, wx.Bitmap)
|
||||
for it, text in enumerate(texts):
|
||||
id = wx.NewId()
|
||||
id = cls.nextID()
|
||||
rootItem = wx.MenuItem(rootMenu, id, text)
|
||||
rootMenu.info[id] = (m, fullContext, it)
|
||||
|
||||
@@ -109,6 +116,10 @@ class ContextMenu(object):
|
||||
if amount > 0 and i != len(fullContexts) - 1:
|
||||
rootMenu.AppendSeparator()
|
||||
|
||||
debug_end = len(cls._ids)
|
||||
if (debug_end - debug_start):
|
||||
logger.debug("%d new IDs created for this menu" % (debug_end - debug_start))
|
||||
|
||||
return rootMenu if empty is False else None
|
||||
|
||||
@classmethod
|
||||
@@ -134,6 +145,22 @@ class ContextMenu(object):
|
||||
def getSubMenu(self, context, selection, rootMenu, i, pitem):
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def nextID(cls):
|
||||
"""
|
||||
Fetches an ID from the pool of IDs allocated to Context Menu.
|
||||
If we don't have enough ID's to fulfill request, create new
|
||||
ID and add it to the pool.
|
||||
|
||||
See GH Issue #589
|
||||
"""
|
||||
cls._idxid += 1
|
||||
|
||||
if cls._idxid >= len(cls._ids): # We don't ahve an ID for this index, create one
|
||||
cls._ids.append(wx.NewId())
|
||||
|
||||
return cls._ids[cls._idxid]
|
||||
|
||||
def getText(self, context, selection):
|
||||
"""
|
||||
getText should be implemented in child classes, and should return either
|
||||
|
||||
Reference in New Issue
Block a user