Created
July 13, 2026 18:48
-
-
Save connordavenport/67d6bed2a5434694544dd7dae0b27e5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from mojo.subscriber import Subscriber, registerRoboFontSubscriber | |
| import pandas as pd | |
| from AppKit import NSPasteboardTypeString, NSPasteboard | |
| ATTRIBUTES = "name unicode width angledLeftMargin angledRightMargin".split(" ") | |
| class contextual_auto_unicodes(Subscriber): | |
| debug = True | |
| def fontOverviewWantsContextualMenuItems(self, info): | |
| myMenuItems = [ | |
| ("Copy Data Frame", | |
| [ | |
| ("Markdown", self.markdown_callback), | |
| ("CSV", self.csv_callback), | |
| ("Spaces", self.space_sep_callback), | |
| ]), | |
| ] | |
| info["itemDescriptions"].extend(myMenuItems) | |
| #self.location = "overview" | |
| self.glyphs = CurrentFont().selectedGlyphs | |
| @property | |
| def data(self): | |
| data = { | |
| attr : [getattr(g, attr) or None for g in self.glyphs] | |
| for attr in | |
| ATTRIBUTES | |
| } | |
| return data | |
| def csv_callback(self, sender): | |
| _data = self.data | |
| table = pd.DataFrame(_data) | |
| csv = table.to_csv(index=False) | |
| self.copy_to_pasteboard(csv) | |
| def space_sep_callback(self, sender): | |
| _data = self.data | |
| table = pd.DataFrame(_data) | |
| spaces = table.to_csv(sep="\t", index=False) | |
| self.copy_to_pasteboard(spaces) | |
| def markdown_callback(self, sender): | |
| _data = self.data | |
| table = pd.DataFrame(_data) | |
| md = table.to_markdown(index=False) | |
| self.copy_to_pasteboard(md) | |
| def copy_to_pasteboard(self, text): | |
| pb = NSPasteboard.generalPasteboard() | |
| pb.clearContents() | |
| pb.declareTypes_owner_([ | |
| NSPasteboardTypeString, | |
| ], None) | |
| pb.setString_forType_(text, NSPasteboardTypeString) | |
| if __name__ == '__main__': | |
| registerRoboFontSubscriber(contextual_auto_unicodes) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment