1""" 2A number of usefull categories on AppKit classes 3""" 4__all__ = () 5import objc 6from AppKit import NSGraphicsContext 7 8class _ctxHelper(object): 9 def __enter__(self): 10 NSGraphicsContext.saveGraphicsState() 11 12 def __exit__(self, exc_type, exc_value, exc_tb): 13 NSGraphicsContext.restoreGraphicsState() 14 return False 15 16 17class NSGraphicsContext (objc.Category(NSGraphicsContext)): 18 @classmethod 19 def savedGraphicsState(self): 20 return _ctxHelper() 21 22try: 23 from AppKit import NSAnimationContext 24 25 class NSAnimationContext (objc.Category(NSAnimationContext)): 26 @classmethod 27 def __enter__(cls): 28 cls.beginGrouping() 29 30 @classmethod 31 def __exit__(cls, exc_type, exc_value, exc_tb): 32 cls.endGrouping() 33 return False 34 35except ImportError: 36 pass 37