Tools

static/glyphViewToolbar.png

You can add custom tools to RoboFont, by subclassing the BaseEventTool class or an existing core tool. RoboFont core tools are Bezier Tool, Editing Tool, Measurement Tool and Slice Tool. 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

This is an easy example, with most event callback. You need installTool() to tell RoboFont you want to install in a new tool. Custom tools can also be activated at start up through the Preferences.

"""
Example of a simple tool.

Doesn't do more then drawing an oval on the mouse down position.

"""
from mojo.events import BaseEventTool, installTool
from mojo.drawingTools import *

class MyTool(BaseEventTool):
    
    def setup(self):
        self.position = None
    
    def mouseDown(self, point, clickCount):
        self.position = point
    
    def mouseDragged(self, point, delta):
        self.position = point
    
    def mouseUp(self, point):
        self.position = None
    
    def draw(self, scale):
        if self.position is not None:
            size = 10
            x = self.position.x - size
            y = self.position.y - size
            fill(None)
            stroke(1, 0, 0)
            oval(x, y, size*2, size*2)
    
    def getToolbarTip(self):
        return "My Tool Tip"
    
    

installTool(MyTool())

BaseEventTool

tool.getGlyph()

Returns the current glyph used by the tool

tool.getNSView()

Returns the current glyph view

tool.getCurrentEvent()

Returns the current NSEvent.

tool.refreshView()

updates the current glyph view

tool.setCursor(cursor=None)

Sets the cursor as current cursor (needs a NSCursor object), if None is given it will be return to default cursor of the tool

tool.zoomRect(offset=None)

zoom to a given rect

tool.toggleTransformMode()

Toggle the transform

tool.getDefaultCursor()

returns the default cursor for the tool, this must be overwritten

tool.getToolbarIcon()

returns the toolbar icon for the tool, this must be overwritten

tool.mouseDown(point, clickCount)

send a mouse down notification to the tool, with the mouse point in the and the clickCount

tool.rightMouseDown(point, clickCount)

send a right mouse down notification to the tool, with the mouse point in the and the clickCount

tool.modifyPoint(point)

modify the point coordinates

In the embedded tools this is used to modify the point when fe. on shiftDown

tool.mouseMoved(point)

send a mouse moved notification to the tool, be careful and optimize the code cause the mouse moves all the time

tool.mouseDragged(point, delta)

send a mouse dragged notification to the tool, the delta is the difference between the previous drag point

tool.rightMouseDragged(point, delta)

send a right mouse dragged notification to the tool, the delta is the difference between the previous drag point

tool.mouseUp(point)

send a mouse up notification to the tool

tool.isDragging()

returns a bools if the tool is in a dragging event

tool.keyDown(event)

send a key down notification to the tool, possible to get the pressed characters by event.characters()

tool.keyUp(event)

send a key up notification to the tool

tool.modifiersChanged()

send a modifiers changed notification to the tool, happens when shift, command, control, alt is changed

tool.getModifiers()

returns a dictionary with all the modifiers keys as bools. True when pressed down, keys are: shiftDown, commandDown, optionDown, controlDown

tool.getArrowsKeys()

returns a dictionary with all the arrows keys as bools. True when pressed down, keys are: up, down, left, right

Tools Menu methods

tool.acceptMenuEditCallbacks()

Overwrite this if you want your tool to accept menu callbacks.

tool.selectAll()

perform a select all in your tool, don’t overwrite it if you don’t want to do anything with it

tool.selecteAllAlternate()

perform a select all in your tool with alt key down, don’t overwrite it if you don’t want to do anything with it

tool.deselectAll()

perform a deselect all in your tool, don’t overwrite it if you don’t want to do anything with it

tool.copy()
tool.copyAsComponent()
tool.cut()
tool.delete()
tool.paste()
tool.additionContextualMenuItems()

called when a contextual menu is created, it is required to return a list of tuples with a title string and a callback function example [(“additional stuff”, myObject.myAdditionMenuCallback), ]

Tools Draw Methods

tool.draw(scale)

draw in the glyph view

tool.drawBackground(scale)

draw in the background of the glyph view

tool.drawPreview(scale)

additional drawing in the glyph view while holding the glyph view preview key

tool.drawInactive(scale, glyph, view)

additional drawing in the glyph view when the glyph view is not active, the glyph will not be the current glyph, same for the view

tool.drawBackgroundSelection(scale)

draw in the background, should be related to a selection

tool.drawSelection(scale, glyph, view)

draw the selection for a glyph in a view

Space Center

tool.spaceCenterDraw(glyph, scale, selected, spaceCenter)

draw in the space center for given glyph

tool.spaceCenterKeyDown(glyph, event, spaceCenter)

send a key down notification to the tool, possible to get the pressed characters by event.characters()

tool.spaceCenterKeyUp(glyph, event, spaceCenter)

send a key up notification to the tool

Tools Notifications Methods

tool.viewWillChangeGlyph()

the glyph in the current view will change

tool.viewDidChangGlyph()

the glyph in the current view did change

tool.currentGlyphChanged()

the current glyph in the app changed

tool.preferencesChanged()

the user defaults changed

tool.becomeInactive()

the tool becomes inactive

tool.becomeActive()

the tool becomes active

tool.didUndo()

a undo notification when the undo is already performed

tool.glyphWindowWillOpen()

a new glyph window will open

tool.glyphWindowDidOpen()

a new glyph window did open

tool.glyphWindowWillClose()

a glyph window will close

tool.spaceCenterWillOpen()

a new Space Center will open

tool.spaceCenterDidOpen()

a new Space Center did open

tool.spaceCenterWillClose()

a Space Center will close

tool.fontWillOpen(font)

a UFO will been opened

tool.fontDidOpen(font)

a UFO did open

tool.newFontWillOpen(font)

a new UFO will been created

tool.newFontDidOpen(font)

a new UFO is been created

tool.binaryFontWillOpen(font, source, format)

a binary font will open

the source is the fontTools font object

tool.fontWillClose(font)

a UFO is been closed

tool.applicationDidFinishLauching()

the app is ready launching

tool.applicationDidBecomeActive()

the app becomes active

tool.applicationWillResignActive()

the app will resign being active

tool.fontBecameCurrent(font)

a font becomes active

tool.fontResignCurrent(font)

a font resigns being active

tool.fontWillAutoSave(font)

font will auto save

tool.fontDidAutoSave(font)

font did auto save

tool.fontWillSave(font, path)

font will save

tool.fontDidSave(font, path)

font did save

tool.fontWillGenerate(font, format, path)

font will generate to a binary format

tool.fontDidGenerate(font, format, path)

font did generate to a binary format

tool.fontDidChangeExternally(font)

An external change to the font has happend

Tools Attributes

tool.allPointList

A list of clicked and dragged points used by the tool

tool.mouseDownPoints

A list of clicked points used by the tool

tool.shiftDown

Bool if shift is down

tool.commandDown

Bool if command is down

tool.optionDown

Bool if option is down

tool.controlDown

Bool if control is down

tool.spaceBarDown

Bool if space is down

tool.arrowKeysDown

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

tool.currentPoint

returns the last points from the allPointsList

tool.selection

returns the current glyph selection object