The icons in the user interface are based on the qtawesome library but there has been the need to extend the provided additional custom icons.
Icons are provided to the code via a Singleton object icon.py
. in the openlp.core.ui
package.
There is a mapping between the code tag for the icon and the actual icon implementation name provided by qtawesome.
Any icon extensions are also loaded and managed by this class. This has allowed us to create our own icons.
In openlp.core.ui.fonts
directory there is a file called openlp.std. This contains the icon images, it is a clone of qtawesome to allow some examples to be available, only the Openlp fonts are loaded from here.
This file is best edited using FontForge.
Inside the file, there are slots for the individual icon images and the openlp custom ones are on the first page.
FontForge will also allow this file to be compiled to openlp.tff which is used at run time and resides in the same directory. the icon.py
code loads this file are startup.
To map between an individual font in the tff file and the application code, a record needs to be added to openlp-charmap.json
. This file and the tff file are used by qtawesome to load the fonts and allow the code to have access to them.
To find an existing font name, search the json files for the font name using a text editor or a text search tool like grep.
Qtawesome loads its fonts under the mdi1 handle. To see all of the possible handles take a look at https://pypi.org/project/QtAwesome/. OpenLP loads its fonts under the op handle.
This means it is obvious in the code where a font comes from. In python 3.7 this is where the files come from.
The ttf files contain the actual icons and the json files contain the mapping. Below is the lynx file locations and filenames. The same files are located at <username>\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\qtawesome\fonts
/usr/lib/python3.7/site-packages/qtawesome/fonts/elusiveicons-webfont-charmap.json
/usr/lib/python3.7/site-packages/qtawesome/fonts/elusiveicons-webfont.ttf
/usr/lib/python3.7/site-packages/qtawesome/fonts/fontawesome4.7-webfont-charmap.json
/usr/lib/python3.7/site-packages/qtawesome/fonts/fontawesome4.7-webfont.ttf
/usr/lib/python3.7/site-packages/qtawesome/fonts/fontawesome5-brands-webfont-charmap.json
/usr/lib/python3.7/site-packages/qtawesome/fonts/fontawesome5-brands-webfont.ttf
/usr/lib/python3.7/site-packages/qtawesome/fonts/fontawesome5-regular-webfont-charmap.json
/usr/lib/python3.7/site-packages/qtawesome/fonts/fontawesome5-regular-webfont.ttf
/usr/lib/python3.7/site-packages/qtawesome/fonts/fontawesome5-solid-webfont-charmap.json
/usr/lib/python3.7/site-packages/qtawesome/fonts/fontawesome5-solid-webfont.ttf
/usr/lib/python3.7/site-packages/qtawesome/fonts/materialdesignicons-webfont-charmap.json
/usr/lib/python3.7/site-packages/qtawesome/fonts/materialdesignicons-webfont.ttf
In addition to mapping icons, it is possible to amend a number of attributes. The array of icon mappings in the code allows this to happen. If an icon is defined but not found, a default icon is provided so the code will load and work, you will just get a red cross.
1: OpenLP has changed, between versions 3.0.2 and 3.1.0, to use mdi
icons (from materialdesignicons.com) instead of fa
(Font Awesome). This was done due to questions regarding Font Awesome 5 license and Debian.