Last active
April 20, 2021 14:45
-
-
Save connordavenport/e2fc66f0b5f1d2149785c8ed6170e385 to your computer and use it in GitHub Desktop.
An observer script to sync background layers with foreground layer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mojo.events import addObserver, removeObserver | |
class syncLayerWidths: | |
def __init__(self): | |
self.font = None | |
self.glyph = None | |
addObserver(self, "glyphChanged", "currentGlyphChanged") | |
# --------- from Tal's RoboHud --------------- | |
def beginObservingGlyph(self): | |
if self.glyph is not None: | |
self.glyph.addObserver(self, "widthChanged", "Glyph.WidthChanged") | |
def stopObservingGlyph(self): | |
self.glyph = CurrentGlyph() | |
if self.glyph is not None: | |
self.font = self.glyph.font | |
self.glyph.removeObserver(self, "Glyph.Changed") | |
# -------------------------------------------- | |
def glyphChanged(self,info): | |
self.stopObservingGlyph() | |
self.beginObservingGlyph() | |
def widthChanged(self,point): | |
if self.glyph: | |
for layerGlyph in self.glyph.layers: | |
layerGlyph.width = self.glyph.width | |
syncLayerWidths() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment