From d3ec5355c2ebe79f80d18c69801028428c0b8771 Mon Sep 17 00:00:00 2001 From: Michael Walsh Date: Wed, 28 Jan 2026 14:47:21 -0500 Subject: [PATCH 1/2] add boilerplate changes to standardize how TAVI is launched --- src/tavi/__main__.py | 40 ++++++++++++++++++++++++++++ src/tavi/frontend/main.py | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/tavi/__main__.py create mode 100644 src/tavi/frontend/main.py diff --git a/src/tavi/__main__.py b/src/tavi/__main__.py new file mode 100644 index 00000000..0509ca38 --- /dev/null +++ b/src/tavi/__main__.py @@ -0,0 +1,40 @@ +"""Entry point.""" + +import argparse +import sys + +from tavi import __version__ as tavi_version +from tavi.frontend.main import start + + +def _print_text_splash() -> None: + # TODO + pass + + +def _createArgparser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser( + prog="TAVI", description="Triple Axis data Visualization Toolkit (TAVI) ", epilog="https://tavi.readthedocs.io/" + ) + parser.add_argument("-v", "--version", action="version", version=tavi_version) + parser.add_argument( + "--headcheck", + action="store_true", + help="start the gui then shut it down after 5 seconds. This is used for testing", + ) + return parser + + +def main(args: list[str] = None) -> int: + """Setups up and runs the application.""" + parser = _createArgparser() + options, _ = parser.parse_known_args(args) + + # show the ascii splash screen + _print_text_splash() + + return start(options) + + +if __name__ == "__main__": + raise SystemExit(main(sys.argv)) diff --git a/src/tavi/frontend/main.py b/src/tavi/frontend/main.py new file mode 100644 index 00000000..4ab19d53 --- /dev/null +++ b/src/tavi/frontend/main.py @@ -0,0 +1,56 @@ +"""Main Qt entry point.""" + +import signal +import sys +from argparse import Namespace + +from qtpy.QtCore import QTimer +from qtpy.QtWidgets import QApplication + +from tavi.backend.model.interface.TaviProjectInterface import TaviProjectInterface +from tavi.configuration import Configuration +from tavi.frontend.presenter.main_presenter import MainPresenter + + +def _qapp() -> QApplication: + if QApplication.instance(): + _app = QApplication.instance() + else: + _app = QApplication(sys.argv) + return _app + + +def start(options: Namespace = None) -> int: + """Start the UI.""" + signal.signal(signal.SIGINT, signal.SIG_DFL) + + app = _qapp() + config = Configuration() + + if not config.is_valid(): + msg = ( + "Error with configuration settings!", + f"Check and update your file: {config.config_file_path}", + "with the latest settings found here:", + f"{config.template_file_path} and start the application again.", + ) + + print(" ".join(msg)) + sys.exit(-1) + + # TODO: Log a welcome message + print("Welcome to TAVI! Happy visualizing!") + try: + dict_of_model = {"TaviProjectInterface": TaviProjectInterface()} + mainWindow = MainPresenter(dict_of_model) + mainWindow._view.show() + + if options.headcheck: + SECONDS = 3 # arbitrarily chosen + # TODO: log that it is doing a headcheck + QTimer.singleShot(SECONDS * 1000, lambda: app.exit(0)) + return app.exec() + + except Exception: # noqa: BLE001 + # TODO: logger.exception("Uncaught Error bubbled up to main!") + return -1 From cf414231317f57960e73594f26293ff6e7b3b84f Mon Sep 17 00:00:00 2001 From: Michael Walsh Date: Wed, 28 Jan 2026 15:05:49 -0500 Subject: [PATCH 2/2] migrate how we check version to the standard --- src/tavi/__init__.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/tavi/__init__.py b/src/tavi/__init__.py index 475eb027..9e5687e4 100644 --- a/src/tavi/__init__.py +++ b/src/tavi/__init__.py @@ -1,16 +1,6 @@ -""" -Contains the entry point for the application -""" +"""Contain the entry point for the application.""" try: from ._version import __version__ # noqa: F401 except ImportError: __version__ = "unknown" - - -def Tavi(): # noqa: N802 - """Start Class""" - - from .tavimain import Tavi as tavi # noqa: E501, N813 - - return tavi()