Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion meshroom/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Backend(Enum):
PYSIDE = 2


CurrentBackend = None
DictModel = None
ListModel = None
Slot = None
Expand All @@ -25,7 +26,8 @@ class Backend(Enum):


def init(backend):
global DictModel, ListModel, Slot, Signal, Property, BaseObject, Variant, VariantList, JSValue
global CurrentBackend, DictModel, ListModel, Slot, Signal, Property, BaseObject, Variant, VariantList, JSValue
CurrentBackend = backend
if backend == Backend.PYSIDE:
# PySide types
from .qt import DictModel, ListModel, Slot, Signal, Property, BaseObject, Variant, VariantList, JSValue
Expand Down
36 changes: 36 additions & 0 deletions meshroom/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from contextlib import contextmanager
import hashlib
import importlib
import importlib.util
import inspect
import logging
import os
Expand All @@ -18,6 +19,7 @@
except Exception:
pass

from meshroom.common import CurrentBackend, Backend
from meshroom.core.plugins import NodePlugin, NodePluginManager, Plugin, processEnvFactory, formatNodeDescriptionErrorMessage
from meshroom.core.submitter import BaseSubmitter
from meshroom.env import EnvVar, meshroomFolder
Expand Down Expand Up @@ -343,6 +345,35 @@ def nodeVersion(nodeDesc: desc.Node, default=None):
return moduleVersion(nodeDesc.__module__, default)


def loadPluginMenu(pluginMenuFile):
"""
Registers a menu from a python script

Args:
folder: the folder where we search for the menu.
"""
# Generate a custom module name to avoid collisions
moduleName = f"mrMenus.{uuid.uuid4().hex}"
try:
spec = importlib.util.spec_from_file_location(moduleName, pluginMenuFile)
module = importlib.util.module_from_spec(spec)
sys.modules[moduleName] = module
spec.loader.exec_module(module)
logging.debug(f"Loaded menu registration from '{pluginMenuFile}'.")
except Exception as exc:
tb = traceback.extract_tb(exc.__traceback__)
last_call = tb[-1]
logging.warning(
f" * Failed to load menu file '{pluginMenuFile}' ({type(exc).__name__}): {str(exc)}\n"
# filename:lineNumber functionName
f"{last_call.filename}:{last_call.lineno} {last_call.name}\n"
# line of code with the error
f"{last_call.line}"
# Full traceback
f"\n{traceback.format_exc()}\n\n"
)
Comment thread
Alxiice marked this conversation as resolved.


def loadNodes(folder, packageName, pluginUid) -> list[NodePlugin]:
if not os.path.isdir(folder):
logging.error(f"Node folder '{folder}' does not exist.")
Expand Down Expand Up @@ -377,6 +408,11 @@ def loadPluginFolder(folder, userPlugin: bool = False) -> list[Plugin]:
logging.info(f"Plugin folder '{folder}' does not contain a 'meshroom' folder.")
return []

# Register any menu(s) declared by this plugin
pluginMenuFile = mrFolder / "menu.py"
if CurrentBackend == Backend.PYSIDE and pluginMenuFile.exists():
loadPluginMenu(pluginMenuFile)

plugins = loadAllNodes(folder=mrFolder)
if plugins:
for plugin in plugins:
Expand Down
4 changes: 4 additions & 0 deletions meshroom/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from meshroom.ui.components.messaging import MessageController
from meshroom.ui.components.shapes import ShapeFilesHelper, ShapeViewerHelper
from meshroom.ui.palette import PaletteManager
from meshroom.ui.menu import MeshroomMenuManager
from meshroom.ui.scene import Scene
from meshroom.ui.utils import QmlInstantEngine
from meshroom.ui import commands
Expand Down Expand Up @@ -288,6 +289,9 @@ def __init__(self, inputArgs):
if os.path.isdir(pyside6QmlPath):
self.engine.addImportPath(pyside6QmlPath)

# Expose the menu manager
self.engine.rootContext().setContextProperty("MeshroomMenuManager", MeshroomMenuManager(parent=self))

# expose available node types that can be instantiated
self.engine.rootContext().setContextProperty("_nodeTypes", {n: {"category": pluginManager.getRegisteredNodePlugins()[n].nodeDescriptor.category} for n in sorted(pluginManager.getRegisteredNodePlugins().keys())})

Expand Down
Loading
Loading