From ae21c0fc0f04c1400e81e82d2080020142b1ec4d Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Sun, 3 Jan 2021 08:52:30 +0100 Subject: [PATCH] Add args --- README.md | 1 + main.py | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 479b2ab..e48ab8e 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,5 @@ Run it: ```sh ./dist/qt-map-py/qt-map-py # start centered in PoznaƄ ./dist/qt-map-py/qt-map-py 33.66195 -95.55362 # start centered at given lat / lon +./dist/qt-map-py/qt-map-py 33.66195 -95.55362 --die # start centered at given lat / lon and close the window once the location is selected (otherwise each location is printed in a new line to stdout) ``` diff --git a/main.py b/main.py index 4f603bc..5866898 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,18 @@ 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") @@ -37,8 +49,10 @@ if __name__ == "__main__": def cb(): print(root.getSelectedLocation()) - QGuiApplication.quitOnLastWindowClosed() - root.close() + sys.stdout.flush() + if args.die: + QGuiApplication.quitOnLastWindowClosed() + root.close() root.selected.connect(cb) sys.exit(app.exec_())