SimplePanoramaViewer/SimplePanoramaViewer
Rémi BERTHO db826ceade
Add ' escape
Signed-off-by: Rémi BERTHO <remi.bertho@dalan.fr>
2018-09-01 12:19:38 +02:00

43 lines
1 KiB
Python
Executable file

#!/usr/bin/env python3
import os
import sys
from os import path
from pathlib import Path
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngine import *
from PyQt5.QtWebEngineWidgets import *
app = QApplication(sys.argv)
app.setApplicationName("SimplePanoramaViewer")
if len(sys.argv) < 2:
img_dialog = QFileDialog.getOpenFileName(None, "Open image", str(Path.home()), "JPG Images (*.jpg *.JPG *.jpeg)")
img = img_dialog[0]
else:
img = path.abspath(sys.argv[1])
if img == "":
exit(0)
img = img.replace("'", "\\'")
exe_dir = path.dirname(path.realpath(sys.argv[0]))
os.chdir(exe_dir)
try:
with open("html/index.html", "r", encoding="utf8") as file:
html = file.read()
except OSError as exception:
print("Error: HTML file not found: " + str(exception))
html = html.replace("__IMG_PATH__", img)
web = QWebEngineView()
web.setHtml(html,QUrl("file://" + exe_dir + "/index.html"))
web.setWindowTitle(img)
web.show()
sys.exit(app.exec_())