CanDo: An Interactive Authoring Tool, Part 8 -- AppEvents and Graphics Printing

by Randy Finch

While trying to decide what type of program to write for this month's topic, I realized there is a program I have been needing for some time that would be perfect. I can use the program every time I write an installment for this CanDo series.

I create the figures for my articles using DeluxePaint. Once I have all of the figures on disk, I like to view them in slide show fashion to check for mistakes before printing them. This is just begging for a custom Workbench utility program, and CanDo is up to the job. The program is entitled PrintPics.

The Program Design

The user interface for PrintPics is shown in the upper-left corner of Figure 1. The program allows multiple icons representing IFF graphics files, such as those in the CDoVHelm window in the lower-right corner of Figure 1, to be selected and dragged to the interface window. The selected filenames are then displayed in the List object. The View button activates a slide show of the pictures. The Print button is used to print the pictures to the current Preferences printer. The Quit button allows the user to exit the program. Finally, the long button at the bottom of the interface window executes the PrinterGfx program in the Prefs directory (Figure 2). This allows the user to quickly change the printer's graphics settings before printing the files.

PrintPics consists of two cards. One is named WBInterface. It is the user interface described above. The other card is named Picture and is used for displaying the picture files while viewing or printing.

The User Interface Card

The first thing that must be done when creating the PrintPics deck is to change the name of CanDo's default blank card to WBInterface. The window type of this card must then be changed to Workbench. This can be done by bringing up the Window/Editor requester from the Main Control Panel as shown in Figure 3. There are several things that must be done within this requester.

  1. Change the title to "View/Print Pictures".
  2. In the section labeled "Open the window onto...", select "the Workbench screen."
  3. Select the Object button in the Attributes section and make sure all five objects are checked. These include Close Button, Depth Button, Drag Bar, Size Button, and Visible Borders.
  4. Select the Available Modes button in the Normal Window section and make sure the number of colors is set to a number that is less than or equal to the number of colors on your Workbench screen. I use a four-color Workbench so that is what I have selected. If you have eight or more colors, you can use a larger number of colors. If the number of colors selected is larger than what is available on the Workbench, the window will not appear on the Workbench, but will remain on its own custom screen. The size and position of the window can also be set at this time; however, since the window has a drag bar and a sizing button, these parameters can be set by moving and sizing the window on the Workbench. (IMPORTANT NOTE: The position can be changed while in Design mode whereas the size can only be changed while in Browse mode. Beware that for some strange reason, if you open the Window/Editor requester and then select the Cancel button, CanDo will not allow the size of the window to be changed even in Browse mode. To correct the problem, open the Window/Editor requester again and select the Ok button. The window can then be re-sized in Browse mode.)
  5. Click on the AppEvent button in the Scripts section and add the script that is shown in Listing 1 for the WBInterface card's OnAppEvent event. OnAppEvent is activated when the user drags icons from another window on the Workbench to the WBInterface card.

The OnAppEvent script added in the last step simply creates a document named AppEventList and puts the contents of Arg1 into it. When an AppEvent occurs within a CanDo program, the list of filenames associated with the icons that were moved into the window is assigned to the system variable Arg1. Each filename is separated by a line feed character (ASCII 10). By typing Arg1 into the document, the latter will contain all the selected filenames, one per line. Document AppEventList is associated with the List object on the WBInterface card. Thus, whenever the document is updated, the filenames in the List object update also.

The User Interface Objects

The WBInterface card contains five objects: a List object and four TextButton objects. The List object, named AppEvents, is simply used to display the names of the files to be viewed and/or printed. Therefore, it has no scripts associated with it. As mentioned earlier, the document associated with this object is named AppEventList.

The first TextButton is named View and is used to activate a slide show of the files listed in the AppEvents object. The second TextButton is named Print and is used to print the files listed in the AppEvents object. The third TextButton is named Quit and is used to exit the program. The fourth TextButton is named PrintSettings and is used for changing the printer's graphics preferences. Each of these four buttons have an OnRelease event script that executes when the button is selected.

The OnRelease script for the View button assigns the string "View" to the variable named Command, moves the cursor to the start of the current document (AppEventList), and then goes to the card, Picture. The OnRelease script for the Print button is exactly the same except the variable, Command, is equated to the string "Print". The script for the Quit button simply executes the Quit command. The script for the PrintSettings button executes CanDo's Dos command with the string "SYS:Prefs/PrinterGfx" as its argument. This tells CanDo to execute the program named PrinterGfx in the SYS:Prefs directory. This program is included with AmigaDOS. It allows the user to change various graphics settings for the currently selected printer.

The Picture Card

The Picture card can be initialized at design time to any resolution because it will be changing based on the resolution of the pictures being displayed. The Window/Editor should be used to turn off all available objects via the Objects button in the Attributes section. These objects can interfere with the display of the picture files.

When the View or Print button is pressed on the WBInterface card, its OnRelease event script activates. Each script activates the Picture card after assigning a value to the variable, Command, and moving the cursor to the top of the AppEventList document. When the Picture card is activated, its AfterAttachment script executes after the card is displayed.

Following through the AfterAttachment script in Listing 1, the first thing that occurs is that the variable, TheLine, is compared to a null string. TheLine is the string in the current line of the current document. If this string is not null, meaning that at least one file has been dragged to the WBInterface card, the ShowPicture command is executed with TheLine as an argument. The ShowPicture command loads the file specified by its argument and associates it with the current card, Picture. It does not matter if the file contains a picture of a different resolution or depth than the Picture card, CanDo will automatically change the card's resolution to match the file. The ScreenTo FRONT command then displays the picture.

Next, the script determines which button the user pressed by looking at the contents of the variable, Command. If this variable is equal to "View", then the script pauses for five seconds, otherwise (the only alternative is "Print") the PrintWindow command is executed. This command prints the current window to the user's Preferences printer using the current graphics settings. After either pausing or printing, the current document's cursor is moved down one line, which places it on the next filename in the list, and the script is exited.

Once the AfterAttachment script finishes execution, the one and only object on the Picture card activates. The object is a timer set to go off after zero seconds. Therefore, its Occurred script executes immediately. This script checks to see if TheLine is null. If it is, there are no more files in the list to view or print, so the program goes to the WBInterface card to await more user input. If TheLine is not null, the Picture card is activated again causing its AfterAttachment script to execute again. The Timer object, named Timer_1, must be used because the GotoCard command cannot be issued from within an AfterAttachment script.

Some of you may be wondering why I didn't just pass the list of filenames from the OnAppEvent script to the Picture card by using Arg1 as an argument and then creating a loop within the AfterAttachment script to display each picture in turn. Good idea! I tried it. It doesn't work. The first picture displays fine, but when a picture that is not the same resolution as the first is encountered, it does not display properly. It will appear using the resolution of the first picture. Thus, if the first picture is high resolution interlaced, a subsequent picture that is high resolution non-interlaced will be squashed vertically. This bug was verified by a technical support person at INOVAtronics. They plan to correct this problem in a future release. As an interim work-around, the Picture card must be activated between each picture. This reinitialization allows the card's resolution to be changed via the ShowPicture command.

The Home Stretch

Well, that was short and sweet. I like programs that are useful yet do not require too much effort to develop. Do you have any utilities created with CanDo? If so, I would like to see them. You can write me care of this magazine.


Back to list of articles
Back to Randy Finch's Home Page
Last modified on April 1, 1996
Randy Finch at webmaster@rcfinch.com