Fix some import issues, and save the scale factor on the BitmapLoader class (since it probably won't be changing?)

This commit is contained in:
blitzmann
2018-09-11 19:48:02 -04:00
parent 07b6c9c437
commit 7f02a078fd

View File

@@ -27,8 +27,6 @@ import wx
import config
import gui.mainFrame as mainFrame
from logbook import Logger
logging = Logger(__name__)
@@ -48,6 +46,8 @@ class BitmapLoader(object):
dont_use_cached_bitmaps = False
max_cached_bitmaps = 500
scaling_factor = None
@classmethod
def getStaticBitmap(cls, name, parent, location):
static = wx.StaticBitmap(parent)
@@ -78,18 +78,23 @@ class BitmapLoader(object):
@classmethod
def loadBitmap(cls, name, location):
filename = "{0}.png".format(name)
scale = int(mainFrame.MainFrame.getInstance().GetContentScaleFactor())
if scale == 1:
if cls.scaling_factor is None:
import gui.mainFrame
cls.scaling_factor = int(gui.mainFrame.MainFrame.getInstance().GetContentScaleFactor())
scale = cls.scaling_factor
print(cls.scaling_factor)
filenameScaled = "{0}@{1}x.png".format(name, scale)
img = cls.loadImage(filenameScaled, 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)
else:
filenameScaled = "{0}@{1}x.png".format(name, scale)
img = cls.loadImage(filenameScaled, location)
if img is None:
img = cls.loadImage(filename, location)
scale = 1
scale = 1
if img is None:
return None
bmp: wx.Bitmap = img.ConvertToBitmap()
if scale > 1:
bmp.SetSize((int(bmp.GetWidth()/scale), int(bmp.GetHeight()/scale)))