TagLab icon indicating copy to clipboard operation
TagLab copied to clipboard

Failed to load application font

Open KayelynSimmons-NOAA opened this issue 1 year ago • 1 comments

image (4)

KayelynSimmons-NOAA avatar Apr 07 '23 22:04 KayelynSimmons-NOAA

@KayelynSimmons-NOAA the reason this is happening is that either the fonts folder and / or it's sub-folders are not present in your TagLab folder, or, it's because the function for loading those fonts is not able to find them because the absolute paths are not being return correctly (seems to be an issue with certain Windows computers).

For those in who have this issue in the future, because this is a bug and needs to be adjusted, temporarily you can comment out the sys.exit(-2) calls and see if TagLab loads Roboto correctly, without pulling from the fonts folder (i.e.,, it's pulling from you OS).


if __name__ == '__main__':

   ...

    # set the application font
    if platform.system() != "Darwin":
        QFD = QFontDatabase()
        font_id1 = QFD.addApplicationFont(os.path.join(PATH_FONTS, "opensans/OpenSans-Regular.ttf"))
        if font_id1 == -1:
            print("Failed to load application font..")
            # sys.exit(-2)   <------ Comment out 

        font_id2 = QFD.addApplicationFont(os.path.join(PATH_FONTS, "roboto/Roboto-Light.ttf"))
        if font_id2 == -1:
            print("Failed to load application font..")
            # sys.exit(-2)   <------ Comment out 

        font_id3 = QFD.addApplicationFont(os.path.join(PATH_FONTS, "roboto/Roboto-Regular.ttf"))
        if font_id3 == -1:
            print("Failed to load application font..")
            # sys.exit(-2)   <------ Comment out 

        font = QFont('Roboto')
        app.setFont(font)
        

@massimomartinelli for some reason people are running into this issue, it might be worth modifying the order such that we try to load Roboto first, and if that doesn't work, then try to pull from the fonts folder, and if that doesn't work for some reason, then it's a real issue:


        try:
            font = QFont('Roboto')
            app.setFont(font)
        
        except Exception:
            print("Failed to load native font; attempting to load from file..")
            
        try:
            QFD = QFontDatabase()
            font_id1 = QFD.addApplicationFont(os.path.join(PATH_FONTS, "opensans/OpenSans-Regular.ttf"))
            font_id2 = QFD.addApplicationFont(os.path.join(PATH_FONTS, "roboto/Roboto-Light.ttf"))
            font_id3 = QFD.addApplicationFont(os.path.join(PATH_FONTS, "roboto/Roboto-Regular.ttf"))
    
            font = QFont('Roboto')
            app.setFont(font)
        
        except Exception:
            print("Failed to load application font..")
            sys.exit(-2)

Jordan-Pierce avatar Apr 01 '24 15:04 Jordan-Pierce