Hi, I'm trying to write a LedMorph that shows the actual time. It should have also two buttons, 'quit' which closes the frame and 'stop' which should stop the clock.
Unfortunately the stop button does not work and I can't figure out where's the problem. Even by trying to send the stopStepping message manually from a workspace the LedMorph doesn't stop stepping. Does anyone know what's the problem? I post the code, please tell me what I'm doing wrong. -> OriginalLed class has messages: initialize, step (they overwrite ancestor messages to set desired behavior) LedMorph subclass: #OriginalLed instanceVariableNames: 'time' classVariableNames: '' poolDictionaries: '' category: 'MyLed' initialize super initialize . time := Time new . self chars: 8 . self flash: true . self extent: (100@100) . self position: (200@150) . step time := Time now . self string: time print24 . -> LedFrame is a subclass of AlignmentMorph, which contains the OriginalLed and buttons. It defines 4 messages: -> initialize, addControls, addLed, stopStepping AlignmentMorph subclass: #LedFrame instanceVariableNames: 'controls led' classVariableNames: '' poolDictionaries: '' category: 'MyLed' initialize super initialize . self listDirection: #bottomToTop . self position: (200 @ 150) . self addControls . self addLed . self openInWorld . addControls controls := AlignmentMorph new listDirection: #rightToLeft . controls addMorph: (SimpleButtonMorph new target: led; label: 'stop'; actionSelector: #stopStepping) . controls addMorph: (SimpleButtonMorph new target: self; label: 'quit'; actionSelector: #delete) . self addMorph: controls . addLed led := OriginalLed new . self addMorph: led . stopStepping led stopStepping . I didn't write any comment inside the code, since it's very simple to understand. Sorry if I misspelled any term or said anything wrong, I'm a real squeak beginner. |
Hi Frank,
I haven't tried the example yet. But I know from my own work that when you don't want steps #wantsSteps should return false. Otherwise each time you pick your morph up and drop it the system restarts stepping. so wantsSteps (ck the spelling) ^ time isNil and stopStepping super stopStepping time := nil . startStepping super startStepping time := Time now. Hth, Yours in curiosity and service, --Jerome Peace --- On Sat, 3/6/10, FrankBz <[hidden email]> wrote: > From: FrankBz <[hidden email]> > Subject: [Newbies] LedMorph - step problem > To: [hidden email] > Date: Saturday, March 6, 2010, 11:25 AM > > Hi, I'm trying to write a LedMorph that shows the actual > time. It should have > also two buttons, 'quit' which closes the frame and 'stop' > which should stop > the clock. > Unfortunately the stop button does not work and I can't > figure out where's > the problem. > Even by trying to send the stopStepping message manually > from a workspace > the LedMorph doesn't stop stepping. > Does anyone know what's the problem? > > I post the code, please tell me what I'm doing wrong. > > -> OriginalLed class has messages: initialize, step > (they overwrite ancestor > messages to set desired behavior) > > LedMorph subclass: #OriginalLed > instanceVariableNames: 'time' > classVariableNames: '' > poolDictionaries: '' > category: 'MyLed' > > initialize > super initialize . > time := Time new . > self chars: 8 . > self flash: true . > self extent: (100@100) . > self position: (200@150) . > > step > time := Time now . > self string: time print24 . > > -> LedFrame is a subclass of AlignmentMorph, which > contains the OriginalLed > and buttons. It defines 4 messages: > -> initialize, addControls, addLed, stopStepping > > AlignmentMorph subclass: #LedFrame > instanceVariableNames: 'controls led' > classVariableNames: '' > poolDictionaries: '' > category: 'MyLed' > > initialize > super initialize . > self listDirection: #bottomToTop . > self position: (200 @ 150) . > self addControls . > self addLed . > self openInWorld . > > addControls > controls := AlignmentMorph new > listDirection: #rightToLeft . > > controls addMorph: (SimpleButtonMorph > new target: led; label: 'stop'; > actionSelector: #stopStepping) . > controls addMorph: (SimpleButtonMorph > new target: self; label: 'quit'; > actionSelector: #delete) . > self addMorph: controls . > > addLed > led := OriginalLed new . > self addMorph: led . > > stopStepping > led stopStepping . > > I didn't write any comment inside the code, since it's very > simple to > understand. > Sorry if I misspelled any term or said anything wrong, I'm > a real squeak > beginner. > -- > View this message in context: http://n4.nabble.com/LedMorph-step-problem-tp1582908p1582908.html > Sent from the Squeak - Beginners mailing list archive at > Nabble.com. > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi Jerome, thanks for answering.. I modified the program as you suggested and now it seems to work fine.
Basically it starts or stops stepping when sending those messages to the LedFrame in the workspace. What is still not working is the button that should invoke stopStepping. May it depend on the fact that actionSelector message cannot find the #stopStepping I defined? The reason why I'm supposing that is that the other button which selects #delete works fine. Have you any suggestion about that? Just to be precise I defined wantsSteps, startStepping and stopStepping in the OriginalLed class, then I added two methods in the main frame startStepping and stopStepping in order to invoke the methods on the instance variable of led of LedFrame. Thanks in advance |
On 08.03.2010, at 13:42, FrankBz wrote:
> > > Hi Jerome, thanks for answering.. I modified the program as you suggested and > now it seems to work fine. > Basically it starts or stops stepping when sending those messages to the > LedFrame in the workspace. > What is still not working is the button that should invoke stopStepping. May > it depend on the fact that actionSelector message cannot find the > #stopStepping I defined? The reason why I'm supposing that is that the other > button which selects #delete works fine. > > Have you any suggestion about that? > > Just to be precise I defined wantsSteps, startStepping and stopStepping in > the OriginalLed class, then I added two methods in the main frame > startStepping and stopStepping in order to invoke the methods on the > instance variable of led of LedFrame. > > Thanks in advance That seems wrong - you should not define startStepping and stopStepping because those methods already exist. - Bert - _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by FrankBz
Sorry, I solved it. The problem was that I had to change the target of that button to 'self' instead of the led instance.
Anyway, if you have any other advise or suggestion, you're welcome. Thanks a lot |
In reply to this post by Bert Freudenberg
_______________________________________________
|
Free forum by Nabble | Edit this page |