Undo for multiple glyphs/list?



  • Hi,

    Currently working on my first tiny script/extension, all is working well in terms of functionality, the only thing I can't seem to get working is the undo:

    The user can scope the operation to be applied to either all glyphs of a font or just a selection, which in both cases results in a list of glyphs I then loop through.

    Want I'd want is to add the prepareUndo and performUndo to the list object that contains all the glyphs the user has selected.

    So my list is either

    glyphNames = font.keys() 
    

    OR

    glyphNames = font.selection
    

    So when I call

    glyphNames.prepareUndo("blah")
    #functionality goes here
    glyphNames.performUndo()
    

    I get this in the output

    AttributeError: 'list' object has no attribute performUndo()
    

    Is there any way to get an undo working for a list of glyphs?
    Or do I need to import a specific module to get the undo working apart from the ones I have (AppKit, vanilla, defcon BaseWindowController)?

    Any help would be much appreciated, my apologies if that's a terribly stupid question, I just want to learn and find my way around here, my knowledge of Python is is much less than what you could call limited...

    Many thanks,
    Franz



  • Ok, convinced :-)
    It's a floating window now.

    Just pushed 1.1 to github:

    http://github.com/franzheidl/SidebearingsEQ



  • Many thanks Frederik, I tried that but felt somewhat awkward (at least to me), not in terms of Undo but in the environment of the other windows. Will reconsider though.


  • admin

    cool

    you could change the vanilla.Window to a vanilla.FloatingWindow

    A floating window will not became the first responder to actions send by fe. the menu bar.

    succes!



  • In any event, I have just pushed my first little RoboFont Extension to github:

    http://github.com/franzheidl/SidebearingsEQ



  • Hi Frederik,

    one more thing: The Undo/Redo seems to be available in the Edit menu only when the Font Collection or the Glyph Editor window has the focus, not when my own window is in front.

    Am I still doing something wrong or is this OK/expected behaviour?

    Sorry to be a pain, I just want to know if I'm doing ok and learn a bit while at it :-)

    Many thanks,
    Franz



  • Hi Frederik,
    many thanks, works a treat!
    I just wasn't aware the undo manager was bound to the glyph.

    Franz


  • admin

    He

    A list object does not haveprepareUndo / performUndo methods.

    The best way is to tell each glyph while looping over all glyphNames to prepareUndo / preformUndo:

    font = CurrentFont()
    glyphNames = font.selection
    if not glyphNames:
        glyphNames = font.keys()
    
    for glyphName in glyphNames:
        glyph = font[glyphName]
        glyph.prepareUndo("myAction")
        # action start
        glyph.move((100, 100))
        # action end
        glyph.performUndo()
    

    You can have multiple undo's when selecting multiple glyphs in the Font Overview and hit ⌘-Z.

    Bundling undo states over several glyphs into one undo state isn't possible because each glyph has his own undo manager.

    hope this helps


Log in to reply