[ui] app: Rewrite thumbnail retrieval and handle more exceptions

This commit is contained in:
Candice Bentéjac 2025-01-22 15:52:22 +01:00
parent 18a0bdf8f3
commit 59afac317d

View file

@ -365,21 +365,27 @@ class MeshroomApp(QApplication):
Returns: Returns:
The path to the thumbnail if it could be found, an empty string otherwise The path to the thumbnail if it could be found, an empty string otherwise
""" """
thumbnail = ""
try: try:
with open(filepath) as file: with open(filepath) as file:
fileData = json.load(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]]: def _getRecentProjectFilesFromSettings(self) -> list[dict[str, str]]:
""" """