Skip to content

Instantly share code, notes, and snippets.

@gferreira
Last active October 1, 2019 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gferreira/3e4c4d5181301ddc8e819aec7ebe3e9e to your computer and use it in GitHub Desktop.
Save gferreira/3e4c4d5181301ddc8e819aec7ebe3e9e to your computer and use it in GitHub Desktop.
Q: can vanilla windows talk to each other? A: yes they can!
from AppKit import NSApp
from vanilla import *
class LayersWindow(object):
def __init__(self):
self.w = FloatingWindow((123, 200), title='layers')
self.w.layers = List((10, 10, -10, -10), ['foreground', 'background', 'sketches'])
self.w.bind("close", self.closeCallback)
self.w.vanillaWrapper = self
self.w.open()
def closeCallback(self, sender):
print("close and delete")
del self.w.vanillaWrapper
class MoveWindow(object):
def __init__(self):
self.w = FloatingWindow((123, 80), title='move')
self.w.value = EditText((10, 10, -10, 20), '10')
self.w.apply = Button((10, 40, -10, 20), title='apply', callback=self.moveGlyphsCallback)
self.w.open()
@property
def selectedLayers(self):
app = NSApp()
layers = []
selection = []
for window in app.windows():
if window.title() == 'layers':
delegate = window.delegate()
if hasattr(delegate, "vanillaWrapper"):
vanillaWrapper = delegate.vanillaWrapper
layers.extend(vanillaWrapper.w.layers.get())
selection.extend(vanillaWrapper.w.layers.getSelection())
return [L for i, L in enumerate(layers) if i in selection]
def moveGlyphsCallback(self, sender):
value = int(self.w.value.get())
f = CurrentFont()
for glyphName in f.selectedGlyphNames:
for layerName in self.selectedLayers:
g = f[glyphName].getLayer(layerName)
g.moveBy((value, value))
LayersWindow()
MoveWindow()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment