Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RoboFont_rightClick_contextual_menu.py
from mojo.events import addObserver
from AppKit import NSPasteboard, NSArray
def copy2clip(txt):
from AppKit import NSPasteboard, NSStringPboardType
pb = NSPasteboard.generalPasteboard()
pb.declareTypes_owner_([NSStringPboardType],None)
pb.setString_forType_(txt,NSStringPboardType)
class Contextual(object):
def __init__(self):
addObserver(self, "fontOverviewAdditionContextualMenuItems", "fontOverviewAdditionContextualMenuItems")
def fontOverviewAdditionContextualMenuItems(self, notification):
myMenuItems = [
("selected glyphs to clipboard", self.printSelected),
("selected glyphs to clipboard [comma separated]", self.printSelectedCommaStyle),
("selected glyphs to clipboard [python list]", self.printSelectedPythonStyle),
]
notification["additionContextualMenuItems"].extend(myMenuItems)
def printSelectedCommaStyle(self, sender):
f = CurrentFont()
txt = ", ".join(f.selectedGlyphNames)
copy2clip(txt)
def printSelectedPythonStyle(self, sender):
f = CurrentFont()
txt = "["
for name in f.selectedGlyphNames:
txt += f"'{name}',"
txt += "]"
copy2clip(txt)
def printSelected(self, sender):
f = CurrentFont()
txt = " ".join(f.selectedGlyphNames)
copy2clip(txt)
Contextual()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment