How Do I ... : Write Smalltalk scripts : Connect scripts and parts to add function : Example: Connect a script to a push button
Example: Connect a script to a push button
Connect scripts and parts to add functionConnect scripts and parts to add functionNo tip for this topicNo example for this topicTest my scriptTest my script
In this example, the user can click on a push button to display a message box. The message box is created by a Smalltalk script accessed through an event-to-script connection.
Event Code Hook sample
Define the user interface shown above, then add a script to the part class:
1. Select Script Editor in the lower-right corner of the Composition Editor to open the Script Editor.
2. Use the Script Editor to write and save the following script:
displayMessage
| messageBox |
messageBox := (CwMessagePrompter new)
title: 'Hey!';
messageString: 'Please do not press that button again.'.
messageBox prompt.
3. Select Composition Editor icon in the lower-right corner of the Script Editor to open the Composition Editor.
4. Click mouse button 2 on the Push Button part to open its pop-up menu. (For UNIX, use mouse button 3.)
5. Select Connect > clicked.
6. Click on the free-form surface; then select Event to Script.
7. In the displayed window, select the displayMessage script and then OK.
The connection appears as a single-headed arrow pointing to an icon representing the script. When the user clicks on the push button, the script connection accesses the displayMessage method, running the script that displays the message box.
Last modified date: 08/09/2019