summaryrefslogtreecommitdiffstats
path: root/examples/fontforge-old/demoAddToMenu.py
blob: 6af6580ccb03ce18151efe09dbeb559263c69624 (plain)
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
#!/usr/bin/env python
'FontForge: Demo script to add menu items to FF tools menu'
__url__ = 'http://github.com/silnrsi/pysilfont'
__copyright__ = 'Copyright (c) 2014 SIL International (http://www.sil.org)'
__license__ = 'Released under the MIT License (http://opensource.org/licenses/MIT)'
__author__ = 'David Raymond'

import sys, os, fontforge
sys.path.append(os.path.join(os.environ['HOME'], 'src/pysilfont/scripts'))
import samples.demoFunctions
from samples.demoFunctions import functionList, callFunctions
#from samples.demoCallFunctions import callFunctions

def toolMenuFunction(functionGroup,font) :
    reload (samples.demoFunctions)
    callFunctions(functionGroup,font)
    
funcList=functionList()

for functionGroup in funcList :
    menuType = funcList[functionGroup][0]
    fontforge.registerMenuItem(toolMenuFunction,None,functionGroup,menuType,None,functionGroup);
    print functionGroup, " registered"

''' This script needs to be called from one of the folders that FontForge looks in for scripts to
run when it is started. With current versions of FontForge, one is Home/.config/fontforge/python.
You may need to turn on showing hidden files (ctrl-H in Nautilus) before you can see the .config 
folder.  Within there create a one-line python script, say call sampledemo.py containing a call 
to this script, eg:

execfile("/home/david/src/pysilfont/scripts/samples/demoAddToMenu.py")

Due to the reload(samples.demoFunctions) line above, changes functions defined in demoFunctions.py 
are dynamic, ie FontForge does not have to be restarted (as would be the case if the functions were
called directly from the tools menu. Functions can even be added dynamically to the function groups.

If new function groups are defined, FontForge does have to be restarted to add them to the tools menu.
'''