From 09bcd4d68e302272cb8a5f966506aadb6328fafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Fri, 12 Jun 2020 00:14:08 +0200 Subject: [PATCH] Allow different return types in get_preview for saves. --- basic_features/basic_save_game_info.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/basic_features/basic_save_game_info.py b/basic_features/basic_save_game_info.py index a1c8b57..abf0892 100644 --- a/basic_features/basic_save_game_info.py +++ b/basic_features/basic_save_game_info.py @@ -1,6 +1,7 @@ # -*- encoding: utf-8 -*- import os +import sys from typing import Callable @@ -64,9 +65,26 @@ class BasicGameSaveGameInfoWidget(mobase.ISaveGameInfoWidget): self.setPalette(palette) def setSave(self, filename): - pixmap = QPixmap(self._get_preview(filename)) + # Resize the label to (0, 0) to hide it: + self._label.resize(0, 0) + + # Retrieve the pixmap: + value = self._get_preview(filename) + if isinstance(value, str): + pixmap = QPixmap(value) + elif isinstance(value, QPixmap): + pixmap = value + else: + print( + "Failed to retrieve the preview, bad return type: {}.".format( + type(value) + ), + file=sys.stderr, + ) + return + + # Scale the pixmap and show it: pixmap = pixmap.scaledToWidth(320) - self.setWindowTitle("The Title: {}".format(filename)) self._label.setPixmap(pixmap) self.resize(pixmap.width(), pixmap.height())