Rework target profile and damage pattern menus to use regular ticks
This commit is contained in:
@@ -5,7 +5,6 @@ import wx
|
||||
|
||||
import gui.globalEvents as GE
|
||||
import gui.mainFrame
|
||||
from gui.bitmap_loader import BitmapLoader
|
||||
from gui.contextMenu import ContextMenuUnconditional
|
||||
from service.damagePattern import DamagePattern as import_DamagePattern
|
||||
from service.fit import Fit
|
||||
@@ -58,7 +57,7 @@ class ChangeDamagePattern(ContextMenuUnconditional):
|
||||
name = getattr(pattern, "_name", pattern.name) if pattern is not None else "No Profile"
|
||||
|
||||
self.patternIds[id] = pattern
|
||||
menuItem = wx.MenuItem(rootMenu, id, name)
|
||||
menuItem = wx.MenuItem(rootMenu, id, name, kind=wx.ITEM_CHECK)
|
||||
rootMenu.Bind(wx.EVT_MENU, self.handlePatternSwitch, menuItem)
|
||||
|
||||
# set pattern attr to menu item
|
||||
@@ -70,13 +69,24 @@ class ChangeDamagePattern(ContextMenuUnconditional):
|
||||
fit = sFit.getFit(fitID)
|
||||
if fit:
|
||||
dp = fit.damagePattern
|
||||
if dp == pattern:
|
||||
bitmap = BitmapLoader.getBitmap("state_active_small", "gui")
|
||||
menuItem.SetBitmap(bitmap)
|
||||
return menuItem
|
||||
checked = dp is pattern
|
||||
else:
|
||||
checked = False
|
||||
return menuItem, checked
|
||||
|
||||
def isChecked(self, i):
|
||||
try:
|
||||
single = self.singles[i]
|
||||
except IndexError:
|
||||
return super().isChecked(i)
|
||||
if self.fit and single is self.fit.damagePattern:
|
||||
return True
|
||||
return False
|
||||
|
||||
def getSubMenu(self, callingWindow, context, rootMenu, i, pitem):
|
||||
msw = True if "wxMSW" in wx.PlatformInfo else False
|
||||
# Attempt to remove attribute which carries info if non-sub-items should
|
||||
# be checked or not
|
||||
self.checked = None
|
||||
|
||||
if self.m[i] not in self.subMenus:
|
||||
# if we're trying to get submenu to something that shouldn't have one,
|
||||
@@ -85,16 +95,16 @@ class ChangeDamagePattern(ContextMenuUnconditional):
|
||||
id = pitem.GetId()
|
||||
self.patternIds[id] = self.singles[i]
|
||||
rootMenu.Bind(wx.EVT_MENU, self.handlePatternSwitch, pitem)
|
||||
if self.fit and self.patternIds[id] == self.fit.damagePattern:
|
||||
bitmap = BitmapLoader.getBitmap("state_active_small", "gui")
|
||||
pitem.SetBitmap(bitmap)
|
||||
return False
|
||||
|
||||
sub = wx.Menu()
|
||||
|
||||
# Items that have a parent
|
||||
msw = "wxMSW" in wx.PlatformInfo
|
||||
for pattern in self.subMenus[self.m[i]]:
|
||||
sub.Append(self.addPattern(rootMenu if msw else sub, pattern))
|
||||
mitem, checked = self.addPattern(rootMenu if msw else sub, pattern)
|
||||
sub.Append(mitem)
|
||||
mitem.Check(checked)
|
||||
|
||||
return sub
|
||||
|
||||
|
||||
@@ -26,8 +26,7 @@ class FactorReload(ContextMenuUnconditional):
|
||||
fitIDs = Fit.getInstance().toggleFactorReload()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitIDs=tuple(fitIDs)))
|
||||
|
||||
@property
|
||||
def checked(self):
|
||||
def isChecked(self, i):
|
||||
sFit = Fit.getInstance()
|
||||
return sFit.serviceFittingOptions["useGlobalForceReload"]
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ class GraphDmgApplyProjectedMenu(ContextMenuUnconditional):
|
||||
self.settings.set('applyProjected', not self.settings.get('applyProjected'))
|
||||
wx.PostEvent(self.mainFrame, GE.GraphOptionChanged())
|
||||
|
||||
@property
|
||||
def checked(self):
|
||||
def isChecked(self, i):
|
||||
return self.settings.get('applyProjected')
|
||||
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ class GraphDmgIgnoreResistsMenu(ContextMenuUnconditional):
|
||||
self.settings.set('ignoreResists', not self.settings.get('ignoreResists'))
|
||||
wx.PostEvent(self.mainFrame, GE.GraphOptionChanged())
|
||||
|
||||
@property
|
||||
def checked(self):
|
||||
def isChecked(self, i):
|
||||
return self.settings.get('ignoreResists')
|
||||
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ class ItemGroupPrice(ContextMenuUnconditional, metaclass=ABCMeta):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitIDs=(fitID,)))
|
||||
|
||||
@property
|
||||
def checked(self):
|
||||
def isChecked(self, i):
|
||||
return self.settings.get(self.optionName)
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import wx
|
||||
|
||||
import gui.globalEvents as GE
|
||||
import gui.mainFrame
|
||||
from gui.bitmap_loader import BitmapLoader
|
||||
from gui.contextMenu import ContextMenuUnconditional
|
||||
from service.fit import Fit
|
||||
from service.targetProfile import TargetProfile as svc_TargetProfile
|
||||
@@ -46,7 +45,7 @@ class TargetProfileSwitcher(ContextMenuUnconditional):
|
||||
name = getattr(pattern, '_name', pattern.name) if pattern is not None else 'No Profile'
|
||||
|
||||
self.patternIds[id] = pattern
|
||||
item = wx.MenuItem(rootMenu, id, name)
|
||||
item = wx.MenuItem(rootMenu, id, name, kind=wx.ITEM_CHECK)
|
||||
rootMenu.Bind(wx.EVT_MENU, self.handleResistSwitch, item)
|
||||
|
||||
# set pattern attr to menu item
|
||||
@@ -58,10 +57,9 @@ class TargetProfileSwitcher(ContextMenuUnconditional):
|
||||
f = sFit.getFit(fitID)
|
||||
tr = f.targetProfile
|
||||
|
||||
if tr == pattern:
|
||||
bitmap = BitmapLoader.getBitmap('state_active_small', 'gui')
|
||||
item.SetBitmap(bitmap)
|
||||
return item
|
||||
checked = tr == pattern
|
||||
|
||||
return item, checked
|
||||
|
||||
def getSubMenu(self, callingWindow, context, rootMenu, i, pitem):
|
||||
msw = True if 'wxMSW' in wx.PlatformInfo else False
|
||||
@@ -81,13 +79,17 @@ class TargetProfileSwitcher(ContextMenuUnconditional):
|
||||
self.subMenus[currBase].append(pattern)
|
||||
else:
|
||||
self.singles.append(pattern)
|
||||
|
||||
sub.Append(self.addPattern(rootMenu if msw else sub, None)) # Add reset
|
||||
# Add reset
|
||||
mitem, checked = self.addPattern(rootMenu if msw else sub, None)
|
||||
sub.Append(mitem)
|
||||
mitem.Check(checked)
|
||||
sub.AppendSeparator()
|
||||
|
||||
# Single items, no parent
|
||||
for pattern in self.singles:
|
||||
sub.Append(self.addPattern(rootMenu if msw else sub, pattern))
|
||||
mitem, checked = self.addPattern(rootMenu if msw else sub, pattern)
|
||||
sub.Append(mitem)
|
||||
mitem.Check(checked)
|
||||
|
||||
# Items that have a parent
|
||||
for menuName, patterns in list(self.subMenus.items()):
|
||||
@@ -103,7 +105,9 @@ class TargetProfileSwitcher(ContextMenuUnconditional):
|
||||
|
||||
# Append child items to child menu
|
||||
for pattern in patterns:
|
||||
grandSub.Append(self.addPattern(rootMenu if msw else grandSub, pattern))
|
||||
mitem, checked = self.addPattern(rootMenu if msw else grandSub, pattern)
|
||||
grandSub.Append(mitem)
|
||||
mitem.Check(checked)
|
||||
sub.Append(item) # finally, append parent item to root menu
|
||||
|
||||
return sub
|
||||
|
||||
@@ -97,8 +97,8 @@ class ContextMenu(metaclass=ABCMeta):
|
||||
multiple = not isinstance(bitmap, wx.Bitmap)
|
||||
for it, text in enumerate(texts):
|
||||
id = ContextMenu.nextID()
|
||||
check = m.checked
|
||||
rootItem = wx.MenuItem(rootMenu, id, text, kind=wx.ITEM_NORMAL if m.checked is None else wx.ITEM_CHECK)
|
||||
check = m.isChecked(it)
|
||||
rootItem = wx.MenuItem(rootMenu, id, text, kind=wx.ITEM_NORMAL if check is None else wx.ITEM_CHECK)
|
||||
rootMenu.info[id] = (m, callingWindow, fullContext, it)
|
||||
|
||||
sub = m._baseGetSubMenu(callingWindow, srcContext, mainItem, selection, rootMenu, it, rootItem)
|
||||
@@ -180,8 +180,7 @@ class ContextMenu(metaclass=ABCMeta):
|
||||
|
||||
return ContextMenu._ids[ContextMenu._idxid]
|
||||
|
||||
@property
|
||||
def checked(self):
|
||||
def isChecked(self, i):
|
||||
'''If menu item is toggleable, this should return bool value'''
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user