Observers

An observer has to be subscribed to an specific event. When the event happens the observer will get a notification.

from mojo.drawingTools import *
from mojo.events import addObserver

class DrawTest:
    def __init__(self):
        ## add an observer for the draw event
        addObserver(self, "drawSomething", "draw")

    def drawSomething(self, info):
        ## draw something the glyph view
        rect(100, 100, 100, 100)

DrawTest()

Real live example drawing a reference to the current glyph in the Glyph View using the unicode value of the glyph:

"""
An example script of adding an observers and do *something* 

It draws a simple unicode reference of an existing installed font.
"""

from mojo.events import addObserver
from mojo.drawingTools import *

class DrawReferenceGlyph(object):
    
    def __init__(self):
        addObserver(self, "drawReferenceGlyph", "draw")

    def drawReferenceGlyph(self, info):
        
        glyph = info["glyph"]
        
        r = 0
        g = 0
        b = 0
        a = .5
        
        if glyph is not None and glyph.unicode is not None and glyph.unicode < 0xFFFF:
            t = unichr(glyph.unicode)
            
            font("Georgia", 20)
            stroke(None)
            fill(r, g, b, a)
            text(t, (glyph.width + 10, 10))
            
            
DrawReferenceGlyph()

More observers examples.

Events

Any observer can subscriber to these events. The callback receives a dictionary object containing additional objects related to the send event.

Subscribe an observer with addObserver(), remove them with removeObserver().

All notification dictionaries contains the following keys:

glyph

The current/edited/active glyph.

tool

The current tool.

view

The current glyph view.

applicationDidFinishLaunching

Send when RoboFont did finish launching.

applicationDidBecomeActive

Send when RoboFont become the active application.

applicationWillResignActive

Send when RoboFont resigns being the active application.

binaryFontWillOpen

Send when a binary font will open.

font

The font object.

source

The fontTools source object.

format

The format of the source font.

fontWillSave

Send when a font will save.

font

The font object.

path

The path where the font will be saved.

fontDidSave

Send when a font is done saving.

font

The font object.

path

The path where the font did save.

fontWillClose

Send when a font will close.

font

The font object.

newFontWillOpen

Send when a new font will open.

font

The font object.

newFontDidOpen

Send when a new font did open.

font

The font object.

fontWillOpen

Send when a font will open.

font

The font object.

fontDidOpen

Send when a font did open.

font

The font object.

fontWillAutoSave

Send when a font will auto save.

font

The font object.

path

The path where the font did autosave.

fontDidAutoSave

Send when a font did auto save.

font

The font object.

path

The path where the font did autosave.

fontDidChangeExternally

Send when a font did change externally, outside RoboFont.

font

The font object.

fontWillGenerate

Send when a font will generate.

font

The font object.

format

The format of the generated font.

path

The path where the binary font will save.

fontDidGenerate

Send when a font did generate.

font

The font object.

format

The format of the generated font.

path

The path where the binary font will save.

currentGlyphChanged

Send when the current glyph changed, this can be either in the glyph view or in the font overview.

viewWillChangeGlyph

Send when the glyph view will switch to an other glyph.

viewDidChangeGlyph

Send when the glyph view did switch to an other glyph.

glyphWindowWillOpen

Send when a glyph window will open.

window

The glyph window that will open.

glyphWindowDidOpen

Send when a glyph window did open.

window

The glyph window that did open.

glyphWindowWillClose

Send when a glyph window will close.

window

The glyph window that will close.

spaceCenterWillOpen

Send when a space center will open.

window

The space center window that will open.

spaceCenterDidOpen

Send when a space center did open.

window

The space center window that did open.

spaceCenterWillClose

Send when a space center will close.

window

The space center window that will close.

transformChanged

Send when a transformation is applied to a glyph.

scale
translate
rotate
skew
repeatMatrix
extensionDidGenerate

Send when an extension did generate.

path

The path to the extension.

spaceCenterDraw

Send when a space center draws a glyph, this can happen a lot so be care full.

scale

The drawing scale.

spaceCenter

The space center.

selected

A bool if the glyph is selected in the space center.

spaceCenterKeyDown

Send on a key down in a space center.

event

The NSEvent object.

spaceCenter

The space center.

spaceCenterKeyUp

Send on a key up in space center.

event

The NSEvent object.

spaceCenter

The space center.

drawPreview

Send when the glyph view draws a preview.

scale
drawBackground

Send when the glyph view draws the background, before the actual glyph data.

scale
draw

Send when the glyph view draw the glyph data.

scale
drawInactive

Send when the glyph view draw when the glyph window is not the active one.

scale
mouseDown

Send on mouse down in the glyph view. point the point coordinates of the mouse in the glyph coordinate system

clickCount

The click count.

offset

Offset of the zero zero point in the glyph view.

event

The NSEvent object.

rightMouseDown

Send on right mouse down in the glyph view.

point

The point coordinates of the mouse in the glyph coordinate system.

event

The NSEvent object.

mouseDragged

Send on a mouse drag in the glyph view.

point

The point coordinates of the mouse in the glyph coordinate system.

offset

Offset of the zero zero point in the glyph view.

delta

Delta of the drag form the first click.

event

The NSEvent object.

rightMouseDragged

Send on a right mouse drag in the glyph view.

point

The point coordinates of the mouse in the glyph coordinate system.

offset

Offset of the zero zero point in the glyph view.

event

The NSEvent object.

mouseUp

Send on a mouse up in the glyph view.

point

The point coordinates of the mouse in the glyph coordinate system.

offset

Offset of the zero zero point in the glyph view.

event

The NSEvent object.

keyDown

Send on a key down in the glyph view.

event

The NSEvent object.

keyUp

Send on a key up in the glyph view.

event

The NSEvent object.

modifiersChanged

Send when the modifier changed in the glyph view (command, alt, control and shift keys)

event

The NSEvent object.

toggleTransformMode

Send when the glyph view toggles from or out the transform mode.

acceptMenuEditCallbacks

Send when a contextual menu is been build.

item

A menu item.

selectAll

Send on select all in the glyph view.

deselectAll

Send on deselect all in the glyph view.

selectAllAlternate

Send on select all alternate in the glyph view.

copy

Send on copy in the glyph view.

copyAsComponent

Send on copy as component in the glyph view.

cut

Send on cut in the glyph view.

delete

Send on delete in the glyph view.

paste

Send on paste in the glyph view.