Send to Printer


ST 4U 218: Creating a Non-Visual Part in VA Smalltalk

April 11, 2012 12:22:44.398

Today's Smalltalk 4 You looks at creating a new part (non-visual) using the VA Smalltalk parts editing tools. In the next screencast, we'll use the part created here in a UI. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:


If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Today we'll create a non-visual part in VA Smalltalk. IN our next tutorial, we'll integrate this part into a visual one. To get started, open the organizer - which opens automatically in a new VA image:


Enter an application name, let the rest default, and hit ok. When the Composition editor opens, you can close that - we won't need it yet. Instead, from the defining window, create a new part. Give it a name, and set it to be non-visual:


In the View menu, switch to the public interface editor. We need to add some attributes (instance variables), actions, and events. For the latter ones we'll be using the script editor to add Smalltalk code.

Script Editor

Add length and repeat. For repeat, set the object type to Boolean. Then change the tab (top of the tool) to events - we need to add an event, timerFired:


Next, change the tab to actions, and set up stop and start as actions (they will start and stop the timer):


Now that we've done all of that, pull down the "File" menu, and select "Generate Default Scripts". You should see the following:


Generation Options

Hit Ok, and then we can open a browser up and see what we have:


While you're in the browser, add an instance variable - "timer". That will be the actual timer object. Once we have that, we need to go back to the editor, and change back to the script view. We'll now add some methods for #start, #stop, and #timerFired (the latter being the event that happens when our timer goes off):

Script Editor

The code you'll add is below. For each method, select "New Method Template" from the method menu, and then add the code. You can also just add these in the stock browser; either way, they end up in the same place:

Script Editor

	"Perform the start action."

	timer := CwAppContext default
					addTimeout: self length
					receiver: self
					selector: #eventTimerFired:
					clientData: nil.

	"Perform the stop action."
	timer notNil ifTrue: [CwAppContext default
	removeTimeout: timer ].

eventTimerFired: anObject
	"Notify other parts that the timer has expired."

	self signalEvent: #timerFired.
	timer := nil.
	self repeat ifTrue: [self start].

That just about wraps it up - version this off in ENVY so we can continue with it later - you've just created a reusable, non-visual part in VA Smalltalk.


Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

[st4u218-iPhone.m4v ( Size: 8828722 )]

posted by James Robertson

 Share Tweet This