Resources#
An instance of the Resources class holds information about fonts, code syntaxes and themes, and loaded images. By default, an instance of SlideDeck creates its own instance of Resources, but you can create your own instance and pass it to the SlideDeck constructor.
There are two main scenarios where it is useful to create your own instance of `Resources'.
- You want to register your own fonts, code syntaxes, or code themes
- You create more instances of
SlideDeck
and you want to skip some initialization or to skip loading the same images repeatedly.
Resources
instance can also provide a list of available syntaxes and syntax highlighting themes.
Registering own fonts#
from nelsie import Resources, SlideDeck
resources = Resources()
resources.load_fonts_dir("path/to/fonts")
deck = SlideDeck(resources=resources)
When you load new fonts, you may want to register it as generic families fonts:
resources.set_sans_serif("Font for Sans")
resources.set_monospace("Font For Monospace")
resources.set_serif("Font for Serif")
Loading system fonts#
By default, Nelsie loads a fonts shipped together with Nelsie and ignores system fonts. You can change this by the following command and load system fonts from your system.
Warning
The current text rendering engine used in Nelsie tries to preload some font data. So loading system fonts may take some time. On normal system it should be around 0.1s, but if you have many fonts installed it may be significantly slower. The solution is to create a directory only with fonts that you are using in your slides and do not load all system fonts in such situations. It would also make your slides more replicable on other computers.
When you do not load build fonts, do not forget to set basic font set to existing fonts:
resources.set_sans_serif("Font for Sans")
resources.set_monospace("Font For Monospace")
ressources.set_serif("Font for Serif")
Loading custom code syntaxes#
Nelsie supports loading syntax files from Sublime editor (files with .sublime-syntax
extension).
from nelsie import Resources, SlideDeck
resources = Resources(default_code_syntaxes=False)
resources.load_code_syntax_dir("path/to/syntaxes")
deck = SlideDeck(resources=resources)
Known bug
If you want to add custom syntax definitions, you have to disable loading default syntaxes (default_code_syntaxes=False
) otherwise .load_code_syntax_dir()
will not work.
Loading custom code color themes#
Nelsie supports loading color theme thTheme
(files with .thTheme
extension).
from nelsie import Resources, SlideDeck
resources = Resources()
resources.load_code_theme_dir("path/to/themes")
deck = SlideDeck(resources=resources)
Reusing resources in more slide decks#
from nelsie import Resources, SlideDeck
resources = Resources()
deck1 = SlideDeck(resources=resources)
deck2 = SlideDeck(resources=resources)