fontParts
fontParts copied to clipboard
setting glyph.unicodes
A Unicode value can be removed from a glyph by just setting g.unicode = None
When I do g.unicodes = None, I get this:
Traceback (most recent call last):
File "lib/eventTools/eventManager.pyc", line 131, in callObserver_withMethod_forEvent_withInfo_
File "lib/UI/inspector/basePane.pyc", line 86, in _currentGlyphChanged
File "lib/UI/inspector/basePane.pyc", line 64, in _unsubscribeGlyph
File "lib/UI/inspector/guidelinesPane.pyc", line 158, in unsubscribeGlyph
AttributeError: 'NoneType' object has no attribute 'removeObserver'
Traceback (most recent call last):
File "lib/eventTools/eventManager.pyc", line 131, in callObserver_withMethod_forEvent_withInfo_
File "lib/UI/inspector/basePane.pyc", line 86, in _currentGlyphChanged
File "lib/UI/inspector/basePane.pyc", line 64, in _unsubscribeGlyph
File "lib/UI/inspector/guidelinesPane.pyc", line 158, in unsubscribeGlyph
AttributeError: 'NoneType' object has no attribute 'removeObserver'`
I now understand you’re supposed to set g.unicodes = [], but is failing like this really necessary?
(This issue was originally reported to Frederik, who suggested posting it here)
Every line in that traceback is RF code, so I don't think it's a fontParts issue.
The traceback for the same operation in DrawBot (with fontParts.fontshell presumably) gives this traceback:
Traceback (most recent call last):
File "<untitled>", line 11, in <module>
File "/Users/just/code/git/drawbot/dbvenv/lib/python3.6/site-packages/fontParts/base/base.py", line 101, in __set__
setter(value)
File "/Users/just/code/git/drawbot/dbvenv/lib/python3.6/site-packages/fontParts/base/glyph.py", line 210, in _set_base_unicodes
value = list(value)
TypeError: 'NoneType' object is not iterable
Not that great either, but does hint at what's going wrong.
Franks issues is that None could be converted to a list while setting glyph.unicodes
That's not how I read it, though. He writes:
I now understand you’re supposed to set g.unicodes = [], but is failing like this really necessary?
Which I read as "Yes, assigning None is an error and I should have assigned an iterable instead, but I would have found out sooner if RF hadn't given me an incomprehensible traceback" :)
I find fontPart's behavior acceptable (although the error message could be better), and I wouldn't want to change it to accept None. It's a sequence that can be empty, but not None.
I guess you’re both right. For the sake of simplicity, I’d perhaps like to be able to assign f.unicodes = None, but it’s not very reasonable to expect that. However, I think a more understandable traceback would be nice. For example like this:
g = CurrentGlyph()
g.width = None
Traceback (most recent call last):
File "<untitled>", line 2, in <module>
File "/Applications/RoboFont.app/Contents/Resources/lib/python3.6/fontParts/base/base.py", line 101, in __set__
File "/Applications/RoboFont.app/Contents/Resources/lib/python3.6/fontParts/base/glyph.py", line 327, in _set_base_width
File "/Applications/RoboFont.app/Contents/Resources/lib/python3.6/fontParts/base/normalizers.py", line 362, in normalizeGlyphWidth
TypeError: Glyph width must be an :ref:`type-int-float`, not NoneType.