You are adding your view to the content menu (# Define the menu
).
What does the slider change? It might be better off in the context menu after all.
You need to add a callback “GSInspectorViewControllersCallback” and implement
def inspectorViewControllersForLayer_(self, layer):
return [self]
def view(self):
return self.sliderMenuView.group.getNSView()
inspectorViewControllersForLayer_
is supposed to return NSViewControllers, but any object that can return a view will do.
This his the full code:
import objc
from GlyphsApp import *
from GlyphsApp.plugins import *
from vanilla import *
from vanilla.vanillaGroup import Group
# Our own patched Vanilla Group class
class PatchedGroup(Group):
nsViewClass = objc.lookUpClass("GSInspectorView") # GSInspectorView
class CJKMetrics(ReporterPlugin):
@objc.python_method
def settings(self):
self.menuName = 'CJK Metrics'
self.name = 'CJK Metrics'
# Create Vanilla window and group with controls
viewWidth = 150
viewHeight = 40
self.sliderWindow = Window((viewWidth, viewHeight))
self.sliderWindow.group = PatchedGroup((0, 0, viewWidth, viewHeight)) # Using PatchedGroup() here instead of Group()
self.sliderWindow.group.text = TextBox("auto", self.name)
self.sliderWindow.group.slider = Slider("auto", callback=self.sliderCallback_)
rules = [
"H:|-[text]-|",
"H:|-[slider]-|",
"V:|-3-[text]-2-[slider]-3-|",
]
metrics = {}
self.sliderWindow.group.addAutoPosSizeRules(rules, metrics)
GSCallbackHandler.addCallback_forOperation_(self, "GSInspectorViewControllersCallback")
def inspectorViewControllersForLayer_(self, layer):
return [self]
def view(self):
return self.sliderWindow.group.getNSView()
The auto layout stuff is needed as Glyphs internally uses it and the way vanilla sets up the views is not playing well together with it.