diff --git a/nion/swift/command.py b/nion/swift/command.py index 8c0cb71ec..8ef64b67f 100644 --- a/nion/swift/command.py +++ b/nion/swift/command.py @@ -73,22 +73,15 @@ def main() -> None: success = False - # next attempt to launch using pyqt + # next attempt to launch using pyside6 try: - from PyQt5 import QtCore - success = True - except ImportError: - pass - - # next attempt to launch using pyside2 - try: - from PySide2 import QtCore + from PySide6 import QtCore success = True except ImportError: pass if not success: - print("Please install either pyqt or PySide2 using pip or conda or use nionswift-tool to launch.") + print("Please install either pyside6 using pip or conda or use nionswift-tool to launch.") if success: app, error = bootstrap_main(sys.argv) diff --git a/nionswift/__main__.py b/nionswift/__main__.py index dc6411e15..3874f3dc2 100644 --- a/nionswift/__main__.py +++ b/nionswift/__main__.py @@ -2,57 +2,56 @@ import os import subprocess import sys +import typing parser = argparse.ArgumentParser( - prog="python -m nionswift", description="Launch Nion Swift using Qt or a launcher." + prog="python -m nionswift", description="Launch Nion Swift using native launcher or pyside6 libraries." ) parser.add_argument( "--ui", dest="ui", action="store", - choices=["tool", "qt", "pyqt", "pyside2"], + choices=["tool", "qt"], help="choose UI frontend", default="tool", ) -# python 3.8 compatible -parser.add_argument('--fallback', action='store_true') -parser.add_argument('--no-fallback', dest='fallback', action='store_false') -parser.set_defaults(fallback=True) - -# python 3.9+ compatible -# parser.add_argument( -# "--fallback", -# dest="fallback", -# action=argparse.BooleanOptionalAction, -# help="whether to fallback to other UI frontend if preferred choice is unavailable", -# default=True, -# ) +parser.add_argument( + "--fallback", + dest="fallback", + action=argparse.BooleanOptionalAction, + help="whether to fall back to other UI frontend if preferred choice is unavailable", + default=True, +) parsed_args = parser.parse_args() -app = "nionui_app.nionswift" -args = [] +app_id = "nionui_app.nionswift" +args = list[typing.Any]() -order = [] +order = list[str]() if parsed_args.ui: order.append(parsed_args.ui) +# if using fallback, add tool and qt to order if not already present. if parsed_args.fallback: if "tool" not in order: order.append("tool") if "qt" not in order: order.append("qt") +# go through the ui preferences in order for ui in order: if ui == "qt": + # launch the app using the pyside6 qt frontend from nionui_app.nionswift import main - app = main.main({}, {"pyqt": None}) + app = main.main(list(), {"qt": None}) app.run() break else: + # launch using the tool frontend if sys.platform == "darwin": exe_path = os.path.join(sys.exec_prefix, "bin", "Nion Swift.app", "Contents", "MacOS", "Nion Swift") elif sys.platform == "linux": @@ -63,6 +62,6 @@ exe_path = None if exe_path: python_prefix = sys.prefix - proc = subprocess.Popen([exe_path, python_prefix, app] + args, universal_newlines=True) + proc = subprocess.Popen([exe_path, python_prefix, app_id] + args, universal_newlines=True) proc.communicate() break diff --git a/nionui_app/nionswift/main.py b/nionui_app/nionswift/main.py index 533afed27..6d689af34 100644 --- a/nionui_app/nionswift/main.py +++ b/nionui_app/nionswift/main.py @@ -1,10 +1,13 @@ -import os +import typing import warnings -def main(args, bootstrap_args): - from nion.swift import Facade - from nion.swift import Application - from nion.ui import Application as ApplicationUI +from nion.swift import Application +from nion.swift import Facade +from nion.ui import Application as ApplicationUI + + +def main(args: list[typing.Any], bootstrap_args: dict[str, typing.Any]) -> Application.Application: + # from nion.swift import Application warnings.simplefilter("always", RuntimeWarning) Facade.initialize() app = Application.Application(ApplicationUI.make_ui(bootstrap_args))