Re: [Pyobjc-dev] simple animation w/ NSTimer
Brought to you by:
ronaldoussoren
|
From: Carl B. <car...@gm...> - 2008-04-01 07:51:04
|
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 <pyo...@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
> >
> >
> >
>
|