Develop method for context menu classes to signal that they should be displayed, but disabled. This will allow us to determine if a context menu exists for a certain context (stats panel, for example) without relying on old logic of not displaying them if fitting is not loaded.

This commit is contained in:
Ryan Holmes
2019-03-26 09:36:31 -04:00
parent ed7dd12258
commit fa0892032f
3 changed files with 26 additions and 2 deletions

View File

@@ -20,7 +20,11 @@ class DamagePattern(ContextMenu):
if not self.settings.get('damagePattern'):
return False
return srcContext == "resistancesViewFull" and self.mainFrame.getActiveFit() is not None
return srcContext == "resistancesViewFull"
@property
def enabled(self):
return self.mainFrame.getActiveFit() is not None
def getText(self, itmContext, selection):
sDP = import_DamagePattern.getInstance()

View File

@@ -17,7 +17,11 @@ class FactorReload(ContextMenu):
if not self.settings.get('factorReload'):
return False
return srcContext == "firepowerViewFull" and self.mainFrame.getActiveFit() is not None
return srcContext == "firepowerViewFull"
@property
def enabled(self):
return self.mainFrame.getActiveFit() is not None
def getText(self, itmContext, selection):
return "Factor in Reload Time"

View File

@@ -33,6 +33,16 @@ class ContextMenu(object):
def register(cls):
ContextMenu.menus.append(cls)
@classmethod
def hasMenu(cls, selection, *fullContexts):
for i, fullContext in enumerate(fullContexts):
srcContext = fullContext[0]
for menuHandler in cls.menus:
m = menuHandler()
if m.display(srcContext, selection):
return True
return False
@classmethod
def getMenu(cls, selection, *fullContexts):
"""
@@ -117,6 +127,7 @@ class ContextMenu(object):
if check is not None:
rootItem.Check(check)
rootItem.Enable(m.enabled)
empty = False
@@ -186,6 +197,11 @@ class ContextMenu(object):
'''If menu item is toggleable, this should return bool value'''
return None
@property
def enabled(self):
'''If menu item is enabled. Allows an item to display, but not be selected'''
return True
# noinspection PyUnresolvedReferences
from gui.builtinContextMenus import ( # noqa: E402,F401
openFit,