I want to make a plugin with a custom info box (or inspector). I read the Select Tool guide, and try to use vanilla library to create GUI. I use the following code:
from GlyphsApp.plugins import *
from vanilla import *
from vanilla.vanillaGroup import Group
import objc
# Our own patched Vanilla Group class
class PatchedGroup(Group):
nsViewClass = objc.lookUpClass("GSInspectorView") # GSInspectorView
class CJKMetrics(ReporterPlugin):
def settings(self):
self.menuName = 'CJK Metrics'
self.name = 'CJK Metrics'
# Create Vanilla window and group with controls
viewWidth = 150
viewHeight = 40
self.sliderMenuView = Window((viewWidth, viewHeight))
# Using PatchedGroup() here instead of Group()
self.sliderMenuView.group = PatchedGroup((0, 0, viewWidth, viewHeight))
self.sliderMenuView.group.text = TextBox((10, 0, -10, -10), self.name)
self.sliderMenuView.group.slider = Slider((10, 18, -10, 23), callback=self.sliderCallback)
# Define the menu
self.generalContextMenus = [
{"view": self.sliderMenuView.group.getNSView()}
]
# Prints the slider’s value
def sliderCallback(self, sender):
print('Slider value:', sender.get())
But I can only find the group added into the context menu, rather than the info box:
Could you please explain what happens here and how I can add the custom info box?
By the way, in the original guide, the statement nsViewClass = GSInspectorView leaves an error NameError: name 'GSInspectorView' is not defined, so I use objc.lookUpClass("GSInspectorView") instead. Is this correct? And if so, please update the document, thank you!