Skip to content

Commit

Permalink
[ui] app: Rewrite thumbnail retrieval and handle more exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
cbentejac committed Jan 22, 2025
1 parent 18a0bdf commit 59afac3
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions meshroom/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,21 +365,27 @@ def _retrieveThumbnailPath(self, filepath: str) -> str:
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]]:
"""
Expand Down

0 comments on commit 59afac3

Please sign in to comment.