The GlyphPreview object is a simple glyph preview area for use with vanilla windows.

The example script below also shows OpenWindow, a small helper function which prevents RoboFont from opening the same window twice.

fromvanillaimportFloatingWindow,Listfrommojo.glyphPreviewimportGlyphPreviewfrommojo.roboFontimportOpenWindowclassGlyphPreviewExample:def__init__(self):# create a windowself.w=FloatingWindow((400,300),"Preview",minSize=(100,100))# add a list for all glyphs in fontself.w.glyphs=List((10,10,100,-10),[],allowsMultipleSelection=False,selectionCallback=self.showPreviewCallback)# add a GlyphPreview to the windowself.w.preview=GlyphPreview((100,0,-0,-0))# load glyphs from current font to listself.loadGlyphs(CurrentFont())# open the windowself.w.open()defloadGlyphs(self,font):ifnotfont:print('to use this tool, please open a font first')return# load list of glyphsself.w.glyphs.set(font.glyphOrder)defsetGlyph(self,glyph):# set the glyph in the GlyphPreviewself.w.preview.setGlyph(glyph)defshowPreviewCallback(self,sender):# get selected glyphselection=self.w.glyphs.getSelection()ifnotselection:returnselectedGlyph=self.w.glyphs.get()[selection[0]]# set preview in previewf=CurrentFont()iffisnotNone:self.w.preview.setGlyph(f[selectedGlyph])# open the window with OpenWindow, so it cannot be opened twiceOpenWindow(GlyphPreviewExample)