Debian Codegraph @

Babelfont.glyphsFileFormat/Contents/Resources/plugin.py

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