Observers and events

RoboFont Forums Enhancements Observers and events

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

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #3782

    MarkSimonson
    Participant

    Is it possible to add an observer that watches the edit field in the Space Center? I can read the contents of the current Space Center manually, but I want to be able to react whenever the user types or edits the sample text in the edit field.

    #3784

    frederik
    Keymaster

    This is a feature planned feature for the next version.
    Something similar like tools and his observers for the Glyph View but enhanced for Space Center.

    (see http://cl.ly/ExxK :)

    It is possible but it will be with some detours….

    #3798

    MarkSimonson
    Participant

    Okay, plan B then.

    Is there a way to go back and forth between a list of glyphs and a string? For example,

    Go from this:

    [‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘exclam’]

    to this:

    “Hello!”

    and back again? Seems like there should be something like this built into one of the included packages, but I don’t know where to start looking.

    #3800

    frederik
    Keymaster

    Everything is depending on the font you want to use and the character unicode mapping inside that font.

    you can use something similar:

    ## this is used internally to split inputted text to a list of glyph names based on the current font
    from lib.UI.spaceCenter.glyphSequenceEditText import splitText
    from robofab.interface.all.dialogs import AskString
    
    ## get some text
    text = AskString("input")
    print "input:", text
    
    font = CurrentFont()
    
    ## the character map
    cmap = font.getCharacterMapping()
    
    ## split the text based on the camp in to a list of glyph names
    glyphNameList = splitText(text, cmap)
    
    print "as glyph names list:", glyphNameList
    
    ## loop over the glyph names asks for their unicode value in the current font
    ## convert it back to text based on that unicode value
    backToText = u""
    for glyphName in glyphNameList:
        if glyphName in font:
            glyph = font[glyphName]
            if glyph.unicode is not None:
                backToText += u"%s" %(unichr(glyph.unicode))
            else:
                backToText += "/%s " %glyphName    
        else:
            backToText += "/%s " %glyphName
    
    print "backtoText:", backToText
    
    

    hope this makes sense.

    #3801

    MarkSimonson
    Participant

    Ah, okay. I may be able to work from this.

    Essentially, though, I have a little window built with vanilla with a textEditor in it, and I want to get and set the text in the Space Center text field. This is in the form of a list of glyph names, while the vanilla textEditor field is in the form of a string.

    The font I’m using is whatever the default is in the vanilla textEditor field (Helvetica of some kind).

    #3806

    frederik
    Keymaster

    mmmm, oke

    Im kind of guessing what you want to achieve but maybe this can help to.

    A SpaceCenter object also has a setRaw and getRaw methods, expecting a string, text as input or return.

    from robofab.interface.all.dialogs import AskString
    from mojo.UI import CurrentSpaceCenter
    
    sp = CurrentSpaceCenter()
    
    text = AskString("input")
    sp.setRaw(text)
    

    (Ive just updated http://doc.robofont.com/api/mojo/mojo-ui/ with getRaw and setRaw)

    #3807

    MarkSimonson
    Participant

    Yes, that will work! Thanks!

    Sorry for not being clearer about what I was trying to accomplish — I could have spared you from writing all that code in your previous response. I appreciate your time.

    #3811

    MarkSimonson
    Participant

    Here’s the script I’ve been working on:

    http://www.ms-studio.com/Robofont/PangrammerHelper.py

    It’s a little window for composing pangrams. If Space Center is active, it displays them there as well.

    #3815

    frederik
    Keymaster

    great!
    thanks

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

You must be logged in to reply to this topic.