Skip to content

Explicit templates file management - #3153

Open
nicolas-lambert-tc wants to merge 4 commits into
developfrom
feature/explicit-templates-file-management
Open

Explicit templates file management#3153
nicolas-lambert-tc wants to merge 4 commits into
developfrom
feature/explicit-templates-file-management

Conversation

@nicolas-lambert-tc

@nicolas-lambert-tc nicolas-lambert-tc commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

image image

Description

This PR makes Meshroom template files explicit in the project flow. Templates can now be detected from their file extension or serialized header, opened through a dedicated template flow, tracked in their own recent-files list, and clearly identified in the GraphEditor when an opened graph comes from a template.

Features list

  • Add the ".mgt" extension to explicitly represent template files
  • Old templates files (".mg" with template:true) are still loadable
  • Display a visible GraphEditor indicator when the current graph was opened from a template.

Implementation remarks

Template detection is centralized in meshroom.core.files so both core and UI code use the same rules.
Opening a template still initializes an unsaved graph, but the source template filepath is stored separately on the graph model for UI feedback and recent-template tracking.
The GraphEditor indicator is intentionally lightweight and disappears once the graph becomes a regular saved project.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for template files with the .mgt extension, allowing users to save, load, and manage templates separately from standard .mg project files. Key changes include a new files.py utility module, updated template discovery in core modules, and UI enhancements such as a 'Recent Templates' menu, a template badge, and improved drag-and-drop handling. The review feedback highlights several high-quality improvement opportunities, including preventing a fall-through bug in file drop handling, specifying UTF-8 encoding when reading files, refactoring path operations to be more Pythonic, optimizing loops that parse file extensions, and adding defensive null checks in QML to avoid potential runtime errors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread meshroom/ui/scene.py
Comment on lines +783 to +799
if filesByType["meshroomTemplates"]:
if len(filesByType["meshroomTemplates"]) > 1:
self.error.emit(
Message(
"Too Many Meshroom Templates",
"A single Meshroom template (.mgt file) can be opened at once."
)
)
elif filesByType["meshroomScenes"]:
self.error.emit(
Message(
"Mixed Meshroom Files",
"Do not mix Meshroom projects and templates."
)
)
else:
return self.loadTemplate(filesByType["meshroomTemplates"][0])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Add return False immediately after emitting errors for too many templates or mixed files. Otherwise, the function will fall through and still attempt to load the scene file if exactly one scene is present in the dropped files, bypassing the error handling.

Suggested change
if filesByType["meshroomTemplates"]:
if len(filesByType["meshroomTemplates"]) > 1:
self.error.emit(
Message(
"Too Many Meshroom Templates",
"A single Meshroom template (.mgt file) can be opened at once."
)
)
elif filesByType["meshroomScenes"]:
self.error.emit(
Message(
"Mixed Meshroom Files",
"Do not mix Meshroom projects and templates."
)
)
else:
return self.loadTemplate(filesByType["meshroomTemplates"][0])
if filesByType["meshroomTemplates"]:
if len(filesByType["meshroomTemplates"]) > 1:
self.error.emit(
Message(
"Too Many Meshroom Templates",
"A single Meshroom template (.mgt file) can be opened at once."
)
)
return False
elif filesByType["meshroomScenes"]:
self.error.emit(
Message(
"Mixed Meshroom Files",
"Do not mix Meshroom projects and templates."
)
)
return False
else:
return self.loadTemplate(filesByType["meshroomTemplates"][0])

Comment thread meshroom/core/files.py
if extensionLower(path) != MESHROOM_LEGACY_TEMPLATE_EXTENSION:
return False
try:
with open(path) as file:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Specify encoding="utf-8" when opening the file to prevent potential UnicodeDecodeError on platforms where the default system encoding is not UTF-8 (such as Windows).

Suggested change
with open(path) as file:
with open(path, encoding="utf-8") as file:

Comment thread meshroom/core/files.py Outdated
Comment thread meshroom/core/__init__.py Outdated
Comment thread meshroom/core/plugins.py Outdated
Comment thread meshroom/ui/qml/Application.qml Outdated
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.07563% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.43%. Comparing base (bad1f37) to head (ee14941).
⚠️ Report is 84 commits behind head on develop.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
meshroom/multiview.py 33.33% 6 Missing ⚠️
meshroom/core/graph.py 75.00% 4 Missing ⚠️
meshroom/core/files.py 88.88% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3153      +/-   ##
===========================================
+ Coverage    85.39%   85.43%   +0.04%     
===========================================
  Files           73       75       +2     
  Lines        11498    11607     +109     
