[solved] Shipping resources with an experiment
Howdy!
I have an experiment that requires a font that supports unicode better than the ones shipped with OpenSesame (Bitstream Vera Sans Mono seems to work.) I'd like to include the font in the tar.gz file so that people don't have to deal with putting the resource on their system.
It seems the best way would be to include a resources directory like the pool directory in the tar file, but this does not seem to be currently possible.
Is there a way to hack the pool to work for this? For example, can I put the ttf file in the pool and then add it to the resources of the experiment in some inline code?
Thanks,
Per
I have an experiment that requires a font that supports unicode better than the ones shipped with OpenSesame (Bitstream Vera Sans Mono seems to work.) I'd like to include the font in the tar.gz file so that people don't have to deal with putting the resource on their system.
It seems the best way would be to include a resources directory like the pool directory in the tar file, but this does not seem to be currently possible.
Is there a way to hack the pool to work for this? For example, can I put the ttf file in the pool and then add it to the resources of the experiment in some inline code?
Thanks,
Per
Comments
Hi Per,
It would actually be a good idea to have OpenSesame look in the file pool for resources... I've added this as a feature request: https://github.com/smathot/OpenSesame/issues/26
But, right now, this doesn't work, so you'll have to use a bit of inline code. The following will do (in the prepare phase of an inline_script at the start of the experiment):
import os
import os.path
import shutil
if not os.path.exists("resources"):
os.mkdir("resources")
shutil.copy(self.experiment.get_file("my_font.ttf"), "resources")
This copies "my_font.ttf" from the file pool to the resources folder. You can then use this font in sketchpads and in inline code as "my_font" (you'll have to edit the script of sketchpad items to do this, because the GUI doesn't recognize custom fonts).
You could also use the name "sans.ttf", but on Windows this will overwrite the original "sans.ttf", so it's probably better to use a custom name.
Hope this helps!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
As usual, works like a charm! It'll be a one-line change to have resources look in the pool, so I bet we can get that in the next release.
Thanks!
Per