Re: [Pyobjc-dev] simple animation w/ NSTimer
Brought to you by:
ronaldoussoren
|
From: Carl B. <car...@gm...> - 2008-03-31 15:10:50
|
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.
On Mon, Mar 31, 2008 at 3:45 AM, John Buckley <nho...@go...>
wrote:
> Hi Carl,
> You don't pass in the function object when specifying Objective-C methods,
> but a method "selector", which in Python land is just a string (in
> Objective-C selectors have the type SEL, which may or may not also be a
> string). Be careful to fully specify the selector by including the colon for
> each argument e.g.
>
> NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
> 1.0,self,'tick:',None,True)
>
> Note that in the Python method definition the colon is replaced by an
> underscore. So in Objective-C your 'tick' method would look like:
>
> - (void)tick:(NSTimer*)timer
> {
> // Implemenation here
> }
>
> In Python this must be translated to:
>
> def tick_(self, timer):
> # implementation here
>
> However the "selector" string must always use the Objective-C version i.e.
> with the colon.
>
> Regards,
>
> John
> ____________________
>
> Dr. John Buckley
> nho...@gm...
>
> www.olivetoast.com
>
> Mac OS X Leopard
> ____________________
>
> On 31 Mar 2008, at 00:03, Carl Bauer wrote:
>
> I'm a physics grad student (not a coder) wanting to put together a slick
> realtime physics simulation for my statistical mechanics class. (Simulating
> the 2D Ising model for ferromagnets in case anyone cares).
>
> Anyway, to start, I'm just trying to get a rectangle to change colors
> periodically. Why doesn't this work?
>
> import objc
> from Foundation import *
> from AppKit import *
> from PyObjCTools import NibClassBuilder, AppHelper
> from Quartz import NSColor
>
> NibClassBuilder.extractClasses("MainMenu")
>
> # class defined in MainMenu.nib
> 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):
> NSEraseRect(self.rect)
> self.color.setFill()
> NSRectFill(self.rect)
>
> 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.display()
>
> if __name__ == "__main__":
> AppHelper.runEventLoop()
>
> The rectangle is drawn just fine at the beginning, but the timer doesn't
> seem to actually invoke drawRect_. I'm probably just not understanding how
> to properly use display()? Let me know if I'm being annoying and should just
> post to a different mailing list.
>
> Thanks,
> Carl
> -------------------------------------------------------------------------
> 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
>
>
>
|