Hello, I used vanilla to write the interface, and the code is as follows. The problem I encountered is that when I input the value of ‘x/y shift’ in the interface window, I cannot call the filter function to offset the glyph
# encoding: utf-8
from __future__ import division, print_function, unicode_literals
from GlyphsApp.plugins import *
from vanilla import *
class Lvbovanilla(FilterWithDialog):
@objc.python_method
def settings(self):
self.name = 'My Select Tool'
# Create Vanilla window and group with controls
width = 150
height = 80
self.paletteView = Window((width, height))
self.paletteView.group = Group((0, 0, width, height))
self.paletteView.group.text = TextBox((10, 10, -10, 20), 'x/y shift')
self.paletteView.group.editText = EditText((10, 35, 50, 25), callback = self.editTextCallback, continuous = False)
# Set dialog to NSView
self.dialog = self.paletteView.group.getNSView()
# On dialog show
@objc.python_method
def start(self):
# Set default setting if not present
if not Glyphs.defaults['com.myname.myfilter.value']:
Glyphs.defaults['com.myname.myfilter.value'] = 15.0
# Set value of text field
self.paletteView.group.editText.set(Glyphs.defaults['com.myname.myfilter.value'])
# Action triggered by UI
@objc.python_method
def editTextCallback(self, sender):
# Store value coming in from dialog
Glyphs.defaults['com.myname.myfilter.value'] = sender.get()
# Trigger redraw
self.update()
@objc.python_method
def filter(self, Layer, inEditView, customParameters):
value = Glyphs.defaults['com.myname.myfilter.value']
for path in Layer.paths:
for node in path.nodes:
node.position = NSPoint(node.position.x + value, node.position.y + value)
@objc.python_method
def __file__(self):
"""Please leave this method unchanged"""
return __file__
It seems that in your editTextCallback method you are nowhere asking for the value of the EditText. Instead it tries to get the value from the user defaults value = Glyphs.defaults['com.myname.myfilter.value'].
That is not going to work, as a) that is just an example from the source where you copied the code from and would require you to put an actual key in there (instead of the 'com.myname.myfilter.value').
But b) what you really need instead is just the value of the sender. I think sth like value = sender.get() should get you started there.
# encoding: utf-8
from __future__ import division, print_function, unicode_literals
from GlyphsApp.plugins import *
from vanilla import *
class Lvbovanilla(FilterWithDialog):
@objc.python_method
def settings(self):
self.name = 'My Select Tool'
# Create Vanilla window and group with controls
width = 150
height = 80
self.paletteView = Window((width, height))
self.paletteView.group = Group((0, 0, width, height))
self.paletteView.group.text = TextBox((10, 10, -10, 20), 'x/y shift')
self.paletteView.group.editText = EditText((10, 35, 50, 25), callback = self.editTextCallback, continuous = False)
# Set dialog to NSView
self.dialog = self.paletteView.group.getNSView()
# On dialog show
@objc.python_method
def start(self):
# Set default setting if not present
if not Glyphs.defaults['com.myname.myfilter.value']:
Glyphs.defaults['com.myname.myfilter.value'] = 15.0
# Set value of text field
self.paletteView.group.editText.set(Glyphs.defaults['com.myname.myfilter.value'])
# Action triggered by UI
@objc.python_method
def editTextCallback(self, sender):
# Store value coming in from dialog
value = sender.get()
# Trigger redraw
self.update()
@objc.python_method
def filter(self, Layer, inEditView, customParameters):
value = sender.get()
for path in Layer.paths:
for node in path.nodes:
node.position = NSPoint(node.position.x + value, node.position.y + value)
@objc.python_method
def __file__(self):
"""Please leave this method unchanged"""
return __file__
Forgive me for being a novice. This is the code I changed, but it still doesn’t work
You need to do what you want to do with the value. I don’t know what that is, you asked for how to get the value from the EditText in order to proceed from there.
I am afraid that I have no time to write the entire code for you, sorry.
for the beginning I recommend to just put your further code right after where you have the value = sender.get()
At the moment there is only that self.update() method called. Remove that and instead print(value) to see where you are at. And from there just do whatever you want with the value. Maybe also remove all methods from the example code that don’t do anything that your plugin/script needs.
# encoding: utf-8
from __future__ import division, print_function, unicode_literals
from GlyphsApp.plugins import *
from vanilla import *
class Lvbovanilla(FilterWithDialog):
@objc.python_method
def settings(self):
self.name = 'My Select Tool'
# Create Vanilla window and group with controls
self.w = Window((120, 42))
self.w.editText = EditText((10, 10, -10, 22),text='some text',callback=self.editTextCallback)
#self.w.open()
@objc.python_method
def editTextCallback(self, sender):
print("text entry!", sender.get())
value = sender.get()
@objc.python_method
def filter(self, layer, inEditView):
# Shift all nodes in x and y direction by the value
for path in layer.paths:
for node in path.nodes:
node.position = NSPoint(node.position.x + value, node.position.y + value)
# Trigger redraw
#self.update()
@objc.python_method
def __file__(self):
"""Please leave this method unchanged"""
return __file__
Instead of using a variable to store your value, rather use the Glyphs defaults. Store your values in Glyphs.defaults (read up on the documentation for reading/writing defaults correctly) and then read them directly from the defaults in your filter method.