in src/open_vp_cal/main.py [0:0]
def open_ui() -> None:
""" Opens the MainWindow as QApplication after the splash screen loads
"""
from PySide6.QtWidgets import QMessageBox
from PySide6 import QtWidgets
from PySide6.QtGui import QPixmap
from open_vp_cal.widgets.splash_screen import SplashScreen
from open_vp_cal.widgets.main_window import MainWindow
def handle_exception(exc_type: type, exc_value: Exception, exc_traceback: traceback) -> None:
""" Handles any unhandled exceptions by logging them to a file in the user's home directory and displaying a
QMessageBox to the user.
Args:
exc_type: The type of exception
exc_value: The value of the exception
exc_traceback: The traceback of the exception
"""
# Format current date and time as a string
current_time = datetime.now().strftime("%Y%m%d_%H%M%S")
# Get the home directory and form the full filename
log_dir = ResourceLoader.log_dir()
filename = log_dir / f"OpenVPCal_{current_time}.log"
# Open the file in appended mode and write the stack trace
with filename.open("a") as handle:
traceback.print_exception(exc_type, exc_value, exc_traceback, file=handle)
# Display the error message in a QMessageBox
QMessageBox.critical(None, "An unhandled Exception Occurred",
"An unhandled Exception Occurred\n" + str(exc_value),
QMessageBox.Ok)
# Then call the default handler if you want
sys.__excepthook__(exc_type, exc_value, exc_traceback)
sys.excepthook = handle_exception
app = QtWidgets.QApplication(sys.argv)
app.setStyle("Fusion")
pixmap = QPixmap(ResourceLoader.open_vp_cal_logo_full())
# Define product name, version info, and credits
product_name = 'OpenVPCal'
version_info = open_vp_cal.__version__
# Create and show the splash screen
splash = SplashScreen(pixmap, version_info)
splash.show()
# Simulate a delay for loading the main application
time.sleep(4)
# After loading is done, close the splash screen
splash.close()
window = MainWindow(f"{product_name} v{version_info}")
window.show()
window.load_project_layout()
sys.exit(app.exec())