-
Notifications
You must be signed in to change notification settings - Fork 161
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
Simulator not loaading dynamic fonts #276
Comments
@uraich Could you take a look? |
it doesn't work because there is no The attribute is set for imported modules. I am thinking something may have changed in how the script gets loaded |
I checked the local version of example_roller_3.py and that works fine. If must have to do with the JavaScript version of the interpreter. When I only import lvgl as lv and the display_driver then |
The if you run this code in the simulator it works. import lvgl as lv
import display_driver
script_path = display_driver.__file__[:display_driver.__file__.rfind('/')] if display_driver.__file__.find('/') >= 0 else '.'
print(script_path) the |
@amirgon: Does the simulator access fonts on a different folder than script.py/./../assets/font ? |
it's not that. the problem is literally the |
check this link and look at the error. It points explicitly to line 15 saying the name doesn't exist. |
I am not sure why it doesn't exist because if you add this before that line print(display_driver.__file__) a path does get printed out. |
@uraich I think there is an extra font_montserrat_22 = lv.font_load("S:" + script_path + "/../../assets/font/montserrat-22.fnt") This fails: lv.font_load("S:/../../assets/font/montserrat-22.fnt") But after removing the
The simplest solution is to set try:
script_path = __file__[:__file__.rfind('/')] if __file__.find('/') >= 0 else '.'
except NameError:
script_path = '.' |
so why use the crazy file thing and not hard code the path? if script_path is '' then the font never gets loaded. if This entire code block isn't right. try:
roller1.set_style_text_font(lv.font_montserrat_22,lv.PART.SELECTED)
except:
fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'S')
print("montserrat-22 not enabled in lv_conf.h, dynamically loading the font")
# get the directory in which the script is running
try:
script_path = __file__[:__file__.rfind('/')] if __file__.find('/') >= 0 else '.'
except NameError:
print("Could not find script path")
script_path = ''
if script_path != '':
try:
font_montserrat_22 = lv.font_load("S:" + script_path + "/../../assets/font/montserrat-22.fnt")
roller1.set_style_text_font(font_montserrat_22,lv.PART.SELECTED)
except:
print("Cannot load font file montserrat-22.fnt") because even if the font sets properly it still tried to load the font dynamically. This is better code for handling the dynamic loading of the font. try:
roller1.set_style_text_font(lv.font_montserrat_22 ,lv.PART.SELECTED)
except (NameError, AttributeError):
print(
"montserrat-22 not enabled in lv_conf.h, "
"attempting to dynamically load the font"
)
try:
fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'S')
font_montserrat_22 = lv.font_load(
"S:../../assets/font/montserrat-22.fnt"
)
roller1.set_style_text_font(font_montserrat_22, lv.PART.SELECTED)
except:
print(
"Cannot load font file montserrat-22.fnt, "
"using default font instead"
) |
@kdschlosser Your suggestion is incorrect when running locally and current directory is different than the script's path. |
OK the path to the font is statically set in a relative position to the script. what you are doing with the file thing is you are taking off the filename and then appending onto that the relative path. if you get the absolute path for as an example.. lvgl/src/core/../misc is identical to lvgl/src/misc which is what you are doing with the file the location of the font is in the same relative location to the script you are using a path that is partially absolute and partially relative. This is an even better way of handling the problem try:
roller1.set_style_text_font(lv.font_montserrat_22 ,lv.PART.SELECTED)
except (NameError, AttributeError):
print(
"montserrat-22 not enabled in lv_conf.h, "
"attempting to dynamically load the font"
)
try:
script_path = __file__.split('/')[:-1]
except NameError:
script_path = []
try:
fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'S')
font_montserrat_22 = lv.font_load(
"S:{0}".format('/'.join(script_path + ['../../assets/font/montserrat-22.fnt']))
)
roller1.set_style_text_font(font_montserrat_22, lv.PART.SELECTED)
except:
print(
"Cannot load font file montserrat-22.fnt, "
"using default font instead"
) This way if This is the original code.. I commented why it is wrong. try:
roller1.set_style_text_font(lv.font_montserrat_22, lv.PART.SELECTED) <<< this gets tried and if it succeeds the code in the except block doesn't run
except:
fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'S')
print(
"montserrat-22 not enabled in lv_conf.h, dynamically loading the font"
)
# get the directory in which the script is running
try:
script_path = __file__[:__file__.rfind('/')] if __file__.find('/') >= 0 else '.' <<< even tho the font succeeded in loading this still gets run because it is at the same indentaation level as the try except block before it
except NameError:
print("Could not find script path")
script_path = ''
if script_path != '':
try:
font_montserrat_22 = lv.font_load( <<< This end up failing because the fs_driver was never initialized
"S:" + script_path + "/../../assets/font/montserrat-22.fnt"
)
roller1.set_style_text_font(font_montserrat_22, lv.PART.SELECTED)
except:
print("Cannot load font file montserrat-22.fnt") <<< resulting in this message getting displayed even tho the correct font initially loaded in the first place
you can see they are at the same indent level here,, |
As the title states the Simulator doesn't load fonts from the file system
https://sim.lvgl.io/v9.0/micropython/ports/javascript/index.html?script_startup=https://raw.githubusercontent.com/lvgl/lvgl/091141885abb5fbfbf91d6b8b925d429722a5814/examples/header.py&script=https://raw.githubusercontent.com/lvgl/lvgl/091141885abb5fbfbf91d6b8b925d429722a5814/examples/widgets/roller/lv_example_roller_3.py
The text was updated successfully, but these errors were encountered: