Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to create app #1546

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions sleap/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down
Loading