From 2bdf7531d3b7cbbd60efe74232fa4675a9612f93 Mon Sep 17 00:00:00 2001 From: Yann Lanthony Date: Fri, 20 Dec 2024 17:00:22 +0100 Subject: [PATCH] [app] Add support for enabling QML debugging Introduce new environment variable to enable and configure QML debugging when starting Meshroom GUI app. Introduce a new EnvVar class to centralize the management of environment variables across Meshroom. --- meshroom/env.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++ meshroom/ui/app.py | 8 +++++++ 2 files changed, 61 insertions(+) create mode 100644 meshroom/env.py diff --git a/meshroom/env.py b/meshroom/env.py new file mode 100644 index 0000000000..d3b6da3057 --- /dev/null +++ b/meshroom/env.py @@ -0,0 +1,53 @@ +""" +Meshroom environment variable management. +""" + +__all__ = [ + "EnvVar", +] + +import os +from dataclasses import dataclass +from enum import Enum +import sys +from typing import Any, Type + + +@dataclass +class VarDefinition: + """Environment variable definition.""" + + # The type to cast the value to. + valueType: Type + # Default value if the variable is not set in the environment. + default: str + # Description of the purpose of the variable. + description: str = "" + + def __str__(self) -> str: + return f"{self.description} ({self.valueType.__name__}, default: '{self.default}')" + + +class EnvVar(Enum): + """Meshroom environment variables catalog.""" + + # UI - Debug + MESHROOM_QML_DEBUG = VarDefinition(bool, "False", "Enable QML debugging") + MESHROOM_QML_DEBUG_PARAMS = VarDefinition( + str, "port:3768", "QML debugging params as expected by -qmljsdebugger" + ) + + @staticmethod + def get(envVar: "EnvVar") -> Any: + """Get the value of `envVar`, cast to the variable type.""" + value = os.environ.get(envVar.name, envVar.value.default) + return EnvVar._cast(value, envVar.value.valueType) + + @staticmethod + def _cast(value: str, valueType: Type) -> Any: + if valueType is str: + return value + elif valueType is bool: + return value.lower() in {"true", "1", "on"} + return valueType(value) + diff --git a/meshroom/ui/app.py b/meshroom/ui/app.py index 1c523b6640..d19f7652e8 100644 --- a/meshroom/ui/app.py +++ b/meshroom/ui/app.py @@ -8,6 +8,7 @@ from PySide6 import QtCore from PySide6.QtCore import Qt, QUrl, QJsonValue, qInstallMessageHandler, QtMsgType, QSettings from PySide6.QtGui import QIcon +from PySide6.QtQml import QQmlDebuggingEnabler from PySide6.QtQuickControls2 import QQuickStyle from PySide6.QtWidgets import QApplication @@ -16,6 +17,8 @@ from meshroom.core.taskManager import TaskManager from meshroom.common import Property, Variant, Signal, Slot +from meshroom.env import EnvVar + from meshroom.ui import components from meshroom.ui.components.clipboard import ClipboardHelper from meshroom.ui.components.filepath import FilepathHelper @@ -192,6 +195,11 @@ def __init__(self, inputArgs): args = createMeshroomParser(inputArgs) qtArgs = [] + + if EnvVar.get(EnvVar.MESHROOM_QML_DEBUG): + debuggerParams = EnvVar.get(EnvVar.MESHROOM_QML_DEBUG_PARAMS) + self.debugger = QQmlDebuggingEnabler(printWarning=True) + qtArgs = [f"-qmljsdebugger={debuggerParams}"] logStringToPython = { 'fatal': logging.FATAL,