links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Prompting the user
Last updated at 1:49 pm UTC on 16 January 2006
There are many ways for an application to prompt the user for information. Below, in no particular order, are a set of these. The list is probably not complete, since I now and then find a new item to add, but certainly covers most of the possibilities.

Copy all the code below in a Workspace and evaluate it statement by statement. Do a 'print-it' to see the results. This gives you an idea what's happening.
Comments in Squeak are in double quotes...like this: "This is a comment.
A comment might span
many lines before ending"
To make the comments more obvious, I've put them in italic. Browse on all examples

Selection Menu
SelectionMenu confirm: 'Are you hungry?' 
	"Shows a menu with the string as a title, and choices of 'Yes' and 'No'. 
	Answers true or false".

SelectionMenu confirm: 'Are you hungry?' 
		trueChoice: 'yes, I''m famished' 
		falseChoice: 'no, I just ate'
	"Like the previous example but lets you change the names of the Yes/No options."

aMenu := SelectionMenu 
	labelList: #( 'Dog' 'Cat' 'Bird' 'Horse' )
	selections: #( 'Fido' 'Slinky' 'Tweetie' 'Herman' ).
aMenu startUpWithCaption: 'Pick One'
	"Shows a menu with a caption of 'Pick One' and menu items from label list. 
	Answers the item from selections that corresponds to the item. 
	(Click Horse and it answers Herman)."

aMenu := SelectionMenu 
		labelList: #( 'Dog' 'Cat' 'Bird' 'Horse' )
		lines: #( 2 )  "optional"
		selections: #( 'Fido' 'Slinky' 'Tweetie' 'Herman' ).
aMenu startUpWithCaption: 'Pick One'
	"As above but puts a line after menu item 2."

Self confirm:
self confirm: 'Having Fun Yet?'
	"Shows a menu with the string as a title, and choices of 'Yes' and 'No'. 
	Answers true or false."

self confirm: 'Having Fun Yet?' orCancel: [ 'Sometimes' ]
	"Shows a menu with the string as a title, and choices of 'Yes', 'No', and 'Cancel''. 
	Answers true, false, or the result of the block."

(PopUpMenu labelArray: #('frog' 'and' 'toad') lines: #( ) ) startUp
	"Popup a menu with the given labels; answer the number of the menu item. 
	('frog' is 1, ...)"

(PopUpMenu labels: 'frog and toad') startUp
	"As above. Line breaks become menu item separators."

(PopUpMenu labels: 'frog and toad' lines: #(2)) startUp
	"As above but put a line after menu item 2."

PopUpMenu notify: 'You have been notified!'
	"Puts up a menu with the string as a title and one choice: 'OK'. 
	Answers nothing of interest."

Prompting the user

	request: 'What is your favorite color?'
	initialAnswer: 'red, no blue. Ahhh!'

	multiLineRequest: 'Enter one or more lines; end input by accepting or canceling or typing the enter key'
	centerAt: Display boundingBox center
	initialAnswer: 'bozo!'
	answerHeight: 100
	"The title has more than one line; line breaks are taken from multiLineRequest:."

"EmphasizedMenu does textual emphasis on the menu items."

		selections: #('how' 'well' 'does'   'this'   'work?') 
		emphases: #(bold   plain  italic struckOut plain))

		selections: #('how' 'well' 'does'   'this'   'work?') 
		emphases: #(bold   plain  italic struckOut plain))
	startUpWithCaption: 'A Menu with Emphases'

Menus perform:orSendTo:

	informUser: 'Just a sec!' 
	during: [(Delay forSeconds: 1) wait]
	"Put up a one line message that persists as long as the block runs.  When the block terminates the message disappears."

Utilities informUserDuring:[ :menu |
		#(one two three) do:[:info|
			 menu value: info.
			(Delay forSeconds: 1) wait]]
	"Put up a one line message that changes as a block progresses through its steps. 
	This example simply changes the text after each step."

String (Progress)
'Now here''s some Real Progress' "Note the '' to show ' in here's"
		displayProgressAt: Sensor cursorPoint
		from: 0 to: 10
		during: [:bar |
			1 to: 10 do: [:x | 
				bar value: x.
				(Delay forMilliseconds: 500) wait]].
	"Display a message and a progress bar. The progress bar stays up during 
	the execution of the block. Note that the range (from:to:) must be known 
	ahead of time and must match the number of steps inside the block. 
	(There are many examples in the image.)"

Providing notifications to the user
self notify: 'a notify message'.
	"Starts a notifier window with the message.  Allows you to proceed or start the debugger."

self inform: 'an inform message'.
	"A pop up gives the message, with a button to click to proceed."