Re: [Pyobjc-dev] import Quartz in 10.5 Xcode Project headache
Brought to you by:
ronaldoussoren
From: Orestis M. <or...@or...> - 2010-02-02 22:24:10
|
On 3 Feb 2010, at 00:09, Chris Bonhage wrote: > I'm having some trouble getting your workaround to function as well; the application launches properly if I take the Quartz import out of the global scope and put it in my method or in applicationDidFinishLaunching_, but the animation is still not working... Allow me to demonstrate: > > import objc > from Foundation import * > > class ShakeDemo(NSObject): > window = objc.IBOutlet() > def applicationDidFinishLaunching_(self, sender): > import Quartz > NSLog("Application did finish launching.") > > @objc.IBAction > def shake_(self, sender): > import Quartz > shake = {'count': 4, 'duration': 0.5, 'vigor': 0.05} > shakeAnim = Quartz.CAKeyframeAnimation.animation() > shakePath = Quartz.CGPathCreateMutable() > frame = self.window.frame() > Quartz.CGPathMoveToPoint(shakePath, None, NSMinX(frame), NSMinY(frame)) > shakeLeft = NSMinX(frame) - frame.size.width * shake['vigor'] > shakeRight = NSMinX(frame) + frame.size.width * shake['vigor'] > for i in range(shake['count']): > Quartz.CGPathAddLineToPoint(shakePath, None, shakeLeft, NSMinY(frame)) > Quartz.CGPathAddLineToPoint(shakePath, None, shakeRight, NSMinY(frame)) > Quartz.CGPathCloseSubpath(shakePath) > # Use KVO to set the path and duration since we "can't change a method" > shakeAnim._['path'] = shakePath > shakeAnim._['duration'] = shake['duration'] > self.window.setAnimations_(NSDictionary.dictionaryWithObject_forKey_(shakeAnim, "frameOrigin")) > self.window.animator().setFrameOrigin_(frame.origin) > > if __name__ == "__main__": > from PyObjCTools import AppHelper > AppHelper.runEventLoop() > > This works perfectly on Snow Leopard, but when I run it on Leopard the window disappears after the shake_ action (its frame turns into NSZeroRect rather than animating as far as I can tell). Obviously, ShakeDemo.window outlet is wired to the window in the xib, as is the shake_ action, so I've attached a project file below so you can try for yourself. Just to make sure, is the same code running under plain Obj-C? You might be dealing with some Core Animation change. Other than that, I know that CAAnimations have a property on what to do when the animation finishes (remove, freeze) and so on. You'd need to see the docs for more specifics though. > > <ShakeDemo.zip> > > On Feb 2, 2010, at 2:31 PM, Orestis Markou wrote: > >> This is a known issue, though I've no idea whose bug it is. >> >> The workaround is to put any Quartz-related imports in a place where they are reached *after* the application launches, >> such as applicationDidFinishLaunching_. If you're doing a lot of work you might move them to an external file to make life easier. >> >> Orestis >> >> On 2 Feb 2010, at 21:14, Chris Bonhage wrote: >> >>> I'm trying to use Quartz in my Xcode template-based PyObjC application >>> to do a window shake animation; everything works great in Snow >>> Leopard. When I go about testing it on Leopard systems, some bad stuff >>> happens at application launch, the dock icon bounces continuously, and >>> the console barfs up this nonsense before quieting down and doing >>> nothing at all: >>> >>> _RegisterApplication(), FAILED TO establish the default connection to >>> the WindowServer, _CGSDefaultConnection() is NULL. >>> *** -[NSRecursiveLock unlock]: lock (<NSRecursiveLock: 0x1d66300> >>> '(null)') unlocked when not locked >>> *** Break on _NSLockError() to debug. >>> NSInternalInconsistencyException - Error (1002) creating CGSWindow >>> >>> This issue doesn't occur if the import occurs after >>> AppHelper.runEventLoop() gets called, but the resulting calls to >>> Quartz don't appear to be functioning properly, as the window does not >>> shake and in fact disappears, changing its frame to NSZeroRect for >>> every frame of the key-animation. >>> >>> I've tested this import issue on a clean Xcode project from the >>> template and it occurs, but the internets at large have little to say >>> about the matter outside of the py2app realm. Any thoughts/ >>> workarounds? The fact that this works just fine on Snow Leopard leads >>> me to believe that this is a bug with PyObjC in Leopard, but I really >>> hope not. |