Пример #1
0
def sortCatalog(gui, sortField):
    """
    Sorts the currently loaded catalog in ascending or descending
    order depending upon the sort checkbox in the GUI.

    :param tkwidget gui: GUI object from which the request came
    :param CatalogSortFiedl sortField      which field to sort on.
    """
    prt = gui.getPrtInstance()
    sortOrder = gui.getSortOrderChkbox()

    if (not ASTCatalog.isCatalogLoaded()):
        ASTMsg.errMsg("No catalog is currently loaded.", "No Catalog Loaded")
        return

    prt.clearTextArea()
    prt.printnoln("You have elected to sort the catalog in ")
    if (sortOrder == ASCENDING_ORDER):
        prt.printnoln("ascending")
    else:
        prt.printnoln("descending")
    prt.println(" order by " + sortField.toStr() + " ... ")
    prt.println()

    ASTCatalog.sortStarCatalog(sortField, sortOrder)
    prt.println("The catalog has now been sorted ...")
    prt.resetCursor()
Пример #2
0
def clearCatalog(gui):
    """
    Clears all catalog data currently loaded.
    
    :param tkwidget gui: GUI object from which the request came
    """
    prt = gui.getPrtInstance()

    if (not ASTCatalog.isCatalogLoaded()):
        ASTMsg.errMsg(
            "No catalog is currently loaded, so there is nothing to clear.",
            "No Catalog Loaded")
        return

    prt.clearTextArea()

    if (ASTMsg.pleaseConfirm(
            "Are you sure you want to clear all\ncurrently loaded catalog data?",
            "Clear Catalog Data")):
        ASTCatalog.clearCatalogAndSpaceObjects()
        gui.setFilename("")
        gui.setCatalogType("")
        gui.setEpoch(DEFAULT_EPOCH)
        prt.println("All currently loaded catalog data was cleared ...")
    else:
        prt.println("Catalog data was not cleared ...")

    prt.resetCursor()
Пример #3
0
def listObjByName(gui):
    """
    Displays all catalog information about an object given its name.
    
    :param tkwidget gui: GUI object from which the request came
    """
    prt = gui.getPrtInstance()

    if (not ASTCatalog.isCatalogLoaded()):
        ASTMsg.errMsg("No catalog is currently loaded.", "No Catalog Loaded")
        return

    if (ASTQuery.showQueryForm(["Enter the Object's Name"]) !=
            ASTQuery.QUERY_OK):
        return

    searchStr = ASTQuery.getData(1)
    if ((searchStr == None) or (len(searchStr) <= 0)):
        return

    prt.clearTextArea()
    idx = ASTCatalog.findObjByName(searchStr.strip())
    if (idx < 0):
        prt.println("No object named '" + searchStr +
                    "' was found in the catalog")
    else:
        ASTCatalog.displayFullObjInfo(idx)

    prt.resetCursor()
Пример #4
0
def listAllObjsByConst(gui):
    """
    Shows all space objects within a given constellation.
    
    :param tkwidget gui: GUI object from which the request came
    """
    prt = gui.getPrtInstance()

    if (not ASTCatalog.isCatalogLoaded()):
        ASTMsg.errMsg("No catalog is currently loaded.", "No Catalog Loaded")
        return

    if (ASTQuery.showQueryForm([
            "Enter Constellation's 3 Character Abbreviated Name"
    ]) != ASTQuery.QUERY_OK):
        return

    constAbbrevName = ASTQuery.getData(1)
    if ((constAbbrevName == None) or (len(constAbbrevName) <= 0)):
        return

    prt.clearTextArea()

    idx = ASTConstellation.findConstellationByAbbrvName(
        constAbbrevName.strip())
    if (idx < 0):
        prt.println("No Constellation whose abbreviated name is '" +
                    constAbbrevName + "' was found")
    else:
        prt.setFixedWidthFont()
        ASTCatalog.displayAllObjsByConstellation(idx, gui.getSortOrderChkbox())
        prt.setProportionalFont()

    prt.resetCursor()
