Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to load application font #97

Open
KayelynSimmons-NOAA opened this issue Apr 7, 2023 · 1 comment
Open

Failed to load application font #97

KayelynSimmons-NOAA opened this issue Apr 7, 2023 · 1 comment

Comments

@KayelynSimmons-NOAA
Copy link

image (4)

@Jordan-Pierce
Copy link

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants