Last active
October 1, 2019 07:10
-
-
Save gferreira/3e4c4d5181301ddc8e819aec7ebe3e9e to your computer and use it in GitHub Desktop.
Q: can vanilla windows talk to each other? A: yes they can!
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 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