Undo for multiple glyphs/list?

RoboFont Forums Help / General Undo for multiple glyphs/list?

Tagged: 

This topic contains 7 replies, has 2 voices, and was last updated by  franz 8 years, 7 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #3823

    franz
    Participant

    Hi,

    Currently working on my first tiny script/extension, all is working well in term sof 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

    #3824

    frederik
    Keymaster

    He

    A list object does not have a prepareUndo preformUndo 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 cause each glyph has his own undo manager.

    hope this helps

    #3825

    franz
    Participant

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

    Franz

    #3826

    franz
    Participant

    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

    #3827

    franz
    Participant

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

    http://github.com/franzheidl/SidebearingsEQ

    #3828

    frederik
    Keymaster

    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!

    #3830

    franz
    Participant

    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.

    #3831

    franz
    Participant

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

    Just pushed 1.1 to github:

    http://github.com/franzheidl/SidebearingsEQ

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.