Skip to content
Draft
Show file tree
Hide file tree
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
12 changes: 1 addition & 11 deletions src/tavi/__init__.py
Original file line number Diff line number Diff line change
@@ -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()
40 changes: 40 additions & 0 deletions src/tavi/__main__.py
Original file line number Diff line number Diff line change
@@ -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))
56 changes: 56 additions & 0 deletions src/tavi/frontend/main.py
Original file line number Diff line number Diff line change
@@ -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