Skip to content

Instantly share code, notes, and snippets.

@typoman
Last active May 21, 2022 09:56
Show Gist options
  • Save typoman/4169203c4507f23400b6c58140f0cf92 to your computer and use it in GitHub Desktop.
Save typoman/4169203c4507f23400b6c58140f0cf92 to your computer and use it in GitHub Desktop.
RoboFont startup script to enable jump to base glyph of componets by double clicking on the component in glyph view.
from defconAppKit.windows.baseWindow import BaseWindowController
from vanilla import FloatingWindow
from mojo.events import addObserver, removeObserver
from mojo.UI import SetCurrentGlyphByName
"""
RoboFont Helper
Type: Start up
Purpose: After it's run, if you double click on a component it will jump to its base glyph.
"""
class CompJumper():
def __init__(self):
addObserver(self, "_mouseDown", "mouseDown")
def destroy(self, sender):
removeObserver(self, "mouseDown")
def _mouseDown(self, info):
p = info["point"]
if info['clickCount'] == 2:
g = CurrentGlyph()
for c in g.components:
path = c.naked().getRepresentation("defconAppKit.NSBezierPath")
if path.containsPoint_((p.x, p.y)):
SetCurrentGlyphByName(c.baseGlyph)
return
# class DebuggerWindow(BaseWindowController):
# def __init__(self):
# self.w = FloatingWindow((123, 44), 'debug!')
# cj = CompJumper()
# self.w.open()
# self.w.bind("close", cj.destroy)
# DebuggerWindow()
CompJumper()
@okay-type
Copy link

In robofont 4.2+ you can option + triple click on a component to go to its base glyph

@typoman
Copy link
Author

typoman commented May 21, 2022

Update for RF 4:

from mojo.UI import OpenGlyphWindow
from mojo.subscriber import Subscriber, registerGlyphEditorSubscriber

class BaseGlyphJumper(Subscriber):

    def glyphEditorDidMouseUp(self, info):
        if info["NSEvent"].clickCount() == 2:
            glyph = info["glyph"]
            font = glyph.font
            for component in glyph.components:
                if not component.selected:
                    continue
                if component.baseGlyph not in font:
                    continue
                baseGlyph = font[component.baseGlyph]
                OpenGlyphWindow(baseGlyph)

if __name__ == '__main__':
    registerGlyphEditorSubscriber(BaseGlyphJumper)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment