mojo.events

publishEvent(key, **attr)

Publish an event with additional info to the active tool and to all observers.

postEvent(key, **attr)

Post an event with additional info to all observers.

This will not be posted to the active tool.

installTool(event, updateGlyphWindow=True)

Install a tool object.

uninstallTool(event, updateGlyphWindow=True)

Uninstall a tool object.

addObserver(observer, method, event, identifier=None)

Add an observer object for an event with a callback method. Optionally an identifier can be provided, must be a str and should not be unique.

from mojo.events import addObserver

class MyObserver(object):

    def __init__(self):
        addObserver(self, 'myCallback', 'drawBackground')

    def myCallback(self, info):
        # draw here
        pass

removeObserver(observer, event)

Remove an observer object.

findObservations(observer=None, event=None, identifier=None)

Return a list of all observations.

getToolOrder()

Return the tool order in the UI.

setToolOrder(newOrder, updateGlyphWindow=True)

Set a new tool order. The newOrder must have the same tools as the old order, only the order can change.

clearObservers()

Clear all observers.

This should never be called directly, as it will invalidate all existing observers. It is recommended that the observer removes itself when it’s done observing an event.

allObservers()

Return a list of all running observers.

disableEvents()

Disables all events.

enableEvents()

Enables all events.

setActiveEventTool(name)

Set the active tool by name.

setActiveEventToolByIndex(index, window=None)

Set the active tool by index.

getActiveEventTool()

Returns the active tool.

extractNSEvent(nsEvent)

Return a dictionary with data extracted from the NSEvent object, with the following keys:

keyDown
The pressed character.
keyDownWithoutModifiers
The pressed characters with modifiers.
up
A bool indicating if the up arrow key is pressed.
down
A bool indicating if the down arrow key is pressed.
left
A bool indicating if the left arrow key is pressed.
right
A bool indicating if the right arrow key is pressed.
shiftDown
A bool indicating if the Shift modifier key is pressed.
capLockDown
A bool indicating if the Caps Lock modifier key is pressed.
optionDown
A bool indicating if the Option modifier key is pressed.
controlDown
A bool indicating if the Control modifier key is pressed.
commandDown
A bool indicating if the Command modifier key is pressed.

class BaseEventObserver()

A simple event observer that can help receiving events and silently catch TypeErrors.

class BaseEventTool()

The base event tool contains all possible callbacks, and does nothing.

allPointList

A list of clicked and dragged points used by the tool.

arrowKeysDown

A dictionary of bools indicating if the arrow keys are pressed: up, down, left, right.

capLockDown

Bool indicating if the Caps Lock key is pressed.

commandDown

Bool indicating if the Command key is pressed.

controlDown

Bool indicating if the Control key is pressed.

currentPoint

Get the mouse position as a point object.

mouseDownPoints

A list of clicked points used by the tool.

optionDown

Bool indicating if the Option key is pressed.

selection

Get the selection object of the current glyph in the glyph view.

shiftDown

Bool indicating if the Shift key is pressed.

spaceBarDown

Bool indicating if the space bar is pressed.

acceptMenuEditCallbacks(menuItem=None)

Called by the glyph view when a menu item is validated. Should return a bool.

addMarqueRectLayer()

addSelectionLayer()

addedUndoItem(notification)

Called when an addedUndoItem event is posted.

You must overwrite this to change the behavior.

def addedUndoItem(self, notification):
    ## do stuff

Don’t call it externally.

additionContextualMenuItems()

Return a list of tuples formatted as [(title, callback)].

The callback can be a list object to create a submenu for the title.

Use this method to add items to the contextual menu.

def additionContextualMenuItems(self):
    return [("additional stuff", myObject.myAdditionMenuCallback), ]

Don’t call it externally.

applicationDidBecomeActive()

Called when a RoboFont became active event is posted.

You must overwrite this to change the behavior.

def applicationDidBecomeActive(self):
    ## do stuff

Don’t call it externally.

applicationDidFinishLaunching()

Called when a RoboFont finished launching event is posted.

You must overwrite this to change the behavior.

def applicationDidFinishLaunching(self):
    ## do stuff

Don’t call it externally.

applicationScreenChanged()

Called when a RoboFont detects a change in screens event is posted.

You must overwrite this to change the behavior.

def applicationScreenChanged(self):
    ## do stuff

Don’t call it externally.

applicationWillResignActive()

Called when a RoboFont will resign active event is posted.

You must overwrite this to change the behavior.

def applicationWillResignActive(self):
    ## do stuff

Don’t call it externally.

becomeActive()

Called when a tool become active event is posted.

You must overwrite this to change the behavior.

def becomeActive(self):
    ## do stuff

Don’t call it externally.

becomeInactive()

Called when a tool become inactive event is posted.

You must overwrite this to change the behavior.

def becomeInactive(self):
    ## do stuff

Don’t call it externally.

binaryFontWillOpen(font, source, format)

Called when a new binary font will open event is posted.

You must overwrite this to change the behavior.

def binaryFontWillOpen(self, font, source):
    ## do stuff

Don’t call it externally.

copyAsComponent()

Called when a copy as component event is posted.

You must overwrite this to change the behavior.

def copyAsComponent(self):
    ## do stuff

Don’t call it externally.

currentGlyphChanged()

Called when the current glyph changed event is posted.

You must overwrite this to change the behavior.

def currentGlyphChanged(self):
    ## do stuff

Don’t call it externally.

cut()

Called when a cut event is posted.

You must overwrite this to change the behavior.

def cut(self):
    ## do stuff

Don’t call it externally.

delete()

Called when a delete event is posted.

You must overwrite this to change the behavior.

def delete(self):
    ## do stuff

Don’t call it externally.

deselectAll()

Called when a deselect all event is posted.

You must overwrite this to change the behavior.

def deselectAll(self):
    ## do stuff

Don’t call it externally.

didSetup()

Return a bool if the setup is done,

Overwrite if you want to change the default behavior.

Don’t call it externally.

didUndo(notification)

Called when an undo event is posted.

You must overwrite this to change the behavior.

def didUndo(self, notification):
    ## do stuff

Don’t call it externally.

draw(scale=1)

Called when a draw event is posted.

You must overwrite this to change the behavior.

def draw(self, scale):
    ## do stuff

Don’t call it externally.

draw callbacks are deprecated use merz layers instead.

drawBackground(scale=1)

Called when a draw background event is posted.

You must overwrite this to change the behavior.

def drawBackground(self, scale):
    ## do stuff

Don’t call it externally.

draw callbacks are deprecated use merz layers instead.

drawBackgroundSelection(scale)

drawInactive(scale=1, glyph=None, view=None)

Called when a draw inactive event is posted.

You must overwrite this to change the behavior.

def drawInactive(self, scale):
    ## do stuff

Don’t call it externally.

drawInactive callbacks are deprecated use merz layers instead.

drawPreview(scale=1)

Called when a draw preview event is posted.

You must overwrite this to change the behavior.

def drawPreview(self, scale):
    ## do stuff

Don’t call it externally.

drawPreview callbacks are deprecated use merz layers instead.

drawSelection(scale, glyph=None, view=None)

extensionContainer(identifier=None, location='foreground', clear=True)

Return a tool specific merz layer.

The location argument can be foreground, background, middleground or preview.

When identifier is None the name of the tool class will be used as the identfier.

fontBecameCurrent(font)

Called when a font became current event is posted.

You must overwrite this to change the behavior.

def fontBecameCurrent(self, font):
    ## do stuff

Don’t call it externally.

fontDidAutoSave(font, path)

Called when a font did auto save event is posted.

You must overwrite this to change the behavior.

def fontDidAutoSave(self, font):
    ## do stuff

Don’t call it externally.

fontDidChangeExternally(font)

fontDidGenerate(font, format, path, layerName)

Called when a font did generate a binary event is posted.

You must overwrite this to change the behavior.

def fontDidGenerate(self, font, format, path, layerName):
    ## do stuff

Don’t call it externally.

fontDidOpen(font)

Called when a font did open event is posted.

You must overwrite this to change the behavior.

def fontDidOpen(self, font):
    ## do stuff

Don’t call it externally.

fontDidSave(font, path)

Called when a font did save event is posted.

You must overwrite this to change the behavior.

def fontDidSave(self, font):
    ## do stuff

Don’t call it externally.

fontResignCurrent(font)

Called when a font resign current event is posted.

You must overwrite this to change the behavior.

def fontResignCurrent(self, font):
    ## do stuff

Don’t call it externally.

fontWillAutoSave(font, path)

Called when a font will auto save event is posted.

You must overwrite this to change the behavior.

def fontWillAutoSave(self, font):
    ## do stuff

Don’t call it externally.

fontWillClose(font)

Called when a font will close event is posted.

You must overwrite this to change the behavior.

def fontWillClose(self, font):
    ## do stuff

Don’t call it externally.

fontWillGenerate(font, format, path, layerName, testInstall=False)

Called when a font will generate a binary event is posted.

You must overwrite this to change the behavior.

def fontWillGenerate(self, font, format, path, layerName, testInstall):
    ## do stuff

Don’t call it externally.

fontWillOpen(font)

Called when a font will open event is posted.

You must overwrite this to change the behavior.

def fontWillOpen(self, font):
    ## do stuff

Don’t call it externally.

fontWillSave(font, path)

Called when a font will save event is posted.

You must overwrite this to change the behavior.

def fontWillSave(self, font):
    ## do stuff

Don’t call it externally.

getArrowsKeys()

Return a dictionary of arrow keys pressed.

True means that a key is pressed down.

Keys are: up, down, left, right.

getCALayer(identifier=None, location='foreground', clear=True)

Return a tool specific ca layer.

The location argument can be foreground, background, middleground or preview.

getCurrentEvent()

Return the current event.

getDefaultCursor()

Return the cursor used by the tool.

Create cursors with mojo.roboFont.CreateCursor.

getGlyph(naked=False)

Return the current glyph assigned to the tool as a FontParts object.

getMarqueRect(offset=None, previousRect=False)

Return the marquee rect. Overwrite if you want to change the default behavior.

getModifiers()

Return a dictionary with all the modifier keys as boolean values.

True means that a key is pressed down.

Keys are: shiftDown, capLockDown, commandDown, optionDown, controlDown.

getToolbarIcon()

Return the toolbar icon for the tool.

getToolbarTip()

Return the toolbar tool tip for the tool.

glyphWindowDidOpen(window)

Called when a Glyph Window did open event is posted.

You must overwrite this to change the behavior.

def glyphWindowDidOpen(self, window):
    ## do stuff

Don’t call it externally.

glyphWindowWillClose(window)

Called when a Glyph Window will close event is posted.

You must overwrite this to change the behavior.

def glyphWindowWillClose(self, window):
    ## do stuff

Don’t call it externally.

glyphWindowWillOpen(window)

Called when a Glyph Window will open event is posted.

You must overwrite this to change the behavior.

def glyphWindowWillOpen(self, window):
 ## do stuff

Don’t call it externally.

isDragging()

A bool indicating when a tool is in a dragging action.

isInvalidEventTool()

A bool indicating if the tool is valid.

A tool is valid when it has a current glyph and a current glyph view.

keyDown(event)

Called when a key down event is posted.

You must overwrite this to change the behavior.

def keyDown(self, event):
    ## do stuff

Don’t call it externally.

keyUp(event)

Called when a key up event is posted.

You must overwrite this to change the behavior.

def keyUp(self, event):
    ## do stuff

Don’t call it externally.

modifiersChanged()

Called when a modifier changed event is posted.

You must overwrite this to change the behavior.

def modifiersChanged(self):
    ## do stuff

Don’t call it externally.

modifyDraggingPoint(point, delta)

Called while dragging a point with the mouse to modify it. Used to change the point, for example when Shift is pressed.

You must overwrite this to change the behavior.

def modifyDraggingPoint(self, point, delta):
    ## do stuff
    return point, delta

Don’t call it externally.

modifyPoint(point)

Called when a mouse down event is posted to modify the mouse down point. Used to change the point, for example when Shift is pressed.

You must overwrite this to change the behavior.

def modifyPoint(self, point):
    ## do stuff
    return point

Don’t call it externally.

mouseDown(point, clickCount)

Called when a mouse down event is posted.

You must overwrite this to change the behavior.

def mouseDown(self, point, clickCount):
    ## do stuff

Don’t call it externally.

mouseDragged(point, delta)

Called when a mouse dragged event is posted.

You must overwrite this to change the behavior.

def mouseDragged(self, point, delta):
    ## do stuff

Don’t call it externally.

mouseMoved(point)

Called when a mouse moved event is posted.

You must overwrite this to change the behavior.

Warning: Avoid adding lots of code to this method, as it’s called very frequently.

def mouseMoved(self, point):
    ## do stuff

Don’t call it externally.

mouseUp(point)

Called when a mouse up event is posted.

You must overwrite this to change the behavior.

def mouseUp(self, point):
    ## do stuff

Don’t call it externally.

newFontDidOpen(font)

Called when a new font did open event is posted.

You must overwrite this to change the behavior.

def newFontDidOpen(self, font):
    ## do stuff

Don’t call it externally.

newFontWillOpen(font)

Called when a new font will open event is posted.

You must overwrite this to change the behavior.

def newFontWillOpen(self, font):
    ## do stuff

Don’t call it externally.

paste()

Called when a paste event is posted.

You must overwrite this to change the behavior.

def paste(self):
    ## do stuff

Don’t call it externally.

pasteSpecial()

Called when a paste event is posted.

You must overwrite this to change the behavior.

def pasteSpecial(self):
    ## do stuff

Don’t call it externally.

refreshView()

Deprecated

Refresh the current glyph view assigned to the tool.

Use merz to draw on screen. Force redrawing is not necessary anymore.

rightMouseDown(point, event)

Called when a right mouse down event is posted.

You must overwrite this to change the behavior.

def rightMouseDown(self, point, event):
    ## do stuff

Don’t call it externally.

rightMouseDragged(point, delta)

Called when a right mouse dragged event is posted.

You must overwrite this to change the behavior.

def rightMouseDragged(self, point, delta):
    ## do stuff

Don’t call it externally.

rightMouseUp(point)

Called when a right mouse up event is posted.

You must overwrite this to change the behavior.

def rightMouseUp(self, point):
    ## do stuff

Don’t call it externally.

selectAllAlternate()

Called when a select all alternate event is posted.

You must overwrite this to change the behavior.

def selectAllAlternate(self):
    ## do stuff

Don’t call it externally.

selectAllControl()

Called when a select control event is posted.

You must overwrite this to change the behavior.

def selectAllControl(self):
    ## do stuff

Don’t call it externally.

setCursor(cursor=None)

Set the current cursor. If None is given, the tool’s cursor will be reset.

This should not be called externally.

setTransformMode(value)

Set the transform mode. This can be used if another tool has its own transformations.

setup()

Called when a tool becomes active. Use it to set all the necessary attributes for the tool.

shouldSendNotifications()

Return a bool if the tool allows notifications to be send out to other tools and observers.

Overwrite if you want to change the default behavior.

Don’t call it externally.

shouldShowMarqueRect()

Called when a mouse dragged event is posted.

Overwrite if you want to change the default behavior and show the marque rect.

This will ignore public event callbacks.

Should return a bool.

shouldShowSelection()

Called when the tool becomes active and becomes inactive

spaceCenterDidOpen(window, font)

Called when a Space Center did open event is posted.

You must overwrite this to change the behavior.

def spaceCenterDidOpen(self, window, font):
    ## do stuff

Don’t call it externally.

spaceCenterDraw(glyph, scale, selected, spaceCenter)

Called when a Space Center draw event is posted.

You must overwrite this to change the behavior.

