Factored out scaled image loading into a method so CodeClimate (hopefully) stops complaining about cognitive complexity.
This commit is contained in:
@@ -85,20 +85,14 @@ class BitmapLoader(object):
|
|||||||
import gui.mainFrame
|
import gui.mainFrame
|
||||||
cls.scaling_factor = int(gui.mainFrame.MainFrame.getInstance().GetContentScaleFactor())
|
cls.scaling_factor = int(gui.mainFrame.MainFrame.getInstance().GetContentScaleFactor())
|
||||||
|
|
||||||
scaledNameTemplate = "{0}@{1}x.png"
|
scale = cls.scaling_factor
|
||||||
img = None
|
|
||||||
scale = cls.scaling_factor + 1
|
|
||||||
|
|
||||||
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
|
scale -= 1
|
||||||
filename = scaledNameTemplate.format(name, scale)
|
filename, img = cls.loadScaledBitmap(name, location, 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
|
|
||||||
|
|
||||||
if img is None:
|
if img is None:
|
||||||
print(("Missing icon file: {0}/{1}".format(location, filename)))
|
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)))
|
bmp.SetSize((int(bmp.GetWidth()/scale), int(bmp.GetHeight()/scale)))
|
||||||
return bmp
|
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
|
@classmethod
|
||||||
def loadImage(cls, filename, location):
|
def loadImage(cls, filename, location):
|
||||||
if cls.archive:
|
if cls.archive:
|
||||||
|
|||||||
Reference in New Issue
Block a user