Observers and events
-
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.
-
great!
thanks
-
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.
-
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.
-
mmmm, oke
I'm kind of guessing what you want to achieve but maybe this can help to.
A
SpaceCenter
object also has asetRaw
andgetRaw
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)
(I've just updated http://doc.robofont.com/api/mojo/mojo-ui/ with
getRaw
andsetRaw
)
-
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).
-
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.
-
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.
-
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....