===========================================
+ Hits          9819     9917      +98     
- Misses        1679     1690      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nicolas-lambert-tc
nicolas-lambert-tc force-pushed the feature/explicit-templates-file-management branch 4 times, most recently from e6659e4 to c24ebd3 Compare June 30, 2026 16:33
@nicolas-lambert-tc
nicolas-lambert-tc marked this pull request as ready for review July 1, 2026 07:23
Copilot AI review requested due to automatic review settings July 1, 2026 07:23
@nicolas-lambert-tc nicolas-lambert-tc self-assigned this Jul 1, 2026
@nicolas-lambert-tc nicolas-lambert-tc added the feature new feature (proposed as PR or issue planned by dev) label Jul 1, 2026
@nicolas-lambert-tc nicolas-lambert-tc added this to the Meshroom 2026.1.0 milestone Jul 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces explicit Meshroom template file handling by adding the .mgt extension, centralizing template detection rules in core, and wiring UI flows to open templates as unsaved graphs while tracking template origin separately for indicators and recent-files.

Changes:

  • Added meshroom.core.files helpers/constants to detect templates via .mgt extension or legacy .mg header metadata.
  • Updated UI load/drop flows to route template files through a dedicated “open template” path, track graph.templateFilepath, and maintain a separate recent-templates list.
  • Added UI affordances (GraphEditor stripes + toolbar badge) to indicate when the active graph originates from a template.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_template_files.py Adds unit tests for extension/header-based template detection, template init behavior, and template discovery.
meshroom/core/files.py Introduces centralized template/project extension constants and detection/extension helpers.
meshroom/core/init.py Updates pipeline template discovery to support .mgt and legacy .mg templates.
meshroom/core/plugins.py Updates plugin template discovery to support .mgt and legacy .mg templates with deterministic ordering.
meshroom/core/graph.py Adds templateFilepath to Graph model and clears it when the graph becomes a regular saved project.
meshroom/multiview.py Extends dropped-file categorization to include Meshroom templates separately from projects.
meshroom/ui/scene.py Routes loads to template flow, adds template drop handling, and updates unknown-extension reporting.
meshroom/ui/graph.py Ensures save-as uses the correct extension for projects vs templates via withExtension.
meshroom/ui/app.py Adds recent-templates persistence and QML-facing properties/slots for template recents.
meshroom/ui/qml/main.qml Adds template recent-file tracking when opening a file at startup.
meshroom/ui/qml/WorkspaceView.qml Updates drop-to-open behavior and recent-file updates for projects vs templates.
meshroom/ui/qml/Application.qml Updates template dialogs/actions/menus and adds a template badge indicator in the UI.
meshroom/ui/qml/GraphEditor/GraphEditor.qml Adds background stripe indicator for template graphs and recognizes .mgt in drag/drop.
meshroom/ui/qml/ImageGallery/ImageListView.qml Treats templates like projects for drag/drop exclusivity and updates copy text.
meshroom/ui/qml/ImageGallery/ImageGridView.qml Treats templates like projects for drag/drop exclusivity and updates copy text.
meshroom/ui/qml/ImageGallery/ImageGallery.qml Updates mixed-file warning text to mention both projects and templates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread meshroom/ui/scene.py
Comment on lines +708 to 712
{images, videos, panoramaInfo, meshroomScenes, meshroomTemplates, otherFiles}: Map containing the
lists of paths for recognized images, videos, Meshroom scenes, Meshroom templates and other files.
Node: cameraInit node used to add new images to it
QPoint: position to locate the node (usually the mouse position)
"""
Comment thread meshroom/ui/scene.py
Comment on lines 496 to +500
def load(self, url):
localFile = self._urlToLocalFile(url)
if isTemplateFile(localFile):
return self.loadTemplate(localFile)
return self._loadWithErrorReport(self.loadGraph, localFile)
@nicolas-lambert-tc
nicolas-lambert-tc force-pushed the feature/explicit-templates-file-management branch from c24ebd3 to ee14941 Compare July 1, 2026 08:22
Comment thread meshroom/ui/app.py

import meshroom
from meshroom.core import pluginManager
from meshroom.core.files import isTemplateFile
Comment thread meshroom/core/graph.py
from meshroom.core import submitters
from meshroom.core.attribute import Attribute, ListAttribute, GroupAttribute
from meshroom.core.exception import GraphCompatibilityError, InvalidEdgeError, StopGraphVisit, StopBranchVisit, CyclicDependencyError
from meshroom.core.files import MESHROOM_PROJECT_EXTENSION, isTemplateFile
@servantftransperfect

Copy link
Copy Markdown
Contributor

Why don't we use the header to check .mgt validity ?

@cbentejac cbentejac changed the title Feature/explicit templates file management Explicit templates file management Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature new feature (proposed as PR or issue planned by dev)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants