Better Save for Subclasses
I broke the save functionality into small chunks to make it easier to subclass. For example:
def saveKerning(self, writer, saveAs=False, progressBar=None):
"""
Save kerning. This method should not be called externally.
Subclasses may override this method to implement custom saving behavior.
"""
if progressBar is not None:
progressBar.update(text="Saving kerning...", increment=0)
if self.kerning.dirty or saveAs:
writer.writeKerning(self.kerning)
self.kerning.dirty = False
self._stampKerningDataState(UFOReader(writer.path))
if progressBar is not None:
progressBar.update()
I just tried to use this in MetricsMachine and realized that I could make it even easier. Now it is implemented like this:
def saveKerning(self, writer):
"""
Save kerning. This method should not be called externally.
Subclasses may override this method to implement custom saving behavior.
"""
writer.writeKerning(self.kerning)
This does away with the subclass needing to deal with any of the data stamping, progress bar updating or anything like that. I think it's much easier. Now I need to figure out how to make something similar for images, data and, especially, layers.
The layer set does a significant amount of work that a subclass shouldn't touch or override. But, there is a major instance of a real world subclass needing to implement custom save behavior. he easiest way to handle this may be to not let subclasses override the layer set save, but pass more info (specifically) the writer down to the layer save method. From there, more deduction could be done about how the save needs to proceed and a more easily subclassable function could be created.