From 59afac317dbe7ac571256ee68c9d28a860456ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Wed, 22 Jan 2025 15:52:22 +0100 Subject: [PATCH] [ui] app: Rewrite thumbnail retrieval and handle more exceptions --- meshroom/ui/app.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/meshroom/ui/app.py b/meshroom/ui/app.py index 6794c731..c9c7b5bd 100644 --- a/meshroom/ui/app.py +++ b/meshroom/ui/app.py @@ -365,21 +365,27 @@ class MeshroomApp(QApplication): Returns: The path to the thumbnail if it could be found, an empty string otherwise """ - thumbnail = "" try: with open(filepath) as file: fileData = json.load(file) - # Find the first CameraInit node - fileData = fileData["graph"] - for node in fileData: - if fileData[node]["nodeType"] == "CameraInit" and fileData[node]["inputs"].get("viewpoints"): - if len(fileData[node]["inputs"]["viewpoints"]) > 0: - thumbnail = fileData[node]["inputs"]["viewpoints"][0]["path"] - break - except FileNotFoundError: - pass - return thumbnail + graphData = fileData.get("graph", {}) + for node in graphData.values(): + if node.get("nodeType") != "CameraInit": + continue + if viewpoints := node.get("inputs", {}).get("viewpoints"): + return viewpoints[0].get("path", "") + + except FileNotFoundError: + logging.info("File {} not found on disk.".format(filepath)) + except (json.JSONDecodeError, UnicodeDecodeError): + logging.info("Error while loading file {}.".format(filepath)) + except KeyError as err: + logging.info("The following key does not exist: {}".format(str(err))) + except Exception as err: + logging.info("Exception: {}".format(str(err))) + + return "" def _getRecentProjectFilesFromSettings(self) -> list[dict[str, str]]: """