from PyQt5 import QtWidgets, uic import os from .db.StarsDB import StarDB from .ui.NewStarDialog import NewStarDialog DEFAULT_DB = "stars.db" class AstrodataGUI(QtWidgets.QMainWindow): def __init__(self): super(AstrodataGUI, self).__init__() classFileDir = os.path.dirname(os.path.abspath(__file__)) absUiFilePath = os.path.join(classFileDir, "astrodatagui.ui") uic.loadUi(absUiFilePath, self) self.actionExit.triggered.connect(self.actionExitTriggered) self.btAddNew.clicked.connect(self.addNewClicked) self.show() self.loadDB() def loadDB(self): try: self.starDB = StarDB.getInstance(DEFAULT_DB) except Exception as e: self.showErrorMessage("DB Connection failed", f"Could not connect to local database file {DEFAULT_DB}\n\ {e}") def showErrorMessage(self, title: str, msg: str): print(title) print(msg) def closeEvent(self, event): confirmation = QtWidgets.QMessageBox.question(self, "Confirmation", "Are you sure you want to close the application?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) if confirmation == QtWidgets.QMessageBox.Yes: event.accept() # Close the app else: event.ignore() # Don't close the app def actionExitTriggered(self): for starDB in StarDB.getAllInstances(): starDB.close() self.close() def addNewClicked(self): diag = NewStarDialog() diag.exec()