Using tkFont from tkinter to identify if a font (Helvetica-Light) is available/installed Using tkFont from tkinter to identify if a font (Helvetica-Light) is available/installed tkinter tkinter

Using tkFont from tkinter to identify if a font (Helvetica-Light) is available/installed


I ended up writing a shell based method to call the fc-list terminal command:

def verify_fonts_are_installed_for_statements():    import subprocess    from os import path    potential_locations = [        '/usr/bin/fc-list',        '/usr/sbin/fc-list',        '/usr/local/sbin/fc-list',        '/usr/local/bin/fc-list',    ]    valid_path = None    for file_path in potential_locations:        if path.exists(file_path):            valid_path = file_path            break    if valid_path is None:        raise IOError('could not find fc-list to verify fonts exist.')    cmd = [valid_path]    output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]    if 'Helvetica Neue' not in output:        raise FontNotInstalledException('Helvetica Neue')    if 'Courier' not in output:        raise FontNotInstalledException('Courier')    log.debug('Courier and Helvetica Neue were found to be installed.')