def spaceCenterDraw(self, glyph, scale, selected, spaceCenter):
    ## do stuff

Don’t call it externally.

spaceCenterKeyDown(glyph, event, spaceCenter)

Called when a Space Center key down event is posted.

You must overwrite this to change the behavior.

def spaceCenterKeyDown(self, glyph, event, spaceCenter):
    ## do stuff

Don’t call it externally.

spaceCenterKeyUp(glyph, event, spaceCenter)

alled when a Space Center key up event is posted.

You must overwrite this to change the behavior.

def spaceCenterKeyUp(self, glyph, event, spaceCenter):
    ## do stuff

Don’t call it externally.

spaceCenterWillClose(window, font)

Called when a Space Center will close event is posted.

You must overwrite this to change the behavior.

def spaceCenterWillClose(self, window, font):
    ## do stuff

Don’t call it externally.

spaceCenterWillOpen(window, font)

Called when a Space Center will open event is posted.

You must overwrite this to change the behavior.

def spaceCenterWillOpen(self, window, font):
    ## do stuff

Don’t call it externally.

toggleTransformMode()

Toggle the transform mode.

Overwrite if you want to change the default behavior.

Don’t call it externally.

transformChanged(**transform)

Called when a transform matrix changed event is posted.

You must overwrite this to change the behavior.

def transformChanged(self, **transform):
    ## transform can have scale, rotate, skew, translate as attributes
    ## do stuff

Don’t call it externally.

transformMode()

Return the current transform mode.

viewDidChangeGlyph()

Called when a glyph view did change event is posted.

You must overwrite this to change the behavior.

def viewDidChangeGlyph(self):
    ## do stuff

Don’t call it externally.

viewWillChangeGlyph()

Called when a glyph view will change event is posted.

You must overwrite this to change the behavior.

def viewWillChangeGlyph(self):
    ## do stuff

Don’t call it externally.

zoomRect(offset=None)

Return the zoom rectangle used by marquee zoom.

class EditingTool()

A tool to edit glyph contours.

boundsRect

allowsMovingMargins(value)

canSelectAnchors()

Return if anchors can be selected.

Overwrite if you want to change the default behavior.

Don’t call it externally.

canSelectComponents()

Return if components can be selected.

Overwrite if you want to change the default behavior.

Don’t call it externally.

canSelectGuidelines()

Return if guidelines can be selected.

Overwrite if you want to change the default behavior.

Don’t call it externally.

canSelectImage()

Return if an image can be selected.

Overwrite if you want to change the default behavior.

Don’t call it externally.

canSelectPoints()

Return if points can be selected.

Overwrite if you want to change the default behavior.

Don’t call it externally.

canSelectSidebearing()

Return if the glyph side bearings can be selected.

Overwrite if you want to change the default behavior.

Don’t call it externally.

canSelectWithMarque()

canToggle()

changePointSmoothness(p)

dragGuide(point, delta)

dragMetrics(point, delta)

dragSelection(point, delta)

dragTransform(point, delta)

isMovingMargins()

mouseDownAddPoint(point)

mouseDownDoubleClick(point)

mouseDownMagicContourSelection(point)

mouseDownSingleClick(point)

mouseDownTripleClick(point)

resetTransform()

setDefaults()

class MeasurementTool()

A tool to measure distances between points in glyph contours.

editMousePoint(point, calculatePointAngle=True)

pointOnContour(point, calculatePointAngle=False)

pointOnGlyphPoints(point, calculatePointAngle=False)

setFromDefaults()

class SliceTool()

A tool to slice glyph contours.

class DrawingTool()

A tool for drawing bezier contours in a glyph.

closeCurrentPath(point)

createContour()

isPointOverStartOrEndPointOfOpenContour(point)

isPointOverStartPoint(point)

setContourAsCurrent(contour)

setCurrentContourDirty()

updateContourVisualisation()

class BezierDrawingTool()

A tool for drawing bezier contours in a glyph.

Inherits from subclass: mojo.events.BezierDrawingTool
Last edited on 30/09/2024