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.
"""fromvanillaimport*fromAppKitimport*fromdefconAppKit.windows.baseWindowimportBaseWindowControllerfrommojo.eventsimportaddObserver,removeObserverclassNotificationItem(object):def__init__(self,notification):self.notification=notificationdef__repr__(self):returnself.notification["notificationName"]keyAttributes={NSFontAttributeName:NSFont.fontWithName_size_("Menlo-Bold",15)}valueAttributes={NSFontAttributeName:NSFont.fontWithName_size_("Menlo-Bold",10),NSForegroundColorAttributeName:NSColor.darkGrayColor()}classObserver(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)self.w.info=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)self.setUpBaseWindowBehavior()self.w.open()defwindowCloseCallback(self,sender):removeObserver(self,None)super(Observer,self).windowCloseCallback(sender)deflistSelection(self,sender):sel=sender.getSelection()foriinsel:item=sender[i]notification=item.notificationkeys=notification.keys()keys.sort()txt=NSMutableAttributedString.alloc().init()forkeyinkeys:attributedString=NSMutableAttributedString.alloc().initWithString_attributes_(key,keyAttributes)txt.appendAttributedString_(attributedString)value="\n%s\n\n"%notification[key]attributedString=NSMutableAttributedString.alloc().initWithString_attributes_(value,valueAttributes)txt.appendAttributedString_(attributedString)self.w.info.getNSTextView().textStorage().setAttributedString_(txt)defclearListCallback(self,sender):self.w.list.set([])self.w.info.set("")defnotification(self,notification):ifnotification["notificationName"]inself.w.ignore.get().split(" "):returnself.w.list.append(NotificationItem(notification))self.w.list.getNSTableView().scrollRowToVisible_(len(self.w.list)-1)Observer()