From 6a382c4445149cc36a282ff0240e91b4072c7786 Mon Sep 17 00:00:00 2001 From: blitzmann Date: Sun, 5 Nov 2017 01:51:05 -0400 Subject: [PATCH] More tweaks to getModifiedItemAttr and fix deprecation warning --- eos/modifiedAttributeDict.py | 10 ++-------- eos/saveddata/drone.py | 4 ++-- eos/saveddata/fighter.py | 8 ++++---- eos/saveddata/module.py | 23 +++++++++++------------ gui/builtinMarketBrowser/marketTree.py | 2 +- gui/builtinViewColumns/maxRange.py | 2 +- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/eos/modifiedAttributeDict.py b/eos/modifiedAttributeDict.py index 49026635f..e522c4487 100644 --- a/eos/modifiedAttributeDict.py +++ b/eos/modifiedAttributeDict.py @@ -31,20 +31,14 @@ class ItemAttrShortcut(object): def getModifiedItemAttr(self, key, default=0): return_value = self.itemModifiedAttributes.get(key) - if return_value is None and default is not None: - return_value = default - - return return_value if default is not None else None + return return_value or default class ChargeAttrShortcut(object): def getModifiedChargeAttr(self, key, default=0): return_value = self.chargeModifiedAttributes.get(key) - if return_value is None and default is not None: - return_value = default - - return return_value if default is not None else None + return return_value or default class ModifiedAttributeDict(collections.MutableMapping): diff --git a/eos/saveddata/drone.py b/eos/saveddata/drone.py index 36c969029..cf9309de2 100644 --- a/eos/saveddata/drone.py +++ b/eos/saveddata/drone.py @@ -168,7 +168,7 @@ class Drone(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): "energyDestabilizationRange", "empFieldRange", "ecmBurstRange", "maxRange") for attr in attrs: - maxRange = self.getModifiedItemAttr(attr) + maxRange = self.getModifiedItemAttr(attr, None) if maxRange is not None: return maxRange if self.charge is not None: @@ -184,7 +184,7 @@ class Drone(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): def falloff(self): attrs = ("falloff", "falloffEffectiveness") for attr in attrs: - falloff = self.getModifiedItemAttr(attr) + falloff = self.getModifiedItemAttr(attr, None) if falloff is not None: return falloff diff --git a/eos/saveddata/fighter.py b/eos/saveddata/fighter.py index 004e86149..695024540 100644 --- a/eos/saveddata/fighter.py +++ b/eos/saveddata/fighter.py @@ -199,12 +199,12 @@ class Fighter(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): "energyDestabilizationRange", "empFieldRange", "ecmBurstRange", "maxRange") for attr in attrs: - maxRange = self.getModifiedItemAttr(attr) + maxRange = self.getModifiedItemAttr(attr, None) if maxRange is not None: return maxRange if self.charge is not None: - delay = self.getModifiedChargeAttr("explosionDelay") - speed = self.getModifiedChargeAttr("maxVelocity") + delay = self.getModifiedChargeAttr("explosionDelay", None) + speed = self.getModifiedChargeAttr("maxVelocity", None) if delay is not None and speed is not None: return delay / 1000.0 * speed @@ -215,7 +215,7 @@ class Fighter(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): def falloff(self): attrs = ("falloff", "falloffEffectiveness") for attr in attrs: - falloff = self.getModifiedItemAttr(attr) + falloff = self.getModifiedItemAttr(attr, None) if falloff is not None: return falloff diff --git a/eos/saveddata/module.py b/eos/saveddata/module.py index fcec22dd4..41b8ba96d 100644 --- a/eos/saveddata/module.py +++ b/eos/saveddata/module.py @@ -251,7 +251,7 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): "ecmBurstRange", "warpScrambleRange", "cargoScanRange", "shipScanRange", "surveyScanRange") for attr in attrs: - maxRange = self.getModifiedItemAttr(attr) + maxRange = self.getModifiedItemAttr(attr, None) if maxRange is not None: return maxRange if self.charge is not None: @@ -280,7 +280,7 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): def falloff(self): attrs = ("falloffEffectiveness", "falloff", "shipScanFalloff") for attr in attrs: - falloff = self.getModifiedItemAttr(attr) + falloff = self.getModifiedItemAttr(attr, None) if falloff is not None: return falloff @@ -409,19 +409,19 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): fitsOnType = set() fitsOnGroup = set() - shipType = self.getModifiedItemAttr("fitsToShipType") + shipType = self.getModifiedItemAttr("fitsToShipType", None) if shipType is not None: fitsOnType.add(shipType) for attr in list(self.itemModifiedAttributes.keys()): if attr.startswith("canFitShipType"): - shipType = self.getModifiedItemAttr(attr) + shipType = self.getModifiedItemAttr(attr, None) if shipType is not None: fitsOnType.add(shipType) for attr in list(self.itemModifiedAttributes.keys()): if attr.startswith("canFitShipGroup"): - shipGroup = self.getModifiedItemAttr(attr) + shipGroup = self.getModifiedItemAttr(attr, None) if shipGroup is not None: fitsOnGroup.add(shipGroup) @@ -453,7 +453,7 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): return False # Check max group fitted - max = self.getModifiedItemAttr("maxGroupFitted") + max = self.getModifiedItemAttr("maxGroupFitted", None) if max is not None: current = 0 if self.owner != fit else -1 for mod in fit.modules: @@ -466,11 +466,10 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): # Check this only if we're told to do so if hardpointLimit: if self.hardpoint == Hardpoint.TURRET: - if (fit.ship.getModifiedItemAttr('turretSlotsLeft') or 0) - fit.getHardpointsUsed(Hardpoint.TURRET) < 1: + if fit.ship.getModifiedItemAttr('turretSlotsLeft') - fit.getHardpointsUsed(Hardpoint.TURRET) < 1: return False elif self.hardpoint == Hardpoint.MISSILE: - if (fit.ship.getModifiedItemAttr('launcherSlotsLeft') or 0) - fit.getHardpointsUsed( - Hardpoint.MISSILE) < 1: + if fit.ship.getModifiedItemAttr('launcherSlotsLeft') - fit.getHardpointsUsed(Hardpoint.MISSILE) < 1: return False return True @@ -500,7 +499,7 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): return True # Check if the local module is over it's max limit; if it's not, we're fine - maxGroupActive = self.getModifiedItemAttr("maxGroupActive") + maxGroupActive = self.getModifiedItemAttr("maxGroupActive", None) if maxGroupActive is None and projectedOnto is None: return True @@ -548,7 +547,7 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): chargeGroup = charge.groupID for i in range(5): - itemChargeGroup = self.getModifiedItemAttr('chargeGroup' + str(i)) + itemChargeGroup = self.getModifiedItemAttr('chargeGroup' + str(i), None) if itemChargeGroup is None: continue if itemChargeGroup == chargeGroup: @@ -559,7 +558,7 @@ class Module(HandledItem, HandledCharge, ItemAttrShortcut, ChargeAttrShortcut): def getValidCharges(self): validCharges = set() for i in range(5): - itemChargeGroup = self.getModifiedItemAttr('chargeGroup' + str(i)) + itemChargeGroup = self.getModifiedItemAttr('chargeGroup' + str(i), None) if itemChargeGroup is not None: g = eos.db.getGroup(int(itemChargeGroup), eager=("items.icon", "items.attributes")) if g is None: diff --git a/gui/builtinMarketBrowser/marketTree.py b/gui/builtinMarketBrowser/marketTree.py index 06b74d88a..ae8b77a85 100644 --- a/gui/builtinMarketBrowser/marketTree.py +++ b/gui/builtinMarketBrowser/marketTree.py @@ -88,7 +88,7 @@ class MarketTree(wx.TreeCtrl): for i in range(len(jumpList) - 1, -1, -1): target = jumpList[i] child, cookie = self.GetFirstChild(item) - while self.GetItemPyData(child) != target: + while self.GetItemData(child) != target: child, cookie = self.GetNextChild(item, cookie) item = child diff --git a/gui/builtinViewColumns/maxRange.py b/gui/builtinViewColumns/maxRange.py index 728e2b9bc..ef420c344 100644 --- a/gui/builtinViewColumns/maxRange.py +++ b/gui/builtinViewColumns/maxRange.py @@ -58,7 +58,7 @@ class MaxRange(ViewColumn): if isinstance(stuff, Mode): return "" - maxRange = stuff.maxRange if hasattr(stuff, "maxRange") else stuff.getModifiedItemAttr("maxRange") + maxRange = stuff.maxRange if hasattr(stuff, "maxRange") else stuff.getModifiedItemAttr("maxRange", None) falloff = stuff.falloff if falloff: falloff = "+%sm" % formatAmount(falloff, 3, 0, 3)