Re: [Pyobjc-dev] simple animation w/ NSTimer
Brought to you by:
ronaldoussoren
|
From: Jack J. <Jac...@cw...> - 2008-04-01 12:01:16
|
This starts to sound like a problem I have occasionally (in ObjC), which has to do with trying to do drawing in another thread. What works for me is using performSelectorOnMainThread to call setNeedsDisplay in the main thread. That usually does the trick. But, given the fact that you come from a timer, you may then want to completely get rid of the NSTimer and use iterative performSelector:withObject:afterDelay: to do everything in the main thread. On 1 apr 2008, at 09:51, Carl Bauer wrote: > Well, now I'm confused. def isOpaque(self) is now in the class and > returns True (a key step, thanks David). I'm also using > setNeedsDisplay_(True) and displayIfNeeded() methods (thanks Bob). > Still, drawRect is not called. Here's the code: > > class Lattice(NibClassBuilder.AutoBaseClass): > # the actual base class is NSView > color = NSColor.redColor() > toggle = 0 > rect = NSMakeRect(40,40,40,40) > > def drawRect_(self,frameRect): > print "drawRect called" > > def isOpaque(self): > return True > > def start_(self, sender): > > self > .timer > = > NSTimer > .scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_ > (1.0,self,self.tick,None,True) > > def tick(self,timer): > self.toggle = (self.toggle+1)%2 > if self.toggle: > self.color = NSColor.blueColor() > else: > self.color = NSColor.redColor() > self.setNeedsDisplay_(True) > self.displayIfNeeded() > > Google searches turned up a few comments about having to return > control to the runloop for anything to happen. Not sure I understand > why that is, since all the appledev docs tell me to just do exactly > what I'm doing and the runloop should be notified. I don't even know > when I took control from the runloop or how to give it back. > > I will try some cocoa lists if no one knows what's going on here. > Thanks everyone. > > -Carl > > On Mon, Mar 31, 2008 at 4:55 PM, Carl Bauer <car...@gm...> > wrote: > Thanks guys. I have read the drawing guide, Bob. It was okay. I > guess I need to read the guide on Views as well before I ask any > more questions. Till then... > > -Carl > > > On Mon, Mar 31, 2008 at 4:25 PM, Bob Vadnais <pyobjc- > de...@bo...> wrote: > On Mar 31, 2008, at 8:10 AM, Carl Bauer wrote: > > > Hey John, thanks for the reply. I implemented your changes, but the > > display is still not being refreshed. I put a print statement inside > > tick_(...) and drawRect_(...). When the timer starts, the print > > statement inside the tick method is called right on cue every > > second. The print statement in drawRect, however, is never called, > > despite my self.display() line inside tick. > > I suggest invoking self.setNeedsDisplay_(True) before self.display(). > > Also, read the Cocoa drawing Guide available from http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaDrawingGuide/CocoaDrawingGuide.pdf > > Ciao, > Bob > > > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace_______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev -- Jack Jansen, <Jac...@cw...>, http://www.cwi.nl/~jack If I can't dance I don't want to be part of your revolution -- Emma Goldman |