-
-
Save frankrolf/6732be11e1efb4bdc506039f7f864592 to your computer and use it in GitHub Desktop.
An example to show how to make defcon notifications in RoboFont
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mojo.events import addObserver, removeObserver | |
from vanilla import Window | |
class RoboFontDefconExample(): | |
def __init__(self): | |
self.w = Window((300, 120), "Debuggin window") | |
self.fonts = {} | |
for f in AllFonts(): | |
self._addFont(f) | |
addObserver(self, "_fontDidOpen", "fontDidOpen") | |
addObserver(self, "_fontWillClose", "fontWillClose") | |
self.w.bind("close", self.destroy) | |
self.w.open() | |
def _fontDidOpen(self, info): | |
f = info['font'] | |
self._addFont(f) | |
def _fontWillClose(self, f): | |
self._removeFont(f) | |
def _addFont(self, f): | |
fontID = list(f.naked().identifiers)[0] | |
self.fonts[fontID] = f | |
f = f.naked() | |
f.dispatcher.addObserver(observer=self, methodName="_glyphNameChanged", notification="Glyph.NameChanged", observable=None) | |
f.dispatcher.addObserver(observer=self, methodName="_glyphUnicodesChanged", notification="Glyph.UnicodesChanged", observable=None) | |
f.dispatcher.addObserver(observer=self, methodName="_glyphShapeChanged", notification="Glyph.ContoursChanged", observable=None) | |
f.dispatcher.addObserver(observer=self, methodName="_glyphShapeChanged", notification="Glyph.ComponentsChanged", observable=None) | |
f.dispatcher.addObserver(observer=self, methodName="_glyphChanged", notification="Glyph.Changed", observable=None) | |
f.dispatcher.addObserver(observer=self, methodName="_glyphWidthChanged", notification="Glyph.WidthChanged", observable=None) | |
def _removeFont(self, f): | |
fontID = list(f.naked().identifiers)[0] | |
del self.fonts[fontID] | |
f = f.naked() | |
f.dispatcher.removeObserver(observer=self, notification="Glyph.NameChanged") | |
f.dispatcher.removeObserver(observer=self, notification="Glyph.UnicodesChanged") | |
f.dispatcher.removeObserver(observer=self, notification="Glyph.ContoursChanged") | |
f.dispatcher.removeObserver(observer=self, notification="Glyph.ComponentsChanged") | |
f.dispatcher.removeObserver(observer=self, notification="Glyph.Changed") | |
f.dispatcher.removeObserver(observer=self, notification="Glyph.WidthChanged") | |
def _glyphNameChanged(self, info): | |
print('_glyphNameChanged', info) | |
def _glyphUnicodesChanged(self, info): | |
print('_glyphUnicodesChanged', info) | |
def _glyphShapeChanged(self, info): | |
print('_glyphShapeChanged', info) | |
def _glyphChanged(self, info): | |
print('_glyphChanged', info) | |
def _glyphWidthChanged(self, info): | |
print('_glyphWidthChanged', info) | |
def destroy(self, sender): | |
removeObserver(self, "fontDidOpen") | |
removeObserver(self, "fontWillClose") | |
for f in list(self.fonts.values()): | |
self._removeFont(f) | |
rfd = RoboFontDefconExample() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment