MCPcopy Index your code
hub / github.com/pyfa-org/Pyfa / AddCommandFit

Class AddCommandFit

gui/builtinContextMenus/commandFitAdd.py:13–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11
12
13class AddCommandFit(ContextMenuUnconditional):
14 # Get list of items that define a command fit
15 sMkt = Market.getInstance()
16 grp = sMkt.getGroup(1770) # Command burst group
17 commandTypeIDs = {item.ID for item in grp.items}
18 commandFits = []
19 menu = None
20
21 @classmethod
22 def fitChanged(cls, evt):
23 # This fires on a FitChanged event and updates the command fits whenever a command burst module is added or
24 # removed from a fit. evt.typeID can be either a int or a set (in the case of multiple module deletions)
25 if evt is None or (getattr(evt, 'action', None) in ("modadd", "moddel") and getattr(evt, 'typeID', None)):
26 if evt is not None:
27 ids = getattr(evt, 'typeID')
28 if not isinstance(ids, set):
29 ids = {ids}
30
31 if evt is None or not ids.isdisjoint(cls.commandTypeIDs):
32 # we are adding or removing an item that defines a command fit. Need to refresh fit list
33 cls.populateFits(evt)
34 evt.Skip()
35
36 @classmethod
37 def populateFits(cls, evt):
38 sFit = Fit.getInstance()
39 cls.commandFits = sFit.getFitsWithModules(cls.commandTypeIDs)
40
41 def __init__(self):
42 self.mainFrame = gui.mainFrame.MainFrame.getInstance()
43
44 def display(self, callingWindow, srcContext):
45 if self.mainFrame.getActiveFit() is None or len(self.__class__.commandFits) == 0 or srcContext != "commandView":
46 return False
47 return True
48
49 def getText(self, callingWindow, itmContext):
50 return _t("Command Fits")
51
52 def addFit(self, menu, fit, includeShip=False):
53 label = fit.name if not includeShip else "({}) {}".format(fit.ship.item.name, fit.name)
54 if not label:
55 label = ' '
56 id = ContextMenuUnconditional.nextID()
57 self.fitMenuItemIds[id] = fit
58 menuItem = wx.MenuItem(menu, id, label)
59 menu.Bind(wx.EVT_MENU, self.handleSelection, menuItem)
60 return menuItem
61
62 def getSubMenu(self, callingWindow, context, rootMenu, i, pitem):
63 msw = True if "wxMSW" in wx.PlatformInfo else False
64 self.context = context
65 self.fitMenuItemIds = {}
66
67 sub = wx.Menu()
68
69 if len(self.__class__.commandFits) < 15:
70 for fit in sorted(self.__class__.commandFits, key=lambda x: x.name):

Callers

nothing calls this directly

Calls 2

getGroupMethod · 0.80
getInstanceMethod · 0.45

Tested by

no test coverage detected