Skip to content

Commit

Permalink
Develop method for context menu classes to signal that they should be…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
blitzmann committed Mar 26, 2019
1 parent ed7dd12 commit fa08920
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion gui/builtinContextMenus/damagePattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def display(self, srcContext, selection):
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()
Expand Down
6 changes: 5 additions & 1 deletion gui/builtinContextMenus/factorReload.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def display(self, srcContext, selection):
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"
Expand Down
16 changes: 16 additions & 0 deletions gui/contextMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -117,6 +127,7 @@ def getMenu(cls, selection, *fullContexts):

if check is not None:
rootItem.Check(check)
rootItem.Enable(m.enabled)

empty = False

Expand Down Expand Up @@ -186,6 +197,11 @@ def checked(self):
'''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,
Expand Down

0 comments on commit fa08920

Please sign in to comment.