SOLVED Observe point changes/movements?



  • I'm hoping to record the changes made to points in glyphs. My current plan is to make a dictionary of point locations when a glyph is opened (or possibly just accessing the glif data), then comparing point locations when points are moved, and making a dictionary of point movements.

    Is there an observer that can send a notification when points are moved?

    I'm hoping for something along the lines of pointMovedInCurrentGlyph, so I could add something like this to my code...

    addObserver(self, 'recordPointMovement', "pointMovedInCurrentGlyph") # fake code
    

    ...but I'm not finding anything obvious.

    Am I missing something? How might I best approach this?



  • Makes sense. Thanks so much for your help!


  • admin

    a script or something else like fe a transormation from the inspector



  • Ohh of course, that is simpler than I was thinking!

    I suppose that the only time points would move without being selected is if they were moved by a script, right?


  • admin

    the Contour.PointsChanged calls your callback with a notification object:

    notification.object # in this case the contour object
    notification.data # optional data related to the event, in this case it will be None
    

    this notification is sent on different events: inserting, removing, changing start point...

    in most cases the moved points are the selected ones:

    glyph.selectedPoints
    


  • It's working nicely to show that a point moved!

    Is there a simple way to know which point moved, once I get the notification? The notification I receive is:

    Contour.PointsChanged --> <lib.fontObjects.doodleContour.DoodleContour object at 0x112f24320>
    

    Ideally, I'd want to get to data which was the point index with its parent contour index.

    If I print notification.data, it only gives None.

    Does the object at 0x112f24320 mean anything?

    Would I have to do something like looping through all points to compare them to a "before" state (possibly in another layer), then assign changed points a unique identifier with generateIdentifierForPoint(point)?



  • @frederik said in Observe point changes/movements?:

    Contour.PointsChanged

    Amazing, thank you! I'll give this a shot tonight and see where it gets me.


  • admin

    There is a Contour.PointsChanged notification for a contour object.

    There are no notifications for each point object.

    a tiny script that shows all font level notifications:

    
    import vanilla
    
    
    class AllNotifications(object):
        
        def __init__(self):
            
            self.w = vanilla.Window((400, 400), minSize=(200, 200))
            self.w.e = vanilla.TextEditor((0, 0, 0, 0))
            # keep a ref otherwise weak ref will not work
            self.w._ref = self
            self.w.bind("close", self.windowClose)
            self.w.open()
            
            self.font = CurrentFont().naked()        
            self.font.dispatcher.addObserver(self, "callback", notification=None, observable=None)
        
        def windowClose(self, sender):
            # remove the observer
            self.font.dispatcher.removeObserver(self, notification=None, observable=None)
            # remove the references
            del self.w._ref    
            del self.font
            
        def callback(self, notification):
            txt = "\n%s --> %s" % (notification.name, notification.object)        
            self.w.e.set(self.w.e.get() + txt)
     
     
    AllNotifications()
    

Log in to reply