This is a useful tool when learning to work with observers in RoboFont: it shows when each observer is fired, and the contents of each notification.

Don’t worry too much about understanding the code in this example. Focus on learning the different notifications. Open a font, click around in the Font Overview, Glyph Editor and Space Center – look at the updates in the notifications list.

Observes objects and displays attributes which are available in the callback info dict.

from vanilla import *
from AppKit import *
from import BaseWindowController
from import addObserver, removeObserver

class NotificationItem(object):

    def __init__(self, notification):
        self.notification = notification

    def __repr__(self):
        return self.notification["notificationName"]

keyAttributes = {NSFontAttributeName : NSFont.fontWithName_size_("Menlo-Bold", 15)}

valueAttributes = {NSFontAttributeName : NSFont.fontWithName_size_("Menlo-Bold", 10), NSForegroundColorAttributeName : NSColor.darkGrayColor()}

class Observer(BaseWindowController):

    def __init__(self):

        self.w = Window((400, 400), "mojo.event observer", minSize=(200, 200))
        self.w.list = List((10, 10, 200, -40), [], selectionCallback=self.listSelection) = TextEditor((220, 10, -10, -40), readOnly=True)
        self.w.ignoreText = TextBox((10, -30, 100, 22), "Ignore:")
        self.w.ignore = EditText((70, -30, -100, 22), "mouseMoved")
        self.w.clear = Button((-70, -30, 60, 22), "Clear", self.clearListCallback)

        addObserver(self, "notification", None)

    def windowCloseCallback(self, sender):
        removeObserver(self, None)
        super(Observer, self).windowCloseCallback(sender)

    def listSelection(self, sender):
        sel = sender.getSelection()
        for i in sel:
            item = sender[i]
            notification = item.notification

            keys = notification.keys()

            txt = NSMutableAttributedString.alloc().init()

            for key in keys:
                attributedString = NSMutableAttributedString.alloc().initWithString_attributes_(key, keyAttributes)

                value = "\n%s\n\n" % notification[key]

                attributedString = NSMutableAttributedString.alloc().initWithString_attributes_(value, valueAttributes)


    def clearListCallback(self, sender):

    def notification(self, notification):
        if notification["notificationName"] in self.w.ignore.get().split(" "):

Last edited on 12/07/2018