Пример #5
0
def menuListener(calcToDo, gui):
    """
    Handle a click on the menu items
    
    :param CalculationType calcToDo: the calculation to perform
    :param tkwidget gui: GUI object to which menu items are associated)
    """
    cen = Chap1.ChapEnums.CalculationType  # shorten to make typing easier!!!

    #****************Constellations Menu
    if (calcToDo == cen.LISTCONSTBYNAME):
        listConstByName(gui)
    elif (calcToDo == cen.LISTCONSTBYABBREVNAME):
        listConstByAbbrevName(gui)
    elif (calcToDo == cen.LISTCONSTBYMEANING):
        listConstsByMeaning(gui)
    elif (calcToDo == cen.LISTALLCONST):
        listAllConstellations(gui)
    elif (calcToDo == cen.FINDCONST):
        findConstellationForRA_Decl(gui)

    #****************Star Catalogs Menu
    elif (calcToDo == cen.CLEARCAT):
        clearCatalog(gui)
    elif (calcToDo == cen.LOADCAT):
        loadCatalog(gui)
    elif (calcToDo == cen.SHOWCATINFO):
        showCatalogInfo(gui)

    #*****************Space Objects Menu
    elif (calcToDo == cen.LISTOBJBYNAME):
        listObjByName(gui)
    elif (calcToDo == cen.LISTOBJBYALTNAME):
        listObjByAltName(gui)
    elif (calcToDo == cen.LISTOBJBYCOMMENTS):
        listObjByComments(gui)
    elif (calcToDo == cen.LISTALLOBJSINCAT):
        listAllObjsInCatalog(gui)
    elif (calcToDo == cen.LISTALLOBJSINRANGE):
        listAllObjsByRange(gui)
    elif (calcToDo == cen.LISTALLOBJSINCONST):
        listAllObjsByConst(gui)
    elif (calcToDo == cen.SORTCATBYCONST):
        sortCatalog(gui, ASTCatalog.CatalogSortField.CONSTELLATION)
    elif (calcToDo == cen.SORTCATBYCONSTANDOBJNAME):
        sortCatalog(gui, ASTCatalog.CatalogSortField.CONST_AND_OBJNAME)
    elif (calcToDo == cen.SORTCATBYOBJNAME):
        sortCatalog(gui, ASTCatalog.CatalogSortField.OBJNAME)
    elif (calcToDo == cen.SORTCATBYOBJALTNAME):
        sortCatalog(gui, ASTCatalog.CatalogSortField.OBJ_ALTNAME)
    elif (calcToDo == cen.SORTCATBYOBJRA):
        sortCatalog(gui, ASTCatalog.CatalogSortField.RA)
    elif (calcToDo == cen.SORTCATBYOBJDECL):
        sortCatalog(gui, ASTCatalog.CatalogSortField.DECL)
    elif (calcToDo == cen.SORTCATBYOBJMV):
        sortCatalog(gui, ASTCatalog.CatalogSortField.VISUAL_MAGNITUDE)

    else:  # This should never happen
        ASTMsg.criticalErrMsg("Unimplemented menu item " + str(calcToDo))
Пример #6
0
def showCatalogInfo(gui):
    """
    Shows the catalog information from the currently loaded catalog.
    
    :param tkwidget gui: GUI object from which the request came
    """
    prt = gui.getPrtInstance()

    if not (ASTCatalog.isCatalogLoaded()):
        ASTMsg.errMsg("No catalog is currently loaded.", "No Catalog Loaded")
    else:
        prt.clearTextArea()
        ASTCatalog.displayCatalogInfo()
        prt.resetCursor()
Пример #7
0
def listObjByComments(gui):
    """
    Displays detailed information about catalog objects that
    contain a target substring in their "comments" field.

    :param tkwidget gui: GUI object from which the request came
    """
    prt = gui.getPrtInstance()

    if (not ASTCatalog.isCatalogLoaded()):
        ASTMsg.errMsg("No catalog is currently loaded.", "No Catalog Loaded")
        return

    if (ASTQuery.showQueryForm([
            "Enter Substring to Search for in the Object's 'Comments' Field"
    ]) != ASTQuery.QUERY_OK):
        return

    searchStr = ASTQuery.getData(1)
    if ((searchStr == None) or (len(searchStr) <= 0)):
        return

    prt.clearTextArea()

    iResult = ASTCatalog.findObjsByComments(searchStr.strip())

    n = len(iResult)

    if (n <= 0):
        prt.println("No Objects in the current Catalog have the substring '" +
                    searchStr + "' in their 'Comments' field")
    else:
        if (n == 1):
            prt.println("One Object has the substring '" + searchStr +
                        "' in it's 'Comments' field")
        else:
            prt.println(
                str(n) + " Objects have the substring '" + searchStr +
                "' in their 'Comments' field")

        for i in range(0, n):
            prt.println()
            prt.setFixedWidthFont()
            prt.println("*" * 80)
            prt.setProportionalFont()
            prt.println("Object # " + str(i + 1))
            ASTCatalog.displayFullObjInfo(iResult[i])

    prt.resetCursor()
Пример #8
0
def listAllObjsInCatalog(gui):
    """
    Shows all catalog information, including space objects,
    in the currently loaded catalog.

    :param tkwidget gui: GUI object from which the request came
    """
    prt = gui.getPrtInstance()

    if (not ASTCatalog.isCatalogLoaded()):
        ASTMsg.errMsg("No catalog is currently loaded.", "No Catalog Loaded")
        return

    prt.clearTextArea()
    ASTCatalog.displayCatalogInfo()
    prt.setFixedWidthFont()
    prt.println("*" * 80)
    ASTCatalog.displayAllCatalogObjects()
    prt.setProportionalFont()
    prt.resetCursor()
Пример #9
0
def loadCatalog(gui):
    """
    Loads a star catalog from disk.
    
    :param tkwidget gui: GUI object from which the request came
    """
    prt = gui.getPrtInstance()

    fileToRead = ASTFileIO.getFileToRead(
        "Select Catalog to Load ...", ASTCatalog.ASTCatalog.getFileExtFilter(),
        ASTCatalog.ASTCatalog.getCatDataDir(), "")

    if ((fileToRead == None) or (len(fileToRead) <= 0)):
        return

    gui.setFilename(fileToRead)

    prt.clearTextArea()

    if ((ASTFileIO.getFileSize(fileToRead) / 1024.0) >
            ASTCatalog.MAX_CATALOG_FILESIZE_KB):
        ASTMsg.infoMsg(
            "Warning: Due to its size, it may take several seconds to load\n" +
            "this Star Catalog. Click 'OK' and then please be patient.\n" +
            "A message will be displayed when loading is completed.", "")

    if (ASTCatalog.loadFormattedStarCatalog(fileToRead)):
        s = ASTStr.strFormat("Read in %d different Constellations with a total of ",ASTCatalog.getCatNumConst()) +\
            ASTStr.strFormat("%d Objects",ASTCatalog.getCatNumObjs())
        prt.println(s)
        gui.setCatalogType(ASTCatalog.getCatType())
        gui.setEpoch(ASTCatalog.getCatEpoch())
    else:
        ASTMsg.errMsg("Could not load the catalog data from " + fileToRead,
                      "Catalog Load Failed")
        gui.setFilename("")
        gui.setCatalogType("")
        gui.setEpoch(DEFAULT_EPOCH)

    prt.resetCursor()
Пример #10
0
def listAllObjsByRange(gui):
    """
    Shows all space objects within a user specified index range.
    
    :param tkwidget gui: GUI object from which the request came
    """
    iMaxNum = 100  # default to 1st 100 entries

    prt = gui.getPrtInstance()

    if (not ASTCatalog.isCatalogLoaded()):
        ASTMsg.errMsg("No catalog is currently loaded.", "No Catalog Loaded")
        return

    if (ASTQuery.showQueryForm([
            "Enter index for 1st object to list\n(ex: 1 for 1st object in the catalog)",
            "Enter number of objects to list\n(ex: 10 for total of 10 objects)"
    ]) != ASTQuery.QUERY_OK):
        return

    prt.clearTextArea()

    n = ASTInt.isValidInt(ASTQuery.getData(1), HIDE_ERRORS)
    if (n.isValidIntObj()):
        iStart = n.getIntValue() - 1  # 0 base indexing assumed!
    else:
        iStart = 0

    n = ASTInt.isValidInt(ASTQuery.getData(2), HIDE_ERRORS)
    if (n.isValidIntObj()):
        iEnd = iStart + n.getIntValue() - 1
    else:
        iEnd = iStart + iMaxNum - 1

    prt.setFixedWidthFont()
    ASTCatalog.displayAllObjsByRange(iStart, iEnd)
    prt.setProportionalFont()
    prt.resetCursor()
Пример #11
0
def findConstellationForRA_Decl(gui):
    """
    Finds the constellation that a given RA/Decl falls within.
    
    :param tkwidget gui: GUI object from which the request came
    """
    prt = gui.getPrtInstance()

    # Get RA & Decl
    if (ASTQuery.showQueryForm([
            "Enter Right Ascension (hh:mm:ss.ss) for Epoch 2000.0",
            "Enter Declination (xxxd yym zz.zzs) for Epoch 2000.0"
    ]) != ASTQuery.QUERY_OK):
        return

    strTmp = ASTQuery.getData(1)  # RA
    if ((strTmp == None) or (len(strTmp) <= 0)):
        return
    raObj = ASTTime.isValidTime(strTmp, HIDE_ERRORS)
    if not (raObj.isValidTimeObj()):
        ASTMsg.errMsg("The RA entered is invalid - try again.", "Invalid RA")
        return

    strTmp = ASTQuery.getData(2)  # Decl
    if ((strTmp == None) or (len(strTmp) <= 0)):
        return
    declObj = ASTAngle.isValidAngle(strTmp, HIDE_ERRORS)
    if not (declObj.isValidAngleObj()):
        ASTMsg.errMsg("The Declination entered is invalid - try again.",
                      "Invalid Decl")
        return

    prt.clearTextArea()

    idx = ASTConstellation.findConstellationFromCoord(raObj.getDecTime(),
                                                      declObj.getDecAngle(),
                                                      DEFAULT_EPOCH)

    if (idx < 0):
        ASTMsg.criticalErrMsg(
            "Could not determine a constellation for the data entered.")
    else:
        prt.println("The location " + ASTTime.timeToStr_obj(raObj, HMSFORMAT) +
                    " RA, " + ASTAngle.angleToStr_obj(declObj, DMSFORMAT) +
                    " Decl " + "is in the " +
                    ASTConstellation.getConstName(idx) + " (" +
                    ASTConstellation.getConstAbbrevName(idx) +
                    ") constellation")

    prt.resetCursor()
Пример #12
0
def exitMenuListener():
    """Handle a click on the Exit menu item"""
    if ASTMsg.pleaseConfirm("Are you sure you want to exit?", " "):
        sys.exit()