Beispiel #1
0
 def addAbility(self, menu, ability):
     label = ability.name
     id = ContextMenuCombined.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
Beispiel #2
0
 def addAbility(self, menu, ability):
     label = ability.name
     id = ContextMenuCombined.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
Beispiel #3
0
 def _addCharge(self, menu, charge):
     id_ = ContextMenuCombined.nextID()
     name = charge.name if charge is not None else 'Empty'
     self.chargeEventMap[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
Beispiel #4
0
    def addCharge(self, menu, charge):
        id_ = ContextMenuCombined.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
Beispiel #5
0
 def addOption(self, menu, optionLabel):
     id = ContextMenuCombined.nextID()
     self.optionIds[id] = optionLabel
     menuItem = wx.MenuItem(menu, id, optionLabel, kind=wx.ITEM_CHECK)
     menu.Bind(wx.EVT_MENU, self.handleMode, menuItem)
     return menuItem
Beispiel #6
0
 def addSeperator(m, text):
     id_ = ContextMenuCombined.nextID()
     m.Append(id_, '─ %s ─' % text)
     m.Enable(id_, False)
Beispiel #7
0
 def addSeperator(m, text):
     id_ = ContextMenuCombined.nextID()
     m.Append(id_, '─ %s ─' % text)
     m.Enable(id_, False)
Beispiel #8
0
    def getSubMenu(self, context, mainItem, 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.mainVariations) > 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.mainVariations)
        # 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 = ContextMenuCombined.nextID()
                m.Append(id, '─ %s ─' % group)
                m.Enable(id, False)

            id = ContextMenuCombined.nextID()
            mitem = wx.MenuItem(rootMenu, id, item.name)
            bindmenu.Bind(wx.EVT_MENU, self.handleSwitch, mitem)

            self.moduleLookup[id] = item, context
            m.Append(mitem)
            mitem.Enable(fit.canFit(item))

        return m
Beispiel #9
0
    def getSubMenu(self, context, mainItem, 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.mainVariations) > 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

        # Do not show abyssal items
        items = list(i for i in self.mainVariations if i.metaGroup is None or i.metaGroup.ID != 15)
        # Sort items by metalevel, and group within that metalevel
        # 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 = ContextMenuCombined.nextID()
                m.Append(id, '─ %s ─' % group)
                m.Enable(id, False)

            id = ContextMenuCombined.nextID()
            mitem = wx.MenuItem(rootMenu, id, item.name)
            bindmenu.Bind(wx.EVT_MENU, self.handleSwitch, mitem)

            self.moduleLookup[id] = item, context
            m.Append(mitem)
            mitem.Enable(fit.canFit(item))

        return m