Skip to content

Instantly share code, notes, and snippets.

@MBurvill
Created December 17, 2017 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MBurvill/fb6772f9e8bc49e583f16e6dc650b7d8 to your computer and use it in GitHub Desktop.
Save MBurvill/fb6772f9e8bc49e583f16e6dc650b7d8 to your computer and use it in GitHub Desktop.
isCompatibleObserverBugTest for RF forum
# IS COMPATIBLE BUG TEST WITH OBSERVING GLYPH CHANGES
from AppKit import *
import vanilla
from defconAppKit.windows.baseWindow import BaseWindowController
from mojo.events import addObserver, removeObserver
from mojo.roboFont import CurrentGlyph, RGlyph
class currentGlyphObserverExample(BaseWindowController):
def __init__(self):
# keep track of the current glyph
self.currentGlyph = None
self.w = vanilla.Window((500, 100), "currentGlyphObserverExample", minSize=(100, 100))
self.w.whatGlyphIsSubscribedButton = vanilla.Button((5, 5, -5, 100), "whatGlyphIsSubscribedButton", callback=self.whatGlyphIsSubscribedButton)
#add observer currentGlyphChanged do something when currentGlyphChanged is called
addObserver(self, "currentGlyphChanged", "currentGlyphChanged")
self.setUpBaseWindowBehavior()
#self.currentGlyphChanged({}) #This was in the original example, I don't know what it is
self.minFont = AllFonts()[0]
self.maxFont = AllFonts()[1]
self.minGlyph = None
self.maxGlyph = None
self.w.open()
def windowCloseCallback(self, sender):
#when this window w is closed, unsubscribe the glyph and remove the observer by name
self._unsubscribeGlyph()
removeObserver(self, "currentGlyphChanged")
super(currentGlyphObserverExample, self).windowCloseCallback(sender)
def whatGlyphIsSubscribedButton(self, sender):
print self.currentGlyph,'is subscribed'
def function(self):
self.minGlyph = self.minFont[self.currentGlyph.name]
self.maxGlyph = self.maxFont[self.currentGlyph.name]
print 'self.currentGlyph',self.currentGlyph
print 'self.minGlyph',self.minGlyph
print 'self.maxGlyph',self.maxGlyph
print 'compatible?', self.minGlyph.isCompatible(self.maxGlyph, report=True)
def currentGlyphChanged(self, info):
glyph = CurrentGlyph()
if glyph == self.currentGlyph:
return
self._unsubscribeGlyph()
if glyph is not None:
self.subscribeGlyph(glyph)
self.currentGlyph = glyph
# a glyph changed, we can call our function now
#print 'glyph changed'
self.function()
else:
print glyph, 'else'
def _unsubscribeGlyph(self):
if self.currentGlyph is not None:
#print 'unsubscribe', self.currentGlyph
self.currentGlyph.removeObserver(self, "Glyph.Changed")
self.currentGlyph = None
def subscribeGlyph(self, glyph):
if glyph is not None:
#print 'subscribe glyph', glyph
glyph.addObserver(self, "_glyphChanged", "Glyph.Changed")
def _glyphChanged(self, notification):
# called when points/contour changes in glyph
#print 'notification outline changes'
self.function()
OpenWindow(currentGlyphObserverExample)
'''
>>>>> ERROR WHEN DRAWING NEW CONTOUR USING DEFAULT BEZIER TOOL
self.currentGlyph <Glyph B (foreground)>
self.minGlyph <Glyph B (foreground)>
self.maxGlyph <Glyph B (foreground)>
compatible? Traceback (most recent call last):
File "lib/eventTools/bezierDrawingTool.pyc", line 149, in _mouseDown
File "lib/eventTools/bezierDrawingTool.pyc", line 64, in createContour
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/defcon/objects/glyph.py", line 397, in appendContour
File "lib/fontObjects/doodleBaseGlyph.pyc", line 661, in insertContour
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/defcon/objects/glyph.py", line 432, in insertContour
File "lib/fontObjects/doodleBaseGlyph.pyc", line 75, in _set_dirty
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/defcon/tools/notifications.py", line 195, in postNotification
File "<untitled>", line 79, in _glyphChanged
File "<untitled>", line 49, in function
File "lib/fontObjects/robofabWrapper.pyc", line 2888, in isCompatible
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontMath/mathGlyph.py", line 221, in __init__
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/defcon/objects/glyph.py", line 309, in drawPoints
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/defcon/objects/contour.py", line 435, in drawPoints
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontMath/mathGlyph.py", line 91, in endPath
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontMath/mathGlyph.py", line 43, in _flushContour
IndexError: list index out of range
Traceback (most recent call last):
File "lib/views/zoomScrollView.pyc", line 271, in drawRect_
File "lib/views/doodleGlyphView.pyc", line 529, in _draw
File "lib/views/doodleGlyphView.pyc", line 790, in _drawPoints
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/defcon/objects/glyph.py", line 644, in getRepresentation
representation = factory(self, self.getParent(), **kwargs)
File "lib/fontObjects/factories/outlineInformationFactory.pyc", line 136, in OutlineInformationFactory
File "lib/fontObjects/factories/outlineInformationFactory.pyc", line 107, in getData
IndexError: list index out of range
self.currentGlyph <Glyph B (foreground)>
self.minGlyph <Glyph B (foreground)>
self.maxGlyph <Glyph B (foreground)>
compatible? Traceback (most recent call last):
File "lib/eventTools/bezierDrawingTool.pyc", line 297, in _mouseUp
File "lib/fontObjects/doodleBaseGlyph.pyc", line 75, in _set_dirty
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/defcon/tools/notifications.py", line 195, in postNotification
File "<untitled>", line 79, in _glyphChanged
File "<untitled>", line 49, in function
File "lib/fontObjects/robofabWrapper.pyc", line 2888, in isCompatible
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontMath/mathGlyph.py", line 221, in __init__
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/defcon/objects/glyph.py", line 309, in drawPoints
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/defcon/objects/contour.py", line 435, in drawPoints
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontMath/mathGlyph.py", line 91, in endPath
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/fontMath/mathGlyph.py", line 43, in _flushContour
IndexError: list index out of range
Traceback (most recent call last):
File "lib/views/zoomScrollView.pyc", line 271, in drawRect_
File "lib/views/doodleGlyphView.pyc", line 529, in _draw
File "lib/views/doodleGlyphView.pyc", line 790, in _drawPoints
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/defcon/objects/glyph.py", line 644, in getRepresentation
representation = factory(self, self.getParent(), **kwargs)
File "lib/fontObjects/factories/outlineInformationFactory.pyc", line 136, in OutlineInformationFactory
File "lib/fontObjects/factories/outlineInformationFactory.pyc", line 107, in getData
IndexError: list index out of range
Traceback (most recent call last):
File "lib/views/zoomScrollView.pyc", line 271, in drawRect_
File "lib/views/doodleGlyphView.pyc", line 529, in _draw
File "lib/views/doodleGlyphView.pyc", line 790, in _drawPoints
File "/Applications/RoboFont.app/Contents/Resources/lib/python2.7/defcon/objects/glyph.py", line 644, in getRepresentation
representation = factory(self, self.getParent(), **kwargs)
File "lib/fontObjects/factories/outlineInformationFactory.pyc", line 136, in OutlineInformationFactory
File "lib/fontObjects/factories/outlineInformationFactory.pyc", line 107, in getData
IndexError: list index out of range
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment