def GetPaperDollResource(typeID, gender=None): assets = filter(lambda a: a.typeID == typeID, cfg.paperdollResources) if len(assets) == 0: log.LogWarn( 'PreviewWnd::PreviewType - No asset matched the typeID {}'.format( typeID)) return None default_asset = first(assets) unisex_asset = first_or_default(assets, lambda a: a.resGender is None, default_asset) return first_or_default(assets, lambda a: a.resGender == gender, unisex_asset)
def GetPaperDollResource(typeID, gender=None): """ Returns the paper doll resource for the given typeID and gender. If there's at least one resource available for this type then a resource will always be returned with the following priority order: - Resource with the requested gender - Resource marked as unisex (gender == None) - The first resource in the list of resources Returns None if no resource could be found for this type. """ assets = filter(lambda a: a.typeID == typeID, cfg.paperdollResources) if len(assets) == 0: log.LogWarn( 'PreviewWnd::PreviewType - No asset matched the typeID {}'.format( typeID)) return None default_asset = first(assets) unisex_asset = first_or_default(assets, lambda a: a.resGender is None, default_asset) return first_or_default(assets, lambda a: a.resGender == gender, unisex_asset)
def UpdateText(self): context = self.previewContainer.context if not hasattr(context, 'typeID'): return groupID = evetypes.GetGroupID(context.typeID) categoryID = evetypes.GetCategoryID(context.typeID) title = evetypes.GetName(context.typeID) if hasattr(context, 'itemID'): bp = sm.GetService('michelle').GetBallpark() if bp: slim = bp.GetInvItem(context.itemID) if slim: title = slim.name self.title.text = title subtitle = '' if categoryID != invconst.categoryApparel: scene = self.previewContainer.sceneContainer.scene model = first_or_default(getattr(scene, 'objects', []), None) if model: radius = round(model.GetBoundingSphereRadius() * 2, 0) if groupID in invconst.turretModuleGroups or groupID in invconst.turretAmmoGroups: subtitle = localization.GetByLabel( 'UI/Preview/ShipSubLabelNoRace', groupName=evetypes.GetGroupName(context.typeID), length=FmtDist(radius)) else: raceID = evetypes.GetRaceID(context.typeID) race = cfg.races.Get( raceID) if raceID in cfg.races else None if race is None: subtitle = localization.GetByLabel( 'UI/Preview/ShipSubLabelNoRace', groupName=evetypes.GetGroupName(context.typeID), length=FmtDist(radius)) else: raceName = localization.GetByMessageID(race.raceNameID) subtitle = localization.GetByLabel( 'UI/Preview/ShipSubLabel', raceName=raceName, groupName=evetypes.GetGroupName(context.typeID), length=FmtDist(radius)) self.subtitle.text = subtitle if categoryID == invconst.categoryApparel: self.descCont.Show() description = evetypes.GetDescription(context.typeID) or '' description = re.sub('<b>|</b>|\\r', '', description) description = re.sub('\\n', '<br>', description) self.desc.text = description
def testAll(self): self.assertEqual(1, it.first_or_default([1, 2, 3])) self.assertEqual(3, it.first_or_default((1, 2, 3), lambda x: x > 2)) self.assertEqual(it.first_or_default([], default=5), 5) self.assertFalse(it.first_or_default([1, 2, 3], lambda x: x > 4))