Getting the glyph and its font



  • Hi,
    In a class derived from BaseEventTool, I use

    g = self.getGlyph()
    f = g.getParent()
    

    in order to obtain the font containing the glyph g.
    However, when I have two opened fonts F1 and F2 and two GlyphWindows opened (one from each font : g1 from F1 and g2 from F2), and when I go from one glyph window to the other, the following code :

    print g.name, g.getParent.fileName
    

    gives me : g1 F2 or g2 F1
    and after some more clicking, I finally get correct values (g1 F1 or g2 F2)

    There seem to be only partially updated information when switching windows.
    Regards,
    Samuel


  • admin

    hi

    could you make an small example?

    I cannot reproduce this issue, with a quick test...

    thanks

    <pre>
    from mojo.events import BaseEventTool, installTool

    class TestTool(BaseEventTool):

    def currentGlyphChanged(self):
        g = self.getGlyph()
        f = g.getParent()
        print g.name, f
    

    installTool(TestTool())
    </pre>



  • [ With Version 1.6 (built 1410152315) ]
    Using your example TestTool :

    • Open two fonts F1 and F2
    • Open glyph g1 from font F1
      (now there are three windows opened, plus the output window)
    • Bring the window for the font F2 to the front
    • click on the glyphs grid, on a glyph g2 (with a name different from g1)
      Now you should observe "g1 <F2>" in the output window

    [Another weirdness: the callbacks "viewDidChangeGlyph" and "currentGlyphChanged" are called before "becomeActive"]
    Best regards,
    Samuel


  • admin

    Hi

    the mixed parents will be fixed in the next update, thanks for reporting

    one thing: a <code>tool.getGlyph()</code> method will always return a glyph from a glyph view, if you select a font window, it will send you a <code>currentGlyphChanged</code> notification, but the glyph will not actually change when using the <code>tool.getGlyph()</code>. To get the global current glyph use <code>CurrentGlyph()</code>

    the other weirdness: see https://github.com/typemytype/RoboFontExamples/blob/master/observers/eventObserver.py

    a tool can become active separately from a <code>currentGlyphChanged</code> or <code>viewDidChangeGlyph</code>



  • Thank you for fixing this.!
    I'll use your eventObserver example to get a better understanding of when each event is triggered.
    Regards,
    Samuel