SOLVED mojo canvas mouseEntered



  • I'm learning more about mojo canvas and am having trouble getting mouseEntered/mouseExited to work. Below is a little test script adding a box to the glyph window. mouseDown works. mouseEntered/mouseExited do not. Anyone know whatimdoingwrong?

    from vanilla import *
    from mojo.events import addObserver, removeObserver
    from mojo.canvas import CanvasGroup
    from mojo.drawingTools import rect
    
    debug = True
    
    class observerTest(object):
    
        def __init__(self):
            if debug == True:
                self.w = Window((150, 50), "debug only")
                self.w.bind("close", self.windowClose)
                self.w.open()
            self.setupStuff()
    
        def setupStuff(self):
            addObserver(self, "doStuff", "glyphWindowWillOpen")
    
        def windowClose(self, sender):
            removeObserver(self, "glyphWindowWillOpen")
    
        def doStuff(self, notification):
            self.window = notification["window"]
            self.offsidesUI = CanvasGroup((0, 0, 100, 100), delegate=self)
            self.window.addGlyphEditorSubview(self.offsidesUI)
    
        def draw(self):
            rect(0, 0, 100, 100)
        def mouseDown(self, event):
            print('mouseDown')
        def mouseEntered(self, event):
            print('mouseEntered')
        def opaque(self):
            return False
        def shouldDrawBackground(self):
            return False
    
    observerTest()
    


  • This works perfectly. Thanks for the update.

    If anyone else wants to play, here's a simpler canvas test script :

    from AppKit import NSApp
    from vanilla import *
    from mojo.canvas import CanvasGroup
    from mojo.drawingTools import rect, fill
    
    debug = True
    
    class CanvasTest(object):
    
        def __init__(self):
            windowname = 'Canvas Test'
            if debug == True:
                for window in [w for w in NSApp().orderedWindows() if w.isVisible()]:
                    if window.title() == windowname:
                        window.close()
            self.w = Window((500, 500), windowname, fullSizeContentView=False)
            self.w.g = CanvasGroup((100, 100, -100, -100), delegate=CanvasStuff())
            self.w.open()
    
    class CanvasStuff(object):
    
        def draw(self):
            fill(.5, .2, 1,1)
            rect(0, 0, 600, 600)
    
        def mouseDown(self, event):
            print('mouseDown')
        def mouseUp(self, event):
            print('mouseUp')
        def mouseDragged(self, event):
            print('mouseDragged')
    
        def mouseEntered(self, event):
            print('mouseEntered')
        def mouseExited(self, event):
            print('mouseExited')
    
    CanvasTest()
    
    


  • Thanks for the explanation. I'll give this another shot when the next beta drops.


  • admin

    a tracking area is needed to catch mouseEntered and mouseExited events – this will be added automatically in the next beta. The default will be the bounds of the view. Canvas objects can overwrite this and add their own tracking rects with a new delegate callback: updateTrackingAreas.


Log in to reply