def getSubMenu(self, context, selection, rootMenu, i, pitem): m = wx.Menu() if "wxMSW" in wx.PlatformInfo: bindmenu = rootMenu else: bindmenu = m isNotDefault = self.mod.spoolType is not None and self.mod.spoolAmount is not None cycleDefault = self.mod.getSpoolData(spoolOptions=SpoolOptions(SpoolType.SCALE, eos.config.settings['globalDefaultSpoolupPercentage'], True))[0] cycleCurrent = self.mod.getSpoolData(spoolOptions=SpoolOptions(SpoolType.SCALE, eos.config.settings['globalDefaultSpoolupPercentage'], False))[0] cycleMin = self.mod.getSpoolData(spoolOptions=SpoolOptions(SpoolType.SCALE, 0, True))[0] cycleMax = self.mod.getSpoolData(spoolOptions=SpoolOptions(SpoolType.SCALE, 1, True))[0] for cycle in range(cycleMin, cycleMax + 1): menuId = ContextMenu.nextID() # Show default only for current value and when not overriden if not isNotDefault and cycle == cycleDefault: text = "{} (default)".format(cycle) else: text = "{}".format(cycle) item = wx.MenuItem(m, menuId, text, kind=wx.ITEM_CHECK) bindmenu.Bind(wx.EVT_MENU, self.handleSpoolChange, item) m.Append(item) item.Check(isNotDefault and cycle == cycleCurrent) self.cycleMap[menuId] = cycle self.resetId = ContextMenu.nextID() item = wx.MenuItem(m, self.resetId, "Reset") bindmenu.Bind(wx.EVT_MENU, self.handleSpoolChange, item) m.Append(item) return m
def getSubMenu(self, context, selection, rootMenu, i, pitem): """ A note on the selection here: Most context menus act on a fit, so it's easy enough to get the active fit from the MainFrame instance. There's never been a reason to get info from another window, so there's not common way of doing this. However, we use this context menu within the Character Editor to apply implant sets to a character, so we need to access the character editor. It is for these reasons that I hijack the selection parameter when calling the menu and pass a pointer to the Character Editor. This way we can use it to get current editing character ID and apply the implants. It would probably be better to have a function on the MainFrame to get the currently open Character Editor (as we do with the item stats window). Eventually... Until then, this long ass note will remain to remind me why stupid shit like this is even happening. """ m = wx.Menu() bindmenu = rootMenu if "wxMSW" in wx.PlatformInfo else m sIS = s_ImplantSets.getInstance() implantSets = sIS.getImplantSetList() self.context = context if len(selection) == 1: self.selection = selection[0] # dirty hack here self.idmap = {} for set in implantSets: id = ContextMenu.nextID() mitem = wx.MenuItem(rootMenu, id, set.name) bindmenu.Bind(wx.EVT_MENU, self.handleSelection, mitem) self.idmap[id] = set m.Append(mitem) return m
def addOption(self, menu, option): label = option id = ContextMenu.nextID() self.optionIds[id] = option menuItem = wx.MenuItem(menu, id, label, kind=wx.ITEM_CHECK) menu.Bind(wx.EVT_MENU, self.handleMode, menuItem) return menuItem
def getSubMenu(self, context, selection, rootMenu, i, pitem): msw = True if "wxMSW" in wx.PlatformInfo else False self.context = context self.fitMenuItemIds = {} sub = wx.Menu() if len(self.__class__.commandFits) < 15: for fit in sorted(self.__class__.commandFits, key=lambda x: x.name): menuItem = self.addFit(rootMenu if msw else sub, fit, True) sub.Append(menuItem) else: typeDict = {} for fit in self.__class__.commandFits: shipName = fit.ship.item.name if shipName not in typeDict: typeDict[shipName] = [] typeDict[shipName].append(fit) for ship in sorted(typeDict.keys()): shipItem = wx.MenuItem(sub, ContextMenu.nextID(), ship) grandSub = wx.Menu() shipItem.SetSubMenu(grandSub) for fit in sorted(typeDict[ship], key=lambda x: x.name): fitItem = self.addFit(rootMenu if msw else grandSub, fit, False) grandSub.Append(fitItem) sub.Append(shipItem) return sub
def addFit(self, menu, fit, includeShip=False): label = fit.name if not includeShip else "({}) {}".format(fit.ship.item.name, fit.name) id = ContextMenu.nextID() self.fitMenuItemIds[id] = fit menuItem = wx.MenuItem(menu, id, label) menu.Bind(wx.EVT_MENU, self.handleSelection, menuItem) return menuItem
def getSubMenu(self, context, selection, rootMenu, i, pitem): msw = True if "wxMSW" in wx.PlatformInfo else False sMkt = service.Market.getInstance() effdata = sMkt.getSystemWideEffects() self.idmap = {} sub = wx.Menu() for swType in sorted(effdata): subItem = wx.MenuItem(sub, wx.ID_ANY, swType) grandSub = wx.Menu() subItem.SetSubMenu(grandSub) sub.AppendItem(subItem) for swData in sorted(effdata[swType], key=lambda tpl: tpl[2]): wxid = ContextMenu.nextID() swObj, swName, swClass = swData self.idmap[wxid] = (swObj, swName) grandSubItem = wx.MenuItem(grandSub, wxid, swClass) if msw: rootMenu.Bind(wx.EVT_MENU, self.handleSelection, grandSubItem) else: grandSub.Bind(wx.EVT_MENU, self.handleSelection, grandSubItem) grandSub.AppendItem(grandSubItem) return sub
def getSubMenu(self, context, selection, rootMenu, i, pitem): self.fitLookup = {} self.context = context sFit = Fit.getInstance() m = wx.Menu() # If on Windows we need to bind out events into the root menu, on other # platforms they need to go to our sub menu if "wxMSW" in wx.PlatformInfo: bindmenu = rootMenu else: bindmenu = m for page in self.mainFrame.fitMultiSwitch._pages: if isinstance(page, BlankPage): continue fit = sFit.getFit(page.activeFitID, basic=True) id = ContextMenu.nextID() mitem = wx.MenuItem(rootMenu, id, "{}: {}".format(fit.ship.item.name, fit.name)) bindmenu.Bind(wx.EVT_MENU, self.handleSelection, mitem) self.fitLookup[id] = fit m.Append(mitem) return m
def addMode(self, menu, mode): label = mode.item.name.rsplit()[-2] id = ContextMenu.nextID() self.modeIds[id] = mode menuItem = wx.MenuItem(menu, id, label, kind=wx.ITEM_RADIO) menu.Bind(wx.EVT_MENU, self.handleMode, menuItem) return menuItem
def addAbility(self, menu, ability): label = ability.name id = ContextMenu.nextID() self.abilityIds[id] = ability menuItem = wx.MenuItem(menu, id, label, kind=wx.ITEM_CHECK) menu.Bind(wx.EVT_MENU, self.handleMode, menuItem) return menuItem
def addFit(self, menu, fit, includeShip=False): label = fit.name if not includeShip else "({}) {}".format( fit.ship.item.name, fit.name) id = ContextMenu.nextID() self.fitMenuItemIds[id] = fit menuItem = wx.MenuItem(menu, id, label) menu.Bind(wx.EVT_MENU, self.handleSelection, menuItem) return menuItem
def getSubMenu(self, context, selection, rootMenu, i, pitem): self.moduleLookup = {} def get_metalevel(x): if "metaLevel" not in x.attributes: return 0 return x.attributes["metaLevel"].value def get_metagroup(x): return x.metaGroup.ID if x.metaGroup is not None else 0 m = wx.Menu() # If on Windows we need to bind out events into the root menu, on other # platforms they need to go to our sub menu if "wxMSW" in wx.PlatformInfo: bindmenu = rootMenu else: bindmenu = m # Sort items by metalevel, and group within that metalevel items = list(self.variations) items.sort(key=get_metalevel) items.sort(key=get_metagroup) group = None for item in items: # Apparently no metaGroup for the Tech I variant: if item.metaGroup is None: thisgroup = "Tech I" else: thisgroup = item.metaGroup.name if thisgroup != group: group = thisgroup id_ = ContextMenu.nextID() m.Append(id_, u'─ %s ─' % group) m.Enable(id_, False) id_ = ContextMenu.nextID() mitem = wx.MenuItem(rootMenu, id_, item.name) bindmenu.Bind(wx.EVT_MENU, self.handleModule, mitem) self.moduleLookup[id_] = item m.AppendItem(mitem) return m
def getSubMenu(self, context, selection, rootMenu, i, pitem): self.moduleLookup = {} def get_metalevel(x): if "metaLevel" not in x.attributes: return 0 return x.attributes["metaLevel"].value def get_metagroup(x): return x.metaGroup.ID if x.metaGroup is not None else 0 m = wx.Menu() # If on Windows we need to bind out events into the root menu, on other # platforms they need to go to our sub menu if "wxMSW" in wx.PlatformInfo: bindmenu = rootMenu else: bindmenu = m # Sort items by metalevel, and group within that metalevel items = list(self.variations) items.sort(key=get_metalevel) items.sort(key=get_metagroup) group = None for item in items: # Apparently no metaGroup for the Tech I variant: if item.metaGroup is None: thisgroup = "Tech I" else: thisgroup = item.metaGroup.name if thisgroup != group: group = thisgroup id = ContextMenu.nextID() m.Append(id, u'─ %s ─' % group) m.Enable(id, False) id = ContextMenu.nextID() mitem = wx.MenuItem(rootMenu, id, item.name) bindmenu.Bind(wx.EVT_MENU, self.handleModule, mitem) self.moduleLookup[id] = item m.AppendItem(mitem) return m
def processFlat(data, root, sub): for swData in sorted(data, key=lambda tpl: tpl[2]): wxid = ContextMenu.nextID() swObj, swName, swClass = swData self.idmap[wxid] = (swObj, swName) subItem = wx.MenuItem(sub, wxid, swClass) if msw: root.Bind(wx.EVT_MENU, self.handleSelection, subItem) else: sub.Bind(wx.EVT_MENU, self.handleSelection, subItem) sub.Append(subItem)
def addSkill(self, rootMenu, skill, i): if i < 0: label = "Not Learned" else: label = "Level %s" % i id = ContextMenu.nextID() self.skillIds[id] = (skill, i) menuItem = wx.MenuItem(rootMenu, id, label, kind=wx.ITEM_RADIO) rootMenu.Bind(wx.EVT_MENU, self.handleSkillChange, menuItem) return menuItem
def addCharge(self, menu, charge): id_ = ContextMenu.nextID() name = charge.name if charge is not None else "Empty" self.chargeIds[id_] = charge item = wx.MenuItem(menu, id_, name) menu.Bind(wx.EVT_MENU, self.handleAmmoSwitch, item) item.charge = charge if charge is not None and charge.iconID is not None: bitmap = BitmapLoader.getBitmap(charge.iconID, "icons") if bitmap is not None: item.SetBitmap(bitmap) return item
def addCharge(self, menu, charge): id = ContextMenu.nextID() name = charge.name if charge is not None else "Empty" self.chargeIds[id] = charge item = wx.MenuItem(menu, id, name) menu.Bind(wx.EVT_MENU, self.handleAmmoSwitch, item) item.charge = charge if charge is not None and charge.icon is not None: bitmap = BitmapLoader.getBitmap(charge.icon.iconFile, "icons") if bitmap is not None: item.SetBitmap(bitmap) return item
def getSubMenu(self, context, selection, rootMenu, i, pitem): msw = True if "wxMSW" in wx.PlatformInfo else False self.patternIds = {} self.context = context self.subMenus = OrderedDict() self.singles = [] sub = wx.Menu() for pattern in self.patterns: start, end = pattern.name.find('['), pattern.name.find(']') if start is not -1 and end is not -1: currBase = pattern.name[start + 1:end] # set helper attr setattr(pattern, "_name", pattern.name[end + 1:].strip()) if currBase not in self.subMenus: self.subMenus[currBase] = [] self.subMenus[currBase].append(pattern) else: self.singles.append(pattern) sub.AppendItem(self.addPattern(rootMenu if msw else sub, None)) # Add reset sub.AppendSeparator() # Single items, no parent for pattern in self.singles: sub.AppendItem(self.addPattern(rootMenu if msw else sub, pattern)) # Items that have a parent for menuName, patterns in self.subMenus.items(): # Create parent item for root menu that is simply name of parent item = wx.MenuItem(rootMenu, ContextMenu.nextID(), menuName) # Create menu for child items grandSub = wx.Menu() # sub.Bind(wx.EVT_MENU, self.handleResistSwitch) # Apply child menu to parent item item.SetSubMenu(grandSub) # Append child items to child menu for pattern in patterns: grandSub.AppendItem( self.addPattern(rootMenu if msw else grandSub, pattern)) sub.AppendItem(item) # finally, append parent item to root menu return sub
def buildMenu(self, data, local_menu, rootMenu, msw): for swType in sorted(data): subItem = wx.MenuItem(local_menu, wx.ID_ANY, swType) grandSub = wx.Menu() subItem.SetSubMenu(grandSub) local_menu.Append(subItem) for swData in sorted(data[swType], key=lambda tpl: tpl[2]): wxid = ContextMenu.nextID() swObj, swName, swClass = swData self.idmap[wxid] = (swObj, swName) grandSubItem = wx.MenuItem(grandSub, wxid, swClass) if msw: rootMenu.Bind(wx.EVT_MENU, self.handleSelection, grandSubItem) else: grandSub.Bind(wx.EVT_MENU, self.handleSelection, grandSubItem) grandSub.Append(grandSubItem)
def getSubMenu(self, context, selection, rootMenu, i, pitem): msw = True if "wxMSW" in wx.PlatformInfo else False self.patternIds = {} self.subMenus = OrderedDict() self.singles = [] sub = wx.Menu() for pattern in self.patterns: start, end = pattern.name.find('['), pattern.name.find(']') if start is not -1 and end is not -1: currBase = pattern.name[start+1:end] # set helper attr setattr(pattern, "_name", pattern.name[end+1:].strip()) if currBase not in self.subMenus: self.subMenus[currBase] = [] self.subMenus[currBase].append(pattern) else: self.singles.append(pattern) sub.AppendItem(self.addPattern(rootMenu if msw else sub, None)) # Add reset sub.AppendSeparator() # Single items, no parent for pattern in self.singles: sub.AppendItem(self.addPattern(rootMenu if msw else sub, pattern)) # Items that have a parent for menuName, patterns in self.subMenus.items(): # Create parent item for root menu that is simply name of parent item = wx.MenuItem(rootMenu, ContextMenu.nextID(), menuName) # Create menu for child items grandSub = wx.Menu() #sub.Bind(wx.EVT_MENU, self.handleResistSwitch) # Apply child menu to parent item item.SetSubMenu(grandSub) # Append child items to child menu for pattern in patterns: grandSub.AppendItem(self.addPattern(rootMenu if msw else grandSub, pattern)) sub.AppendItem(item) #finally, append parent item to root menu return sub
def addPattern(self, rootMenu, pattern): id = ContextMenu.nextID() name = getattr(pattern, "_name", pattern.name) if pattern is not None else "No Profile" self.patternIds[id] = pattern item = wx.MenuItem(rootMenu, id, name) rootMenu.Bind(wx.EVT_MENU, self.handleResistSwitch, item) # set pattern attr to menu item item.pattern = pattern # determine active pattern sFit = service.Fit.getInstance() fitID = self.mainFrame.getActiveFit() f = sFit.getFit(fitID) tr = f.targetResists if tr == pattern: bitmap = BitmapLoader.getBitmap("state_active_small", "gui") item.SetBitmap(bitmap) return item
def getSubMenu(self, context, selection, rootMenu, i, pitem): if selection[0].isMutated: return None msw = True if "wxMSW" in wx.PlatformInfo else False self.skillIds = {} sub = wx.Menu() mod = selection[0] menu = rootMenu if msw else sub for item in mod.item.mutaplasmids: label = item.item.name id = ContextMenu.nextID() self.eventIDs[id] = (item, mod) skillItem = wx.MenuItem(menu, id, label) menu.Bind(wx.EVT_MENU, self.handleMenu, skillItem) sub.Append(skillItem) return sub
def addPattern(self, rootMenu, pattern): id = ContextMenu.nextID() name = getattr(pattern, "_name", pattern.name) if pattern is not None else "No Profile" self.patternIds[id] = pattern item = wx.MenuItem(rootMenu, id, name) rootMenu.Bind(wx.EVT_MENU, self.handleResistSwitch, item) # set pattern attr to menu item item.pattern = pattern # determine active pattern sFit = Fit.getInstance() fitID = self.mainFrame.getActiveFit() f = sFit.getFit(fitID) tr = f.targetResists if tr == pattern: bitmap = BitmapLoader.getBitmap("state_active_small", "gui") item.SetBitmap(bitmap) return item
def getSubMenu(self, context, selection, rootMenu, i, pitem): msw = True if "wxMSW" in wx.PlatformInfo else False self.skillIds = {} sub = wx.Menu() for skill in self.skills: skillItem = wx.MenuItem(sub, ContextMenu.nextID(), skill.item.name) grandSub = wx.Menu() skillItem.SetSubMenu(grandSub) if skill.learned: bitmap = BitmapLoader.getBitmap("lvl%s" % skill.level, "gui") if bitmap is not None: skillItem.SetBitmap(bitmap) for i in xrange(-1, 6): levelItem = self.addSkill(rootMenu if msw else grandSub, skill, i) grandSub.AppendItem(levelItem) if (not skill.learned and i == -1) or (skill.learned and skill.level == i): levelItem.Check(True) sub.AppendItem(skillItem) return sub
def addSeperator(m, text): id_ = ContextMenu.nextID() m.Append(id_, '─ %s ─' % text) m.Enable(id_, False)
def getSubMenu(self, context, selection, rootMenu, i, pitem): self.moduleLookup = {} def get_metalevel(x): if "metaLevel" not in x.attributes: return 0 return x.attributes["metaLevel"].value def get_metagroup(x): return x.metaGroup.ID if x.metaGroup is not None else 0 def get_boosterrank(x): # If we're returning a lot of items, sort my name if len(self.variations) > 7: return x.name # Sort by booster chance to get some sort of pseudorank. elif 'boosterEffectChance1' in x.attributes: return x.attributes['boosterEffectChance1'].value # the "first" rank (Synth) doesn't have boosterEffectChance1. If we're not pulling back all boosters, return 0 for proper sorting else: return 0 m = wx.Menu() # If on Windows we need to bind out events into the root menu, on other # platforms they need to go to our sub menu if "wxMSW" in wx.PlatformInfo: bindmenu = rootMenu else: bindmenu = m # Sort items by metalevel, and group within that metalevel items = list(self.variations) print context if "implantItem" in context: # sort implants based on name items.sort(key=lambda x: x.name) elif "boosterItem" in context: # boosters don't have meta or anything concrete that we can rank by. Go by chance to inflict side effect items.sort(key=get_boosterrank) else: # sort by group and meta level items.sort(key=get_metalevel) items.sort(key=get_metagroup) group = None for item in items: # Apparently no metaGroup for the Tech I variant: if item.metaGroup is None: thisgroup = "Tech I" else: thisgroup = item.metaGroup.name if thisgroup != group and context not in ("implantItem", "boosterItem"): group = thisgroup id = ContextMenu.nextID() m.Append(id, u'─ %s ─' % group) m.Enable(id, False) id = ContextMenu.nextID() mitem = wx.MenuItem(rootMenu, id, item.name) bindmenu.Bind(wx.EVT_MENU, self.handleModule, mitem) self.moduleLookup[id] = item m.AppendItem(mitem) return m
def addSeperator(self, m, text): id = ContextMenu.nextID() m.Append(id, u'─ %s ─' % text) m.Enable(id, False)
def getSubMenu(self, context, selection, rootMenu, i, pitem): self.moduleLookup = {} sFit = Fit.getInstance() fit = sFit.getFit(self.mainFrame.getActiveFit()) def get_metalevel(x): if 'metaLevel' not in x.attributes: return 0 return x.attributes['metaLevel'].value def get_metagroup(x): # We want deadspace before officer mods remap = {5: 6, 6: 5} return remap.get(x.metaGroup.ID, x.metaGroup.ID) if x.metaGroup is not None else 0 def get_boosterrank(x): # If we're returning a lot of items, sort my name if len(self.variations) > 7: return x.name # Sort by booster chance to get some sort of pseudorank. elif 'boosterEffectChance1' in x.attributes: return x.attributes['boosterEffectChance1'].value # the "first" rank (Synth) doesn't have boosterEffectChance1. If we're not pulling back all boosters, return 0 for proper sorting else: return 0 m = wx.Menu() # If on Windows we need to bind out events into the root menu, on other # platforms they need to go to our sub menu if 'wxMSW' in wx.PlatformInfo: bindmenu = rootMenu else: bindmenu = m # Sort items by metalevel, and group within that metalevel items = list(self.variations) # Sort all items by name first items.sort(key=lambda x: x.name) # Do not do any extra sorting for implants if 'implantItem' in context: pass # Boosters don't have meta or anything concrete that we can rank by. Go by chance to inflict side effect elif 'boosterItem' in context: items.sort(key=get_boosterrank) else: # sort by group and meta level items.sort(key=get_metalevel) items.sort(key=get_metagroup) group = None for item in items: # Apparently no metaGroup for the Tech I variant: if 'subSystem' in item.effects: thisgroup = item.marketGroup.marketGroupName elif item.metaGroup is None: thisgroup = 'Tech I' else: thisgroup = item.metaGroup.name if thisgroup != group and context not in ('implantItem', 'boosterItem'): group = thisgroup id = ContextMenu.nextID() m.Append(id, '─ %s ─' % group) m.Enable(id, False) id = ContextMenu.nextID() mitem = wx.MenuItem(rootMenu, id, item.name) bindmenu.Bind(wx.EVT_MENU, self.handleModule, mitem) self.moduleLookup[id] = item, context m.Append(mitem) mitem.Enable(fit.canFit(item)) return m
def getSubMenu(self, context, selection, rootMenu, i, pitem): self.moduleLookup = {} def get_metalevel(x): if "metaLevel" not in x.attributes: return 0 return x.attributes["metaLevel"].value def get_metagroup(x): return x.metaGroup.ID if x.metaGroup is not None else 0 def get_boosterrank(x): # If we're returning a lot of items, sort my name if len(self.variations) > 7: return x.name # Sort by booster chance to get some sort of pseudorank. elif 'boosterEffectChance1' in x.attributes: return x.attributes['boosterEffectChance1'].value # the "first" rank (Synth) doesn't have boosterEffectChance1. If we're not pulling back all boosters, return 0 for proper sorting else: return 0 m = wx.Menu() # If on Windows we need to bind out events into the root menu, on other # platforms they need to go to our sub menu if "wxMSW" in wx.PlatformInfo: bindmenu = rootMenu else: bindmenu = m # Sort items by metalevel, and group within that metalevel items = list(self.variations) print(context) if "implantItem" in context: # sort implants based on name items.sort(key=lambda x: x.name) elif "boosterItem" in context: # boosters don't have meta or anything concrete that we can rank by. Go by chance to inflict side effect items.sort(key=get_boosterrank) else: # sort by group and meta level items.sort(key=get_metalevel) items.sort(key=get_metagroup) group = None for item in items: # Apparently no metaGroup for the Tech I variant: if "subSystem" in item.effects: thisgroup = item.marketGroup.marketGroupName elif item.metaGroup is None: thisgroup = "Tech I" else: thisgroup = item.metaGroup.name if thisgroup != group and context not in ("implantItem", "boosterItem"): group = thisgroup id = ContextMenu.nextID() m.Append(id, '─ %s ─' % group) m.Enable(id, False) id = ContextMenu.nextID() mitem = wx.MenuItem(rootMenu, id, item.name) bindmenu.Bind(wx.EVT_MENU, self.handleModule, mitem) self.moduleLookup[id] = item m.Append(mitem) return m