SOLVED Automatic StatusInteractivePopUpWindow positioning.
-
StatusInteractivePopUpWindow
is very useful. I find myself using it a lot to show a quick input centered within the current glyph editor. (These are little interfaces like the built in "jump to glyph.") Positioning these requires a bit of code that I've been copy/pasting from script to script. I've repeated it enough that I'm wondering if it should be part of mojo. Here's the code:from mojo.UI import CurrentGlyphWindow, StatusInteractivePopUpWindow def getGlyphEditorRectAndScreen(editorWindow): screen = editorWindow.w.getNSWindow().screen() nsWindow = editorWindow.w.getNSWindow() scrollView = editorWindow.getGlyphView().enclosingScrollView() rectInWindowCoords = scrollView.convertRect_toView_(scrollView.frame(), None) rectInScreenCoords = nsWindow.convertRectToScreen_(rectInWindowCoords) (screenX, screenY), (screenWidth, screenHeight) = screen.frame() (x, y), (w, h) = rectInScreenCoords y = -(y + h) return (x, y, w, h), screen class MyThing(object): def __init__(blah): # ... width = 370 height = 505 editorWindow = CurrentGlyphWindow() (editorX, editorY, editorW, editorH), screen = getGlyphEditorRectAndScreen(editorWindow) x = editorX + ((editorW - width) / 2) y = editorY + ((editorH - height) / 2) self.w = StatusInteractivePopUpWindow((x, y, width, height), screen=screen) # ...
Here's what I'm thinking could be added to mojo:
from mojo.UI import CurrentGlyphWindow, StatusInteractivePopUpWindow class MyThing(object): self.w = StatusInteractivePopUpWindow((w, h), centerInView=CurrentGlyphWindow().getGlyphView())
The
centerInView
arg would take aNSView
object. It would check to see if the view is enclosed in a scroll view and, if so, use the scroll view as the view to center within.I'd be happy to contribute code to do this if you like the idea.