Thanks, Frederik. I couldn't figure that out, but I did figure out I could subclass the vanilla elements. I think this approach will work better for what I'm doing.
from vanilla import *
from mojo.events import addObserver, removeObserver
from AppKit import NSApp, NSColor, NSTextAlignmentCenter, NSTextAlignmentRight, NSTextAlignmentLeft
debug = True
class OverlayViewController(object):
def __init__(self):
windowname = 'debug window ui test'
if debug == True:
self.w = Window((500, 50), windowname)
self.w.bind("close", self.windowClose)
for window in [w for w in NSApp().orderedWindows() if w.isVisible()]:
if window.title() == windowname:
window.close()
self.w.open()
self.view = None
addObserver(self, 'addToGlyphView', 'glyphWindowWillOpen')
def windowClose(self, sender):
print('removing observer')
removeObserver(self, "glyphWindowWillOpen")
def addToGlyphView(self, notification):
self.window = notification["window"]
x, y, w, h = xywh = (0, 0, -0, 22)
this = self.testGV = Group(xywh)
this.text1 = SubClassedEditText(xywh, '-', window=self.window, sizeStyle='mini', continuous=False)
self.window.addGlyphEditorSubview(this)
class SubClassedEditText(EditText):
def __init__(self, *args, **kwargs):
self.window = kwargs['window']
del kwargs['window']
super(SubClassedEditText, self).__init__(*args, **kwargs)
this = self.getNSTextField()
this.setBezeled_(False)
this.setBackgroundColor_(NSColor.redColor())
this.setAlignment_(NSTextAlignmentCenter)
addObserver(self, "currentGlyphChanged", "currentGlyphChanged")
def currentGlyphChanged(self, info):
try:
g = self.window.getGlyph()
if g is None: return
f = g.getParent()
self.set(f.info.styleName + ' ' + g.name)
except:
pass
def _breakCycles(self):
super(SubClassedEditText, self)._breakCycles()
removeObserver(self, "currentGlyphChanged")
OverlayViewController()