Skip to content

Commit 6af4af5

Browse files
committed
[ui] app: Rewrite thumbnail retrieval and handle more exceptions
1 parent 18a0bdf commit 6af4af5

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

meshroom/ui/app.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,21 +365,27 @@ def _retrieveThumbnailPath(self, filepath: str) -> str:
365365
Returns:
366366
The path to the thumbnail if it could be found, an empty string otherwise
367367
"""
368-
thumbnail = ""
369368
try:
370369
with open(filepath) as file:
371370
fileData = json.load(file)
372-
# Find the first CameraInit node
373-
fileData = fileData["graph"]
374-
for node in fileData:
375-
if fileData[node]["nodeType"] == "CameraInit" and fileData[node]["inputs"].get("viewpoints"):
376-
if len(fileData[node]["inputs"]["viewpoints"]) > 0:
377-
thumbnail = fileData[node]["inputs"]["viewpoints"][0]["path"]
378-
break
379-
except FileNotFoundError:
380-
pass
381371

382-
return thumbnail
372+
graphData = fileData.get("graph", {})
373+
for node in graphData.values():
374+
if node.get("nodeType") != "CameraInit":
375+
continue
376+
if viewpoints := node.get("inputs", {}).get("viewpoints"):
377+
return viewpoints[0].get("path", "")
378+
379+
except FileNotFoundError:
380+
logging.warning("File {} not found on disk.".format(filepath))
381+
except (json.JSONDecodeError, UnicodeDecodeError):
382+
logging.warning("Error while loading file {}.".format(filepath))
383+
except KeyError as err:
384+
logging.warning("The following key does not exist: {}".format(str(err)))
385+
except Exception as err:
386+
logging.warning("Exception: {}".format(str(err)))
387+
388+
return ""
383389

384390
def _getRecentProjectFilesFromSettings(self) -> list[dict[str, str]]:
385391
"""

0 commit comments

Comments
 (0)