Skip to content

Instantly share code, notes, and snippets.

@RafalBuchner
Created January 21, 2020 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RafalBuchner/9f73c347b17472c546a5393c4501a0f1 to your computer and use it in GitHub Desktop.
Save RafalBuchner/9f73c347b17472c546a5393c4501a0f1 to your computer and use it in GitHub Desktop.
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