Add dialog if no file in cli

Signed-off-by: Rémi BERTHO <remi.bertho@dalan.fr>
This commit is contained in:
Rémi BERTHO 2018-05-01 16:30:56 +02:00
parent b102ed0a60
commit 6c03efaed9
Signed by: dalan
GPG Key ID: EE3B917931C07B64
1 changed files with 12 additions and 4 deletions

View File

@ -3,6 +3,7 @@
import os import os
import sys import sys
from os import path from os import path
from pathlib import Path
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import * from PyQt5.QtCore import *
from PyQt5.QtGui import * from PyQt5.QtGui import *
@ -10,7 +11,17 @@ from PyQt5.QtWidgets import *
from PyQt5.QtWebEngine import * from PyQt5.QtWebEngine import *
from PyQt5.QtWebEngineWidgets import * from PyQt5.QtWebEngineWidgets import *
img = path.abspath(sys.argv[1]) 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)
exe_dir = path.dirname(path.realpath(sys.argv[0])) exe_dir = path.dirname(path.realpath(sys.argv[0]))
os.chdir(exe_dir) os.chdir(exe_dir)
@ -22,9 +33,6 @@ except OSError as exception:
print("Error: HTML file not found: " + str(exception)) print("Error: HTML file not found: " + str(exception))
html = html.replace("__IMG_PATH__", img) html = html.replace("__IMG_PATH__", img)
app = QApplication(sys.argv)
app.setApplicationName("SimplePanoramaViewer")
web = QWebEngineView() web = QWebEngineView()
web.setHtml(html,QUrl("file://" + exe_dir + "/index.html")) web.setHtml(html,QUrl("file://" + exe_dir + "/index.html"))
web.setWindowTitle(img) web.setWindowTitle(img)