Skip to content

Commit 2bdf753

Browse files
committed
[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.
1 parent ce66683 commit 2bdf753

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

meshroom/env.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Meshroom environment variable management.
3+
"""
4+
5+
__all__ = [
6+
"EnvVar",
7+
]
8+
9+
import os
10+
from dataclasses import dataclass
11+
from enum import Enum
12+
import sys
13+
from typing import Any, Type
14+
15+
16+
@dataclass
17+
class VarDefinition:
18+
"""Environment variable definition."""
19+
20+
# The type to cast the value to.
21+
valueType: Type
22+
# Default value if the variable is not set in the environment.
23+
default: str
24+
# Description of the purpose of the variable.
25+
description: str = ""
26+
27+
def __str__(self) -> str:
28+
return f"{self.description} ({self.valueType.__name__}, default: '{self.default}')"
29+
30+
31+
class EnvVar(Enum):
32+
"""Meshroom environment variables catalog."""
33+
34+
# UI - Debug
35+
MESHROOM_QML_DEBUG = VarDefinition(bool, "False", "Enable QML debugging")
36+
MESHROOM_QML_DEBUG_PARAMS = VarDefinition(
37+
str, "port:3768", "QML debugging params as expected by -qmljsdebugger"
38+
)
39+
40+
@staticmethod
41+
def get(envVar: "EnvVar") -> Any:
42+
"""Get the value of `envVar`, cast to the variable type."""
43+
value = os.environ.get(envVar.name, envVar.value.default)
44+
return EnvVar._cast(value, envVar.value.valueType)
45+
46+
@staticmethod
47+
def _cast(value: str, valueType: Type) -> Any:
48+
if valueType is str:
49+
return value
50+
elif valueType is bool:
51+
return value.lower() in {"true", "1", "on"}
52+
return valueType(value)
53+

meshroom/ui/app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from PySide6 import QtCore
99
from PySide6.QtCore import Qt, QUrl, QJsonValue, qInstallMessageHandler, QtMsgType, QSettings
1010
from PySide6.QtGui import QIcon
11+
from PySide6.QtQml import QQmlDebuggingEnabler
1112
from PySide6.QtQuickControls2 import QQuickStyle
1213
from PySide6.QtWidgets import QApplication
1314

@@ -16,6 +17,8 @@
1617
from meshroom.core.taskManager import TaskManager
1718
from meshroom.common import Property, Variant, Signal, Slot
1819

20+
from meshroom.env import EnvVar
21+
1922
from meshroom.ui import components
2023
from meshroom.ui.components.clipboard import ClipboardHelper
2124
from meshroom.ui.components.filepath import FilepathHelper
@@ -192,6 +195,11 @@ def __init__(self, inputArgs):
192195

193196
args = createMeshroomParser(inputArgs)
194197
qtArgs = []
198+
199+
if EnvVar.get(EnvVar.MESHROOM_QML_DEBUG):
200+
debuggerParams = EnvVar.get(EnvVar.MESHROOM_QML_DEBUG_PARAMS)
201+
self.debugger = QQmlDebuggingEnabler(printWarning=True)
202+
qtArgs = [f"-qmljsdebugger={debuggerParams}"]
195203

196204
logStringToPython = {
197205
'fatal': logging.FATAL,

0 commit comments

Comments
 (0)