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.
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
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.
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.
arrowKeysDown
A dictionary of bools indicating if the arrow keys are pressed: up
, down
, left
, right
.
acceptMenuEditCallbacks(menuItem=None)
Called by the glyph view when a menu item is validated. Should return a bool.
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.
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.
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.
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
.
getDefaultCursor()
Return the cursor used by the tool.
Create cursors with mojo.roboFont.CreateCursor
.
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
.
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.
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.
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.
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.
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.
class EditingTool()
A tool to edit glyph contours.
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.