From fcf2d6a72c97a4a8cb54a191ef02327a0c51480a Mon Sep 17 00:00:00 2001 From: Andreas Zuber Date: Wed, 2 Oct 2019 13:16:13 +0200 Subject: [PATCH] Support loading images from zip This commit reenables the ability to load the images from a zip file instead of a directory structure. It is possible to set the location of this file via configforced.py --- config.py | 6 ++++++ gui/bitmap_loader.py | 20 +++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/config.py b/config.py index 8041ff2bc..dddd59edb 100644 --- a/config.py +++ b/config.py @@ -33,6 +33,7 @@ pyfaPath = None savePath = None saveDB = None gameDB = None +imgsZIP = None logPath = None loggingLevel = None logging_setup = None @@ -96,6 +97,7 @@ def defPaths(customSavePath=None): global savePath global saveDB global gameDB + global imgsZIP global saveInRoot global logPath global cipher @@ -155,6 +157,10 @@ def defPaths(customSavePath=None): if not gameDB: gameDB = os.path.join(pyfaPath, "eve.db") + imgsZIP = getattr(configforced, "imgsZIP", imgsZIP) + if not imgsZIP: + imgsZIP = os.path.join(pyfaPath, "imgs.zip") + if debug: logFile = "pyfa_debug.log" else: diff --git a/gui/bitmap_loader.py b/gui/bitmap_loader.py index 66bd7e98b..f6257ecba 100644 --- a/gui/bitmap_loader.py +++ b/gui/bitmap_loader.py @@ -19,6 +19,7 @@ import io import os.path +import zipfile from collections import OrderedDict # noinspection PyPackageRequirements @@ -32,15 +33,12 @@ pyfalog = Logger(__name__) class BitmapLoader: - # try: - # archive = zipfile.ZipFile(os.path.join(config.pyfaPath, 'imgs.zip'), 'r') - # logging.info("Using zipped image files.") - # except (IOError, TypeError): - # logging.info("Using local image files.") - # archive = None - - pyfalog.info("Using local image files.") - archive = None + try: + archive = zipfile.ZipFile(config.imgsZIP, 'r') + pyfalog.info("Using zipped image files.") + except (IOError, TypeError): + pyfalog.info("Using local image files.") + archive = None cached_bitmaps = OrderedDict() dont_use_cached_bitmaps = False @@ -131,8 +129,8 @@ class BitmapLoader: try: img_data = cls.archive.read(path) - sbuf = io.StringIO(img_data) - return wx.ImageFromStream(sbuf) + bbuf = io.BytesIO(img_data) + return wx.Image(bbuf) except KeyError: pyfalog.warning("Missing icon file from zip: {0}".format(path)) else: