This example shows how to use a GlyphLineView to display glyphs from various fonts. The preview shows the current glyph in all open fonts, and is updated when the current glyph changes.

import vanilla
from defconAppKit.windows.baseWindow import BaseWindowController
from defconAppKit.controls.glyphLineView import GlyphLineView
from mojo.events import addObserver, removeObserver

class MultiFontPreview(BaseWindowController):

    def __init__(self):
        self.w = vanilla.Window((400, 400), minSize=(100, 100))
        self.w.glyphLineView = GlyphLineView((0, 0, 0, 0), pointSize=None, autohideScrollers=False, showPointSizePlacard=True)
        addObserver(self, "glyphChanged", "currentGlyphChanged")
        self.glyphChanged(dict(glyph=CurrentGlyph()))
        self.setUpBaseWindowBehavior()
        self.w.open()

    def windowCloseCallback(self, sender):
        removeObserver(self, "currentGlyphChanged")
        super(MultiFontPreview, self).windowCloseCallback(sender)

    def glyphChanged(self, info):
        glyph = CurrentGlyph()
        if glyph is None:
            glyphs = []
        else:
            glyphName = glyph.name
            glyphs = [font[glyphName].naked() for font in AllFonts() if glyphName in font]
        self.w.glyphLineView.set(glyphs)

MultiFontPreview()
Last edited on 02/06/2020