Skip to content

Instantly share code, notes, and snippets.

@okay-type
Last active August 31, 2018 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okay-type/bcd2d9ea18b16b58d757cc1e88c9cb84 to your computer and use it in GitHub Desktop.
Save okay-type/bcd2d9ea18b16b58d757cc1e88c9cb84 to your computer and use it in GitHub Desktop.
adds toggle to synchronize the text, size, pre, post, and suffix data in all open Robofont space center windows
# set as a startup script
# jackson at okaytype.com
# issues: sometimes doesn't update one font
# issues: needs some more testing to make sure it's not slowing things down
# next: add more settings, increase efficiency
from mojo.UI import AllSpaceCenters, CurrentSpaceCenter
from mojo.events import addObserver, removeObserver
from vanilla import *
cachedsettings = 'cachedsettings'
class syncCenter(object):
def __init__(self):
addObserver(self, "addSyncSpaceTool", "spaceCenterDidOpen")
def removeSyncSpaceTool(self, sender):
removeObserver(self, 'spaceCenterDrawLineView')
removeObserver(self, 'removeSyncSpaceTool')
def addSyncSpaceTool(self, sender):
addObserver(self, 'sync', 'spaceCenterDrawLineView')
addObserver(self, "removeSyncSpaceTool", "spaceCenterWillClose")
sp = CurrentSpaceCenter()
sp.syncToggle = CheckBox((-22, -22, 22, 22), title=None, callback=self.checkBoxSync, value=True) # l, t, w, h
def sync(self, none):
# collect new settings
global cachedsettings
sp = CurrentSpaceCenter()
spText = sp.getRaw()
spPre = sp.getPre()
spAfter = sp.getAfter()
spPointSize = sp.getPointSize()
spSuffix = sp.getSuffix()
spLineHt = sp.getLineHeight()
settings = (spText, spPre, spAfter, spPointSize, spSuffix, spLineHt)
if sp.syncToggle:
# stop if unchecked
if not sp.syncToggle.get():
return
# stop if settings haven't changed
if settings == cachedsettings:
return
# proceed if changes were made
else:
# update settings
for sc in AllSpaceCenters():
if sc != sp:
sc.setPre(spPre)
sc.setAfter(spAfter)
sc.setPointSize(spPointSize)
sc.setSuffix(spSuffix)
sc.setLineHeight(spLineHt)
sc.setRaw(spText)
# save settings for next time
cachedsettings = settings
def checkBoxSync(self, sender):
state = sender.get()
for sc in AllSpaceCenters():
sc.syncToggle.set(state)
# sync spacecenters if checked
if state == 1:
self.sync(True)
syncCenter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment