Vanilla processing selection with script

Having a go at assembling a script with a Vanilla UI. Essentially it will provide a list to make a selection (fonts in a folder), and then a button to go on to perform actions on that selection (generate specimen images with Drawbot).

I can make the list and create the button, but I can’t figure out how to make the selection get passed on. In fact my script seems never to get to the button’s callback.

In looking at the Vanilla documentation, I found that even their simple sample scripts weren’t working on my system. This for example never reports “button hit!”:


from vanilla import *

class ButtonDemo(object):

     def __init__(self):
         self.w = Window((100, 40))
         self.w.button = Button((10, 10, -10, 20), "A Button",
                            callback=self.buttonCallback)
         self.w.open()

     def buttonCallback(self, sender):
         print ("button hit!")

ButtonDemo()

(Taken straight from the Vanilla doc (with parentheses added to print line.)) And likewise, this makes the list but doesn’t report what was selected (nothing appears in console):

from vanilla import *

class ListDemo(object):

    def __init__(self):
        self.w = Window((100, 100))
        self.w.myList = List((0, 0, -0, -0), ["A", "B", "C"],
                     selectionCallback=self.selectionCallback)
        self.w.open()

    def selectionCallback(self, sender):
        print (sender.getSelection())

ListDemo()

What am I missing?

The selectionCallback is probably only called when you click a row in the table.
Try to put the print statement into the button callback.

But you might consider a different UI. Why build something that looks a bit like the Finder when you can use a Finder window and 1) drag the fonts into your window or 2) use apple Script to get the selected files from the Fonder?

Ooh, how would I manage drag and drop from the Finder?

Dragging Files (Probably start reading the Introduction)

This is all ObjectiveC but that can be translated into Python quite easily.

FWIW, both scripts work for me when I paste them into the Macro Panel in Glyphs 3.

1 Like

Thanks for trying them out.
Okay, this was unexpected: If I run this


from vanilla import *

class ButtonDemo(object):

     def __init__(self):
         self.w = Window((100, 40))
         self.w.button = Button((10, 10, -10, 20), "A Button",
                            callback=self.buttonCallback)
         self.w.open()

     def buttonCallback(self, sender):
         print ("Button callback")

ButtonDemo()
print ("Print statement")

in the Glyphs macro window, all works fine. If I run it in the Drawbot plugin window, The “Print statement” appears in the Drawbot console but the “Button callback” appears in the Glyphs console! If I run it in the standalone Drawbot app (which is where I was trying to develop my script) I see “Print statement” in its console, and “Button callback” is nowhere I can see.

Oof, that all looks above my scripting abilities. Could an Applescript/Automator workflow pass a list of paths to a Drawbot script?