This example shows how to draw inside the glyph cells of the Font Overview.

The script opens a dialog containing a button to add or remove a ‘label’ to the selected glyphs in the Font Overview.

The state of this ‘label’ is stored in a custom key in the glyph lib. When the Font Overview is refreshed, a small rectangle is drawn inside the cells of all glyphs which have this value set to True.

When the dialog is closed, the observer is removed and the labels are cleared.

from vanilla import FloatingWindow, SquareButton
from import addObserver, removeObserver
from mojo.drawingTools import *

class CustomGlyphCellLabel:

    key = "com.myDomain.customGlyphCellLabel"

    def __init__(self):
        self.w = FloatingWindow((180, 52), "custom labels")
        self.w.button = SquareButton((10, 10, -10, -10), "add/remove label", callback=self.actionCallback)
        self.w.bind("close", self.closeCallback)
        addObserver(self, "drawCell", "glyphCellDrawBackground")

    def drawCell(self, info):
        glyph = info["glyph"]
        value = glyph.lib.get(self.key)
        if value:
            fill(1, 0, 0)
            rect(0, 0, 10, 10)

    def actionCallback(self, sender):
        font = CurrentFont()
        if font is None:

        for glyphName in font.selectedGlyphNames:
            # get current value
            value = font[glyphName].lib.get(self.key, False)
            # toggle value
            font[glyphName].lib[self.key] = not value

    def closeCallback(self, sender):
        font = CurrentFont()
        if font is None:

        for glyph in font:
            if not self.key in glyph.lib:
            del glyph.lib[self.key]

        removeObserver(self, "glyphCellDrawBackground")

Last edited on 01/09/2021