Skip to content

Instantly share code, notes, and snippets.

@typemytype
Last active February 15, 2023 01:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typemytype/b8ad2e8ba392152ee4eb62c617fec294 to your computer and use it in GitHub Desktop.
Save typemytype/b8ad2e8ba392152ee4eb62c617fec294 to your computer and use it in GitHub Desktop.
Set this script as start up script to popup a window listing all recent files
# written by Tal Leming, posted in the RoboFont Community slack
import pathlib
import AppKit
import ezui
from mojo.subscriber import Subscriber, registerRoboFontSubscriber
from mojo import roboFont
from mojo.UI import OpenScriptWindow
roboFontIcon = AppKit.NSApp().applicationIconImage()
class Launcher(Subscriber, ezui.WindowController):
debug = True
def build(self):
content = f"""
* HorizontalStack @roboFontStack
> * Image @roboFontImage
> RoboFont @roboFontTitleLabel
> Version {roboFont.version} @roboFontVersionLabel
|------------------------| @documentTable
| Filename | Last Edited |
| |
|------------------------|
* HorizontalStack @newStack
> (New Font) @newFontButton
> (New Script) @newScriptButton
> (Open...) @openButton
"""
iconSize = 40
descriptionData = dict(
roboFontStack=dict(
alignment="center",
distribution="gravity",
margins=(20, 0, 0, 0)
),
roboFontImage=dict(
image=roboFontIcon,
height=iconSize,
width=iconSize,
gravity="leading"
),
roboFontTitleLabel=dict(
gravity="leading",
style="largeTitle",
),
roboFontVersionLabel=dict(
gravity="trailing",
style="caption1"
),
documentTable=dict(
width=600,
height=300,
columnDescriptions=[
dict(
identifier="filename",
title="Filename"
),
dict(
identifier="modificationDate",
title="Last Edited",
width=200
),
],
items=getRecentDocumentTableItems()
),
newStack=dict(
distribution="gravity",
alignment="trailing"
)
)
self.w = ezui.EZWindow(
content=content,
descriptionData=descriptionData,
controller=self,
size="auto"
)
self.w.getNSWindow().setTitlebarAppearsTransparent_(True)
self.w.getNSWindow().standardWindowButton_(AppKit.NSWindowMiniaturizeButton).setHidden_(True)
self.w.getNSWindow().standardWindowButton_(AppKit.NSWindowZoomButton).setHidden_(True)
mask = self.w.getNSWindow().styleMask()
mask |= AppKit.NSWindowStyleMaskFullSizeContentView
self.w.getNSWindow().setStyleMask_(mask)
self.w.center()
def started(self):
self.w.open()
def documentTableDoubleClickCallback(self, sender):
table = self.w.getItem("documentTable")
fontSuffixes = (".ufo", ".ufoz", ".otf", ".ttf")
for item in table.getSelectedItems():
path = item["path"]
suffix = pathlib.Path(path).suffix.lower()
if suffix in fontSuffixes:
roboFont.OpenFont(path)
elif suffix == ".py":
OpenScriptWindow(path)
else:
pass
self.w.close()
def newFontButtonCallback(self, sender):
roboFont.NewFont()
def newScriptButtonCallback(self, sender):
OpenScriptWindow()
def openButtonCallback(self, sender):
documentController = AppKit.NSDocumentController.sharedDocumentController()
documentController.openDocument_(None)
def getRecentDocumentTableItems():
tableItems = []
fileManager = AppKit.NSFileManager.defaultManager()
documentController = AppKit.NSDocumentController.sharedDocumentController()
recentDocumentURLs = documentController.recentDocumentURLs()
dateFormatter = AppKit.NSDateFormatter.alloc().init()
dateFormatter.setDateStyle_(AppKit.NSDateFormatterLongStyle)
dateFormatter.setTimeStyle_(AppKit.NSDateFormatterShortStyle)
dateFormatter.setDoesRelativeDateFormatting_(True)
for url in recentDocumentURLs:
modTime = fileManager.attributesOfItemAtPath_error_(
url.path(),
None
)[0].fileModificationDate()
modString = dateFormatter.stringFromDate_(modTime)
item = dict(
path=url.path(),
filename=url.lastPathComponent(),
modificationDate=modString
)
tableItems.append(item)
return tableItems
registerRoboFontSubscriber(Launcher)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment