From 2c6c1c546bbbde07c47a77298147e75d31151fa8 Mon Sep 17 00:00:00 2001 From: Kirpal Demian Date: Mon, 9 Jul 2018 21:23:20 -0400 Subject: [PATCH] Stopped errors when css block has no font property (fixes #41) --- import_keyboard.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/import_keyboard.py b/import_keyboard.py index 3000b43..8ad515a 100644 --- a/import_keyboard.py +++ b/import_keyboard.py @@ -426,26 +426,26 @@ def read(filepath): selectors = filter(None, pair[0].split(",")) - font = list(filter(lambda p: re.sub( - r"\s+", "", p.split(":")[0]) == "font-family", props))[-1] - font = re.sub(r"(\'|\")", "", font.split(":")[1]).strip() + fontProperty = list(filter(lambda p: re.sub(r"\s+", "", p.split(":")[0]) == "font-family", props)) + if len(fontProperty) > 0: + font = re.sub(r"(\'|\")", "", fontProperty[-1].split(":")[1]).strip() - if font in googleFonts.keys(): - tempDir = bpy.app.tempdir - urllib.request.urlretrieve( - googleFonts[font], os.path.join(tempDir, font + ".ttf")) - font = bpy.data.fonts.load( - os.path.join(tempDir, font + ".ttf")) + if font in googleFonts.keys(): + tempDir = bpy.app.tempdir + urllib.request.urlretrieve( + googleFonts[font], os.path.join(tempDir, font + ".ttf")) + font = bpy.data.fonts.load( + os.path.join(tempDir, font + ".ttf")) - else: - font = gotham - - for selector in selectors: - if selector == "*": - fonts = [font for i in range(0, 12)] - elif re.fullmatch(r".keylabel[0-9][1-2]?") and int(selector.replace(".keylabel", "")) >= 0 and int(selector.replace(".keylabel", "")) <= 11: - fonts[int(selector.replace( - ".keylabel", ""))] = font + else: + font = gotham + + for selector in selectors: + if selector == "*": + fonts = [font for i in range(0, 12)] + elif re.fullmatch(r".keylabel[0-9][1-2]?") and int(selector.replace(".keylabel", "")) >= 0 and int(selector.replace(".keylabel", "")) <= 11: + fonts[int(selector.replace( + ".keylabel", ""))] = font bpy.context.window_manager.progress_begin(keyboard["keyCount"], 0) bpy.context.window.cursor_set("DEFAULT")