diff --git a/main/astrodatagui/AstrodataGUI.py b/main/astrodatagui/AstrodataGUI.py index 8321369..d651c44 100644 --- a/main/astrodatagui/AstrodataGUI.py +++ b/main/astrodatagui/AstrodataGUI.py @@ -1,6 +1,8 @@ from PyQt5 import QtWidgets, uic import os +from astroquery.simbad import Simbad + from .db.StarsDB import StarDB from .ui.NewStarDialog import NewStarDialog @@ -16,14 +18,18 @@ class AstrodataGUI(QtWidgets.QMainWindow): self.actionExit.triggered.connect(self.actionExitTriggered) self.btAddNew.clicked.connect(self.addNewClicked) + self.listDownloaded.itemClicked.connect(self.starSelected) + self.listSequences.itemClicked.connect(self.sequenceSelected) self.show() self.loadDB() + self.updateStarList() + def loadDB(self): try: - self.starDB = StarDB.getInstance(DEFAULT_DB) + self.starDB: 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\ @@ -49,4 +55,44 @@ class AstrodataGUI(QtWidgets.QMainWindow): def addNewClicked(self): diag = NewStarDialog() - diag.exec() \ No newline at end of file + if not diag.exec(): + return + + try: + mainName = Simbad.query_object(diag.starIdentifier)["MAIN_ID"][0] + except: + self.showErrorMessage("Main Identifier Error", "Failed to grab main identifier, aborting...") + return + + try: + altNames = Simbad.query_objectids(mainName) + except: + self.showErrorMessage("Identifier Error", "Failed to grab all identifiers, aborting...") + return + + self.starDB.insertStar(mainName, altNames, diag.productManifest) + + self.updateStarList() + + def updateStarList(self): + self.listDownloaded.clear() + + for star in self.starDB.getAllStars(): + self.listDownloaded.addItem(star[0]) + + def updateSequenceList(self, sourceSeqTouple): + self.listSequences.clear() + for sT in sourceSeqTouple: + self.listSequences.addItem(f"{sT[0]} - {sT[1]}") + + def starSelected(self, item): + seqs = self.starDB.getStarData(item.text()) + self.updateSequenceList(seqs) + + def sequenceSelected(self, item): + seqText = item.text().split(" - ") + mainName = self.listDownloaded.currentItem().text() + source = seqText[0] + seq = seqText[1] + filePath = self.starDB.getFilePath(mainName, source, seq) + self.flaredetectorPreview.plotFitsFile(filePath) \ No newline at end of file