1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
# encoding: utf-8
from __future__ import division, print_function, unicode_literals
import objc
from GlyphsApp import *
from GlyphsApp.plugins import *
import sys
import os
from babelfont.convertors.gsobject import GSObject
from babelfont import Font
class BabelfontExport(FileFormatPlugin):
# The NSView object from the User Interface. Keep this here!
dialog = objc.IBOutlet()
@objc.python_method
def settings(self):
self.name = "Babelfont"
self.icon = "ExportIconTemplate"
self.toolbarPosition = 100
# Load .nib dialog (with .extension)
# self.loadNib("IBdialog", __file__)
# @objc.python_method
# def start(self):
# pass
@objc.python_method
def export(self, font):
# Ask for export destination and write the file:
title = "Choose export destination"
proposedFilename = font.familyName
fileTypes = ["babelfont"]
# Call dialog
filepath = GetSaveFile(title, proposedFilename, fileTypes)
if filepath:
f = GSObject()
f.scratch = {"gsfont": font}
f.font = Font()
f.gsfont = font
f._load()
f.font.save(filepath)
return (
True,
'The export of "%s" was successful.' % (os.path.basename(filepath)),
)
else:
return (False, "No file chosen")
def __file__(self):
"""Please leave this method unchanged"""
return __file__
|