From 60f024fdb7d162c88c832a7f88cce338708b1827 Mon Sep 17 00:00:00 2001 From: Tron Date: Sun, 14 Oct 2018 15:47:58 -0500 Subject: [PATCH 1/4] Try loading smaller variants if scaled icons are missing. pyfa-org/Pyfa/#1769 --- gui/bitmap_loader.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gui/bitmap_loader.py b/gui/bitmap_loader.py index dd7b3cc00..f2409bc60 100644 --- a/gui/bitmap_loader.py +++ b/gui/bitmap_loader.py @@ -84,10 +84,15 @@ class BitmapLoader(object): if cls.scaling_factor is None: import gui.mainFrame cls.scaling_factor = int(gui.mainFrame.MainFrame.getInstance().GetContentScaleFactor()) - scale = cls.scaling_factor - filenameScaled = "{0}@{1}x.png".format(name, scale) - img = cls.loadImage(filenameScaled, location) + scaledNameTemplate = "{0}@{1}x.png" + img = None + scale = cls.scaling_factor + 1 + + while img is None and scale > 1: + scale -= 1 + filename = scaledNameTemplate.format(name, scale) + img = cls.loadImage(filename, location) if img is None: # can't find the scaled image, fallback to no scaling From 929b2dfb38b436a33c29ee38549e6bf9935f98cb Mon Sep 17 00:00:00 2001 From: Tron Date: Mon, 15 Oct 2018 05:35:28 -0500 Subject: [PATCH 2/4] Factored out scaled image loading into a method so CodeClimate (hopefully) stops complaining about cognitive complexity. --- gui/bitmap_loader.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/gui/bitmap_loader.py b/gui/bitmap_loader.py index f2409bc60..6319d5c0c 100644 --- a/gui/bitmap_loader.py +++ b/gui/bitmap_loader.py @@ -85,20 +85,14 @@ class BitmapLoader(object): import gui.mainFrame cls.scaling_factor = int(gui.mainFrame.MainFrame.getInstance().GetContentScaleFactor()) - scaledNameTemplate = "{0}@{1}x.png" - img = None - scale = cls.scaling_factor + 1 + scale = cls.scaling_factor - while img is None and scale > 1: + filename, img = cls.loadScaledBitmap(name, location, scale) + + while img is None and scale > 0: + # can't find the correctly scaled image, fallback to smaller scales scale -= 1 - filename = scaledNameTemplate.format(name, scale) - img = cls.loadImage(filename, location) - - if img is None: - # can't find the scaled image, fallback to no scaling - filename = "{0}.png".format(name) - img = cls.loadImage(filename, location) - scale = 1 + filename, img = cls.loadScaledBitmap(name, location, scale) if img is None: print(("Missing icon file: {0}/{1}".format(location, filename))) @@ -109,6 +103,23 @@ class BitmapLoader(object): bmp.SetSize((int(bmp.GetWidth()/scale), int(bmp.GetHeight()/scale))) return bmp + @classmethod + def loadScaledBitmap(cls, name, location, scale=0): + """Attempts to load a scaled bitmap. + + Args: + name (str): TypeID or basename of the image being requested. + location (str): Path to a location that may contain the image. + scale (int): Scale factor of the image variant to load. If ``0``, attempts to load the unscaled variant. + + Returns: + (str, wx.Image): Tuple of the filename that may have been loaded and the image at that location. The + filename will always be present, but the image may be ``None``. + """ + filename = "{0}@{1}x.png".format(name, scale) if scale > 0 else "{0}.png".format(name) + img = cls.loadImage(filename, location) + return filename, img + @classmethod def loadImage(cls, filename, location): if cls.archive: From 05ce8fbf1c41dfcad105ad8dc2f197d40c76340c Mon Sep 17 00:00:00 2001 From: Tron Date: Mon, 15 Oct 2018 05:43:56 -0500 Subject: [PATCH 3/4] Fixed flake8 complaints. --- gui/bitmap_loader.py | 2 +- service/port/efs.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/gui/bitmap_loader.py b/gui/bitmap_loader.py index 6319d5c0c..7a8d41a46 100644 --- a/gui/bitmap_loader.py +++ b/gui/bitmap_loader.py @@ -100,7 +100,7 @@ class BitmapLoader(object): bmp: wx.Bitmap = img.ConvertToBitmap() if scale > 1: - bmp.SetSize((int(bmp.GetWidth()/scale), int(bmp.GetHeight()/scale))) + bmp.SetSize((bmp.GetWidth() // scale, bmp.GetHeight() // scale)) return bmp @classmethod diff --git a/service/port/efs.py b/service/port/efs.py index ef224e850..b572e5376 100755 --- a/service/port/efs.py +++ b/service/port/efs.py @@ -83,7 +83,6 @@ class EfsPort(): @staticmethod def getPropData(fit, sFit): - fitID = fit.ID propMods = filter(lambda mod: mod.item and mod.item.group.name == "Propulsion Module", fit.modules) activePropWBloomFilter = lambda mod: mod.state > 0 and "signatureRadiusBonus" in mod.item.attributes propWithBloom = next(filter(activePropWBloomFilter, propMods), None) @@ -341,7 +340,7 @@ class EfsPort(): # This also covers non-bomb weapons with dps values and no hardpoints, most notably targeted doomsdays. typeing = "SmartBomb" # Targeted DDs are the only non drone/fighter weapon without an explict max range - if stats.item.group.name == 'Super Weapon' and stats.maxRange == None: + if stats.item.group.name == 'Super Weapon' and stats.maxRange is None: maxRange = 300000 else: maxRange = stats.maxRange From c5e8742838d4f47bd9ab12c0ffb086a037439f62 Mon Sep 17 00:00:00 2001 From: Tron Date: Mon, 15 Oct 2018 06:00:15 -0500 Subject: [PATCH 4/4] More flake8 fixes. --- gui/fitCommands/guiMetaSwap.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gui/fitCommands/guiMetaSwap.py b/gui/fitCommands/guiMetaSwap.py index c07facd37..d0c99b8bf 100644 --- a/gui/fitCommands/guiMetaSwap.py +++ b/gui/fitCommands/guiMetaSwap.py @@ -48,7 +48,6 @@ class GuiMetaSwapCommand(wx.Command): for x in selection: self.data.append(((FitChangeDroneVariationCommand, fitID, fit.drones.index(x), itemID),),) - def Do(self): for cmds in self.data: for cmd in cmds: