Meshroom/meshroom/ui/app.py
Yann Lanthony 3438900b2b [ui] add "About" dialog
Accessible from main menu Help > About Meshroom, or by pressing "F1". Provides info about Meshroom version + useful links and related Open Source Licenses.

* load COPYING.md from Meshroom/AliceVision files (either provided with the standalone package or online) + translate them to HTML for display  (added `markdown` package in requirements)
* request.js: centralize function to open file urls
* provide system info from MeshroomApp (exposed as contextProperty)
2018-08-03 17:24:04 +02:00

108 lines
4 KiB
Python

import logging
import os
from PySide2.QtCore import Qt, Slot, QJsonValue, Property
from PySide2.QtGui import QIcon
from PySide2.QtWidgets import QApplication
import meshroom
from meshroom.core import nodesDesc
from meshroom.ui import components
from meshroom.ui.components.filepath import FilepathHelper
from meshroom.ui.palette import PaletteManager
from meshroom.ui.reconstruction import Reconstruction
from meshroom.ui.utils import QmlInstantEngine
class MeshroomApp(QApplication):
""" Meshroom UI Application. """
def __init__(self, args):
args = [args[0], '-style', 'fusion'] + args[1:] # force Fusion style by default
super(MeshroomApp, self).__init__(args)
self.setOrganizationName('AliceVision')
self.setApplicationName('Meshroom')
self.setAttribute(Qt.AA_EnableHighDpiScaling)
self.setApplicationVersion(meshroom.__version__)
font = self.font()
font.setPointSize(9)
self.setFont(font)
pwd = os.path.dirname(__file__)
self.setWindowIcon(QIcon(os.path.join(pwd, "img/meshroom.svg")))
# QML engine setup
qmlDir = os.path.join(pwd, "qml")
url = os.path.join(qmlDir, "main.qml")
self.engine = QmlInstantEngine()
self.engine.addFilesFromDirectory(qmlDir, recursive=True)
self.engine.setWatching(os.environ.get("MESHROOM_INSTANT_CODING", False))
# whether to output qml warnings to stderr (disable by default)
self.engine.setOutputWarningsToStandardError(bool(os.environ.get("MESHROOM_OUTPUT_QML_WARNINGS", False)))
self.engine.addImportPath(qmlDir)
components.registerTypes()
# expose available node types that can be instantiated
self.engine.rootContext().setContextProperty("_nodeTypes", sorted(nodesDesc.keys()))
r = Reconstruction(parent=self)
self.engine.rootContext().setContextProperty("_reconstruction", r)
pm = PaletteManager(self.engine, parent=self)
self.engine.rootContext().setContextProperty("_PaletteManager", pm)
fpHelper = FilepathHelper(parent=self)
self.engine.rootContext().setContextProperty("Filepath", fpHelper)
self.engine.rootContext().setContextProperty("MeshroomApp", self)
# Request any potential computation to stop on exit
self.aboutToQuit.connect(r.stopExecution)
self.engine.load(os.path.normpath(url))
@Slot(str, result=str)
def markdownToHtml(self, md):
"""
Convert markdown to HTML.
Args:
md (str): the markdown text to convert
Returns:
str: the resulting HTML string
"""
try:
from markdown import markdown
except ImportError:
logging.warning("Can't import markdown module, returning source markdown text.")
return md
return markdown(md)
@Property(QJsonValue, constant=True)
def systemInfo(self):
import platform
import sys
return {
'platform': '{} {}'.format(platform.system(), platform.release()),
'python': 'Python {}'.format(sys.version.split(" ")[0])
}
@Property("QVariantList", constant=True)
def licensesModel(self):
"""
Get info about open-source licenses for the application.
Model provides:
title: the name of the project
localUrl: the local path to COPYING.md
onlineUrl: the remote path to COPYING.md
"""
rootDir = os.environ.get("MESHROOM_INSTALL_DIR", os.getcwd())
return [
{
"title": "Meshroom",
"localUrl": os.path.join(rootDir, "COPYING.md"),
"onlineUrl": "https://raw.githubusercontent.com/alicevision/meshroom/develop/COPYING.md"
},
{
"title": "AliceVision",
"localUrl": os.path.join(rootDir, "aliceVision", "share", "COPYING.md"),
"onlineUrl": "https://raw.githubusercontent.com/alicevision/AliceVision/develop/COPYING.md"
}
]