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

Improve verification that our fonts are not empty and/or missing #62

Merged
merged 3 commits into from
Jan 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .ciocheck
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
branch = origin/master
diff_mode = commited
file_mode = lines
check = pep8,pydocstyle,flake8,pylint
check = pep8,pydocstyle,flake8
enforce = pep8,pydocstyle,flake8

# Python (pyformat)
Expand Down Expand Up @@ -104,4 +104,4 @@ exclude_lines =
# -----------------------------------------------------------------------------
[pytest]
addopts = -rfew --durations=10
python_functions = test_*
python_functions = test_*
34 changes: 16 additions & 18 deletions qtawesome/iconic_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@ def hook(obj):
directory = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'fonts')

# Load font
id_ = QFontDatabase.addApplicationFont(os.path.join(directory,
ttf_filename))
loadedFontFamilies = QFontDatabase.applicationFontFamilies(id_)
if(loadedFontFamilies):
self.fontname[prefix] = loadedFontFamilies[0]
else:
raise FontError(u"Font at '{0}' appears to be empty. "
"If you are on Windows 10, please read "
"https://support.microsoft.com/en-us/kb/3053676 "
"to know how to prevent Windows from blocking "
"the fonts that come with QtAwesome.".format(
os.path.join(directory, ttf_filename)))

# Verify that font is not corrupt
with open(os.path.join(directory, charmap_filename), 'r') as codes:
self.charmap[prefix] = json.load(codes, object_hook=hook)

Expand All @@ -217,25 +232,8 @@ def hook(obj):
raise FontError(u"Font is corrupt at: '{0}'".format(
os.path.join(directory, ttf_filename)))

id_ = QFontDatabase.addApplicationFont(os.path.join(directory,
ttf_filename))

loadedFontFamilies = QFontDatabase.applicationFontFamilies(id_)

if(loadedFontFamilies):
self.fontname[prefix] = loadedFontFamilies[0]
else:
raise FontError(u"Font at '{0}' appears to be empty. "
"If you are on Windows 10, please read "
"https://support.microsoft.com/en-us/kb/3053676 "
"to know how to prevent Windows from blocking "
"the fonts that come with QtAwesome.".format(
os.path.join(directory, ttf_filename)))

def icon(self, *names, **kwargs):
"""
Return a QIcon object corresponding to the provided icon name.
"""
"""Return a QIcon object corresponding to the provided icon name."""
options_list = kwargs.pop('options', [{}] * len(names))
general_options = kwargs

Expand Down