mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-28 17:57:16 +02:00
[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.
This commit is contained in:
parent
a790ac8f21
commit
968a5d0471
2 changed files with 61 additions and 0 deletions
53
meshroom/env.py
Normal file
53
meshroom/env.py
Normal file
|
@ -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,6 +8,7 @@ from PySide6 import __version__ as PySideVersion
|
|||
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 import nodesDesc
|
|||
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 @@ class MeshroomApp(QApplication):
|
|||
|
||||
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,
|
||||
|
|
Loading…
Add table
Reference in a new issue