Skip to content

Commit

Permalink
[app] Add support for enabling QML debugging
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yann-lty committed Dec 20, 2024
1 parent ce66683 commit 2bdf753
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
53 changes: 53 additions & 0 deletions meshroom/env.py
Original file line number Diff line number Diff line change
@@ -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)

8 changes: 8 additions & 0 deletions meshroom/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2bdf753

Please sign in to comment.