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