You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
# This Python file uses the following encoding: utf-8
|
|
import sys
|
|
import os
|
|
import signal
|
|
|
|
import PyQt5
|
|
from PySide2.QtGui import QGuiApplication
|
|
from PySide2.QtQml import QQmlApplicationEngine
|
|
from PySide2.QtCore import SIGNAL, QObject, Slot
|
|
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(
|
|
description="Display a map widget and make it print the selected location"
|
|
)
|
|
parser.add_argument("lat", help="latitude, as float")
|
|
parser.add_argument("lon", help="longitude, as float")
|
|
parser.add_argument(
|
|
"--die", help="Close the app once location is selected", action="store_true"
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
|
|
dirname = os.path.dirname(PyQt5.__file__)
|
|
plugin_path = os.path.join(dirname, "plugins", "platforms")
|
|
os.environ["QML2_IMPORT_PATH"] = os.path.join(dirname, "qml")
|
|
|
|
application_path = (
|
|
os.path.join(os.path.dirname(sys.executable), "assets")
|
|
if getattr(sys, "frozen", False)
|
|
else os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets")
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
signal.signal(
|
|
signal.SIGINT, signal.SIG_DFL
|
|
) # https://stackoverflow.com/questions/4938723/what-is-the-correct-way-to-make-my-pyqt-application-quit-when-killed-from-the-co
|
|
app = QGuiApplication(sys.argv)
|
|
engine = QQmlApplicationEngine()
|
|
engine.load(os.path.join(application_path, "main.qml"))
|
|
if not engine.rootObjects():
|
|
sys.exit(-1)
|
|
root = engine.rootObjects()[0]
|
|
if len(sys.argv) == 3:
|
|
lat = sys.argv[1]
|
|
lon = sys.argv[2]
|
|
root.setMapPosition(lat, lon)
|
|
|
|
def cb():
|
|
print(root.getSelectedLocation())
|
|
sys.stdout.flush()
|
|
if args.die:
|
|
QGuiApplication.quitOnLastWindowClosed()
|
|
root.close()
|
|
|
|
root.selected.connect(cb)
|
|
sys.exit(app.exec_())
|