Custom tools can be created by subclassing the BaseEventTool class or another existing core tool.

RoboFont core tools are: BezierDrawingTool, EditingTool, MeasurementTool and SliceTool. They are available through the mojo.events module.

from mojo.events import BaseEventTool
# or subclassing a core tool
from mojo.events import BezierDrawingTool, EditingTool, MeasurementTool, SliceTool

Custom tools can also be activated at start up through the Preferences.


class BaseEventTool()

The base event tool contains all the possible callbacks and will do nothing.

allPointList

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

arrowKeysDown

A dictionary of bools with keys: up, down, left, right

capLockDown

Bool if capLock is down

commandDown

Bool if command is down

controlDown

Bool if control is down

currentPoint

Get the mouse position as a point object.

mouseDownPoints

A list of clicked points used by the tool

optionDown

Bool if option is down

selection

Get the selection object of the current glyph in the

shiftDown

Bool if shift is down

spaceBarDown

Bool if space bar is down

acceptMenuEditCallbacks(menuItem=None)

Will be called by the glyph view when a menu item will be validated. Should return a bool.

additionContextualMenuItems()

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

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

Which will be added to each contextual menu.

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

Don’t call it externally.

applicationDidBecomeActive()

Called when RoboFont did become 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 RoboFont did finish 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 RoboFont detects a change in screens.

You must overwrite this to change the behavior.

def applicationScreenChanged(self):
    ## do stuff

Don’t call it externally.

applicationWillResignActive()

Called when 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 in active 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 new binary font will open.

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.

didUndo(notification)

Called when 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.

drawBackground(scale=1)

Called when a drawBackground event is posted.

You must overwrite this to change the behavior.

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

Don’t call it externally.

drawBackgroundSelection(scale)

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

Called when a draw preview event is posted.

You must overwrite this to change the behavior.

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

Don’t call it externally.

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.

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

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.

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 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 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.

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 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 arrows pressed. True if a key is down. Keys are: up, down, left, right

getCurrentEvent()

Return the current event.

getDefaultCursor()

Return the cursor a tool has to use.

Create cursors with mojo.RoboFont.CreateCursor.

getGlyph()

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

getMarqueRect(offset=None, previousRect=False)

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

getModifiers()

Return a dictionary with all the modifiers keys as bools. True when they are 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 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 when durring drag to modifiy a mouse dragged point. Used to change the point fe. 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 modifiy the mouse down point. Used to change the point fe. 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.

Be carefull with adding lots of code cause it will be called a lot.

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 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 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.

refreshView()

Refresh, redisplay the current glyph view assigned to the tool.

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.

selectAll()

Called when a select all event is posted.

You must overwrite this to change the behavior.

def selectAll(self):
    ## 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 it will reset the tools cursor This should not be called exeternaly.

setTransformMode(value)

Set the transform mode this can be used if an other tool has his own transformations

setup()

This will be called when a tool gets active and is used to set all the necessary attributes for the tool.

spaceCenterDidOpen(window, font)

Called when a space center window 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 window 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 window 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 window 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 window 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 window 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 to transform mode. Overwrite if you want to change this 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 changed the glyph 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 changed the glyph 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 marque zoom.

Last edited on 23/01/2018