NextPrevUpTopContentsIndex

16.5.4.1 Example

This example takes you through the process of creating an object, examining its contents, and then modifying the object.

  1. Create a button as follows:
  2. (setq button1 (make-instance 'capi:button))
  3. Choose Values > Inspect in the Listener to inspect the button in the Inspector.
  4. In the Listener, use the CAPI accessor button-enabled to find out whether button1 is enabled.
  5. (capi:button-enabled button1)

    This returns t . So we see buttons are enabled by default. The next step is to destructively modify button1 so that it is not enabled.

  6. Choose Works > Tools > Preferences... in the Inspector.
  7. The Inspector Preferences dialog appears, so that you can change the current package of the Inspector.

  8. In the Package box, replace the default package name with CAPI and click OK .
  9. This changes the process package of the Inspector to the CAPI package, and the package name disappears from all the slots listed. This makes the display a lot easier to read.

  10. In the Inspector, type enabled into the Filter box.
  11. Button objects have a large number of slots, and so it is easier to filter out the slots that you do not want to see than to search through the whole list. After applying the filter, only one slot is listed.

  12. Select the slot enabled .
  13. Choose Slots > Set...
  14. A dialog appears into which you can type a new value for the slot enabled .

    Figure 16.5 Entering a new slot value

  15. Note that previously entered forms are available via a dropdown in this dialog. Enter nil (or select it from the history) and click on OK .
  16. The attributes and values area shows the new value of the enabled slot.

  17. Click on the
  18. button. This removes the filter and displays all the slots once again.
  19. To confirm that the change happened, type the following in the Listener. You should be able to recall the last command using Alt+P or History > Previous .
  20. (capi:button-enabled button1)

    This now returns nil , as expected.

    The next part of this example shows you how you can modify the slots of an object by pasting in the contents of the clipboard. This example shows you how to modify the text and font of button1 .

  21. Type the following into the Listener and then press Return :
  22. "Hello World!"
  23. Choose Values > Copy to copy the string to the clipboard.
  24. Select the TEXT slot of button1 in the Inspector.
  25. Choose Slots > Paste to paste the "Hello World!" string into the text slot of button1 .
  26. This sets the text slot of button1 to the string.

  27. Enter the following into the Listener and press Return :
  28. (let ((font (capi:simple-pane-font button1)))
      (if font 
          (gp:find-best-font 
           button1 
           (apply 'gp:make-font-description 
                  (append (list :size 30) 
                          (gp:font-description-attributes 
                           (gp:font-description 
                            (capi:simple-pane-font button1))))))
        (gp:make-font-description :size 30)))

    This form simply calculates a large font object suitable for the button object.

  29. Choose Values > Copy to copy the font to the clipboard.
  30. Select the FONT slot of button1 in the Inspector.
  31. Choose Slots > Paste to paste the font into the font slot of button1 .
  32. Confirm the effect of these changes by displaying the button object. To do this, choose Object > Listen .
  33. This transfers the button object back into the Listener. As feedback, the string representation of the object is printed in the Listener above the current prompt. The object is automatically transferred to the * variable so that it can be operated on.

  34. In the Listener, type the following:
(capi:contain *)

This displays a window containing the button object. Note that the text now reads "Hello World!", as you would expect, and that the font size is larger than the default size size for buttons. Note further that you cannot click on the button; it is not enabled. This is because you modified the setting of the enabled slot in the earlier part of this example.


Common LispWorks User Guide (Unix version) - 21 Feb 2008

NextPrevUpTopContentsIndex