Skip to content

Commit

Permalink
Add/restore pyside6 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmeyer committed May 21, 2024
1 parent 1f1397c commit fdac61c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
13 changes: 3 additions & 10 deletions nion/swift/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 19 additions & 20 deletions nionswift/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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
13 changes: 8 additions & 5 deletions nionui_app/nionswift/main.py
Original file line number Diff line number Diff line change
@@ -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))
Expand Down

0 comments on commit fdac61c

Please sign in to comment.