I am trying to modify a plugin (showNextFont by Guido Ferreyra ) so that an exit function is called just before the plugin is closed.
Not sure if this is the correct way but I’ve been trying variations of this kind of setup of
__exit__ functions and a
with outside of the class.
Am I on the right track here? Are there plugin examples which use this approach? Is there another way of achieving this?
class showNextFont(ReporterPlugin): def __init__(self, name): print('init') self.filename = filename def __enter__(self): print ("enter") self.file = open(self.filename, 'w') return self.file def __exit__(self, type, value, traceback): if self.file: self.file.close() print ("exit")
snf = showNextFont.alloc().init() with snf as file: print ("working")