From a790ac8f21f27adaa6755928819c54e57bf76f6c Mon Sep 17 00:00:00 2001 From: Yann Lanthony Date: Fri, 20 Dec 2024 16:54:39 +0100 Subject: [PATCH 1/3] [app] Set Fusion style using API Instead of passing the style via QApplication arguments, use the QQuickStyle API. --- meshroom/ui/app.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/meshroom/ui/app.py b/meshroom/ui/app.py index 884b885111..1ca5dd5e84 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.QtQuickControls2 import QQuickStyle from PySide6.QtWidgets import QApplication import meshroom @@ -186,12 +187,11 @@ def createMeshroomParser(args): class MeshroomApp(QApplication): """ Meshroom UI Application. """ - def __init__(self, args): + def __init__(self, inputArgs): meshroom.core.initPipelines() - QtArgs = [args[0], '-style', 'Fusion'] + args[1:] # force Fusion style by default - - args = createMeshroomParser(args) + args = createMeshroomParser(inputArgs) + qtArgs = [] logStringToPython = { 'fatal': logging.FATAL, @@ -203,7 +203,7 @@ def __init__(self, args): } logging.getLogger().setLevel(logStringToPython[args.verbose]) - super(MeshroomApp, self).__init__(QtArgs) + super(MeshroomApp, self).__init__(inputArgs[:1] + qtArgs) self.setOrganizationName('AliceVision') self.setApplicationName('Meshroom') @@ -213,6 +213,9 @@ def __init__(self, args): font.setPointSize(9) self.setFont(font) + # Use Fusion style by default. + QQuickStyle.setStyle("Fusion") + pwd = os.path.dirname(__file__) self.setWindowIcon(QIcon(os.path.join(pwd, "img/meshroom.svg"))) From 968a5d04714cb02253a1932dc33a053ab738a4b1 Mon Sep 17 00:00:00 2001 From: Yann Lanthony Date: Fri, 20 Dec 2024 17:00:22 +0100 Subject: [PATCH 2/3] [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 1ca5dd5e84..06b0d70fa1 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, From c20ecaadd2502ec7ff2b4b6b5469b170d5efc3f5 Mon Sep 17 00:00:00 2001 From: Yann Lanthony Date: Fri, 20 Dec 2024 17:03:08 +0100 Subject: [PATCH 3/3] [app] Add `--env-help` command line option Add a new CLI option to print the available Meshroom environment variables and their descriptions. --- meshroom/env.py | 17 +++++++++++++++++ meshroom/ui/app.py | 10 +++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/meshroom/env.py b/meshroom/env.py index d3b6da3057..3036db206f 100644 --- a/meshroom/env.py +++ b/meshroom/env.py @@ -4,8 +4,10 @@ __all__ = [ "EnvVar", + "EnvVarHelpAction", ] +import argparse import os from dataclasses import dataclass from enum import Enum @@ -51,3 +53,18 @@ def _cast(value: str, valueType: Type) -> Any: return value.lower() in {"true", "1", "on"} return valueType(value) + @classmethod + def help(cls) -> str: + """Return a formatted string with the details of each environment variables.""" + return "\n".join([f"{var.name}: {var.value}" for var in cls]) + + +class EnvVarHelpAction(argparse.Action): + """Argparse action for printing Meshroom environment variables help and exit.""" + + DEFAULT_HELP = "Print Meshroom environment variables help and exit." + + def __call__(self, parser, namespace, value, option_string=None): + print("Meshroom environment variables:") + print(EnvVar.help()) + sys.exit(0) diff --git a/meshroom/ui/app.py b/meshroom/ui/app.py index 06b0d70fa1..82696401da 100644 --- a/meshroom/ui/app.py +++ b/meshroom/ui/app.py @@ -17,7 +17,7 @@ from meshroom.core.taskManager import TaskManager from meshroom.common import Property, Variant, Signal, Slot -from meshroom.env import EnvVar +from meshroom.env import EnvVar, EnvVarHelpAction from meshroom.ui import components from meshroom.ui.components.clipboard import ClipboardHelper @@ -185,6 +185,14 @@ def createMeshroomParser(args): + '\n'.join([' - ' + p for p in meshroom.core.pipelineTemplates]), ) + advanced_group = parser.add_argument_group("Advanced Options") + advanced_group.add_argument( + "--env-help", + action=EnvVarHelpAction, + nargs=0, + help=EnvVarHelpAction.DEFAULT_HELP, + ) + return parser.parse_args(args[1:])