forked from PriaRavichandran/Glyphs-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sync Edit Views.py
63 lines (57 loc) · 2.09 KB
/
Sync Edit Views.py
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
55
56
57
58
59
60
61
62
63
#MenuTitle: Sync Edit Views
# -*- coding: utf-8 -*-
__doc__="""
Refreshes the edit view contents of non-front files. Have multiple files open! Vanilla required.
"""
import vanilla
import GlyphsApp
class SyncEditViews( object ):
def __init__( self ):
# Window 'self.w':
space = 10
windowWidth = 200
windowHeight = 44
self.w = vanilla.FloatingWindow(
( windowWidth, windowHeight ), # default window size
"Sync Edit Views", # window title
autosaveName = "com.Tosche.SyncEditViews.mainwindow" # stores last window position and size
)
# Run Button:
self.w.runButton = vanilla.Button((space, space, -space, -space), "Refresh Other Files", sizeStyle='regular', callback=self.SyncEditViewsMain )
# Open window and focus on it:
self.w.open()
self.w.makeKey()
def SyncEditViewsMain( self, sender ):
try:
font0 = Glyphs.orderedDocuments()[0].font # frontmost font
thisTab = font0.tabs[-1]
thisMaster = font0.selectedFontMaster
mindex = thisTab.masterIndex()
thisText = thisTab.text
thisScale = thisTab.graphicView().scale()
doKern = thisTab.graphicView().doKerning()
doSpace = thisTab.graphicView().doSpacing()
thisSelection = thisTab.graphicView().textStorage().selectedRange()
try:
for i in range(len(Glyphs.orderedDocuments())):
if i != 0:
iFont = Glyphs.orderedDocuments()[i].font
iFontLastTool = iFont.tool
iTab = Glyphs.orderedDocuments()[i].font.tabs[-1]
if mindex <= len(iFont.masters):
iTab.setMasterIndex_(mindex)
iTab.graphicView().setScale_(thisScale)
iTab.text = thisText
iTab.graphicView().setDoKerning_(doKern)
iTab.graphicView().setDoSpacing_(doSpace)
# SET CARET INTO POSITION
iFont.tool = "TextTool"
iTab.graphicView().textStorage().setSelectedRange_(thisSelection)
iFont.tool = iFontLastTool
except Exception, e:
# Glyphs.showMacroWindow() # This is a bit annoying :)
print "Sync Edit views Error (Inside Loop): %s" % e
except Exception, e:
# Glyphs.showMacroWindow() # This is a bit annoying :)
print "Sync Edit views Error: %s" % e
SyncEditViews()