Skip to content

Commit ba35bb6

Browse files
Add check for font directory when using frozen package
1 parent f045829 commit ba35bb6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

qwiic_oled/oled_fonts.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,25 @@ def __getitem__(self, key):
142142
return self._fontData[key]
143143

144144

145+
def _check_if_exists(filename):
146+
"""!
147+
Checks if a file or directory exists. Works on MicroPython and CircuitPython
148+
which do not have os.path functions (as well as Linux which does).
149+
"""
150+
try:
151+
os.stat(filename)
152+
return True
153+
except:
154+
return False
155+
145156
# handy util
146-
147157
def _getFontDir():
148158

159+
# First check if font directory exists where it is installed when using a frozen SparkFun MicroPython package
160+
# It should exist in "_frozen_data" if the package is frozen
161+
if _check_if_exists("_frozen_data" + os.sep + "fonts"):
162+
return "_frozen_data" + os.sep + "fonts"
163+
149164
return __file__.rsplit(os.sep, 1)[0] + os.sep + "fonts"
150165

151166
#-----------------------------------------

0 commit comments

Comments
 (0)