SOLVED Issue: Custom Tool – getGlyph() returns None



  • I'm creating some awesome Custom Tool.
    I'm trying to use the self.getGlyph() method inside overridden becomeActive method. When I'm using getGlyph() in there, it returns None instead of a fontParts object.

    Is there maybe another way to do it? or is it a bug? I really need this glyph object when the tool becomes active.



  • Great! Works! thanks a lot
    (I thought that since getGlyph() is BaseEventTool method, it will be more 'proper' to use it instead of CurrentGlyph() )



  • ps. BaseEventTool.getGlyph() returns None only the first time you activate the tool in a new glyph window; the second time, it does return the current glyph:

    custom tool is active​
    None
    <RGlyph 'i' ('foreground') at 4691232360>
    custom tool is inactive
    custom tool is active
    <RGlyph 'i' ('foreground') at 4485911888>
    <RGlyph 'i' ('foreground') at 4691234264>
    


  • hello @RafaŁ-Buchner,

    I don’t really know what BaseEventTool.getGlyph() does… (so not sure if it’s a bug)

    why not simply use CurrentGlyph() instead?

    here’s an example script based on simpleTool.py:

    from mojo.events import BaseEventTool, installTool, uninstallTool
    from mojo.drawingTools import *
    
    class MyTool(BaseEventTool):
        
        def setup(self):
            self.position = None
        
        def mouseDown(self, point, clickCount):
            self.position = point
        
        def mouseDragged(self, point, delta):
            self.position = point
        
        def mouseUp(self, point):
            self.position = None
    
        def becomeActive(self):
            print('custom tool is active')
            print(self.getGlyph())
            print(CurrentGlyph())
    
        def becomeInactive(self):
            print('custom tool is inactive')
        
        def draw(self, scale):
            if self.position is not None:
                size = 10
                x = self.position.x - size
                y = self.position.y - size
                fill(None)
                stroke(1, 0, 0)
                oval(x, y, size*2, size*2)
        
        def getToolbarTip(self):
            return "My Tool Tip"
        
    installTool(MyTool())
    

Log in to reply