Capture glyph cells on drag and drop



  • Let's say there is a window and I drag some selected glyphs from a font window to that window. Is it possible to capture the name of those glyphs or the font?

    Thank you so much ( ͡° ͜ʖ ͡°)!


  • admin

    hello @bahman,

    I gave it a try – this seems to work:

    from vanilla import Window, List
    from AppKit import NSDragOperationCopy
    from lib.settings import doodleSelectedGlyphIndexesPboardType
    
    class TestWindow:
    
        def __init__(self):
            self.w = Window((400, 200), 'test')
            self.w.list = List((10, 10, -10, -10),
                    [],
                    selfApplicationDropSettings=dict(type=doodleSelectedGlyphIndexesPboardType,
                            allowDropOnRow=True,
                            allowDropBetweenRows=True,
                            operation=NSDragOperationCopy,
                            callback=self.selfApplicationDropCallback))
            self.w.open()
    
        def selfApplicationDropCallback(self, sender, dropInfo):
            isProposal = dropInfo["isProposal"]
    
            if not isProposal:
                glyphs = dropInfo["data"]
                source = dropInfo["source"]
                glyphNames = [source[glyphIndex].name for glyphIndex in glyphs]
                self.w.list.set(glyphNames)
    
            return True
    
    TestWindow()
    

    but using stuff from the lib is not recommended… maybe @frederik knows a better solution.

    cheers!