From 1e0627aae2e69e664d8eca0dd3af04ba8dd9b13c Mon Sep 17 00:00:00 2001 From: Liezl Maree <38435167+roomrys@users.noreply.github.com> Date: Thu, 12 Oct 2023 08:52:48 -0700 Subject: [PATCH] Add function to create app (#1546) --- sleap/gui/app.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/sleap/gui/app.py b/sleap/gui/app.py index 065563e66..41d696f0c 100644 --- a/sleap/gui/app.py +++ b/sleap/gui/app.py @@ -262,7 +262,6 @@ def dragEnterEvent(self, event): event.acceptProposedAction() def dropEvent(self, event): - # Parse filenames filenames = event.mimeData().data("text/uri-list").data().decode() filenames = [parse_uri_path(f.strip()) for f in filenames.strip().split("\n")] @@ -1602,7 +1601,12 @@ def _show_keyboard_shortcuts_window(self): ShortcutDialog().exec_() -def create_parser(): +def create_sleap_label_parser(): + """Creates parser for `sleap-label` command line arguments. + + Returns: + argparse.ArgumentParser: The parser. + """ import argparse @@ -1645,10 +1649,20 @@ def create_parser(): return parser +def create_app(): + """Creates Qt application.""" + + app = QApplication([]) + app.setApplicationName(f"SLEAP v{sleap.version.__version__}") + app.setWindowIcon(QtGui.QIcon(sleap.util.get_package_file("gui/icon.png"))) + + return app + + def main(args: Optional[list] = None, labels: Optional[Labels] = None): """Starts new instance of app.""" - parser = create_parser() + parser = create_sleap_label_parser() args = parser.parse_args(args) if args.nonnative: @@ -1660,9 +1674,7 @@ def main(args: Optional[list] = None, labels: Optional[Labels] = None): # https://stackoverflow.com/q/64818879 os.environ["QT_MAC_WANTS_LAYER"] = "1" - app = QApplication([]) - app.setApplicationName(f"SLEAP v{sleap.version.__version__}") - app.setWindowIcon(QtGui.QIcon(sleap.util.get_package_file("gui/icon.png"))) + app = create_app() window = MainWindow( labels_path=args.labels_path,