TOC PREV NEXT INDEX

Getting Started with AVS/Express Developer Edition




10 Building a User Interface


In this chapter, you build a user interface with the User Interface Kit.

In this chapter you:

10.1 Introduction

The User Interface Kit enables you to build sophisticated user interfaces for your applications. A user interface can include windows, dialogs, menu bars, widgets (fields, list boxes, etc.), labels, and common dialogs (file selection dialogs, message dialogs, etc.). Interfaces you build work on both UNIX and Windows systems.

In this chapter, you build a user interface for the Echo Sounding application. The interface enables the user to select a data file and exit the application.

This chapter illustrates:

10.2 Start AVS/Express
n If you are no longer in AVS/Express, start it now with the myproj project.
express -project myproj
bin\pc\express -project myproj

Depending on where you saved myproj, you may need to specify a pathname.

AVS/Express begins and loads your project.

n If you are still in AVS/Express from the last chapter, delete the current application workspace and load a new one.
10.3 Create a Window

Building a user interface

Create a Window
Add a Menu Bar
Add a File-Selection Dialog
Add an Exit Confirmation Dialog
Encapsulate the User Interface in a Macro

In this section, you create the user interface's window.

1. Go to the User Interface library page.
2. Instance UIapp into the DefaultApplication workspace.
UIapp is located in the Containers library.
Figure J-1


AVS/Express executes the object. An empty window appears on the screen. Here is a portion of it:
Figure J-2


3. Move the UIapp window so it is beside the AVS/Express Network Editor.
That way, neither window obscures the other.
4. Open the UIapp object and scroll down to the title parameter.
Figure J-3


5. Open title, then change title's value to the literal "Echo".
Remember to enclose the literal in quotes and to press Enter to apply the change.
Figure J-4


After you press Enter, AVS/Express may insert a connection operator (=>) before the literal. You can ignore it.
Notice that the window has the title you specified:
Figure J-5


(Note that when you instanced UIapp, the title parameter was connected to the expression name_of(<-). This set the window's title to the name of title's parent object, UIapp. That is why when you instanced UIapp, the window's title was also UIapp.)
6. Scroll up and down through UIapp and observe its various parameters.
For example, parameters x, y, width, and height let you specify the window's position and size. The visible parameter determines whether the window appears; it is currently set to 1, meaning that the window is visible.
The documentation for a kit includes a detailed description of each object in the kit. You can also get online help for an object.
7. Select the Help popup command for UIapp.
8. Remove the on-line help window by selecting the Help window's File->Exit pulldown command.
9. Back in the UIapp object, scroll to the visible parameter, open it, and set it
to 0.
Figure J-6


When you press Enter to apply the change, the Echo window disappears.
10. Change visible back to 1.
The window reappears.
11. Close UIapp.
Figure J-7


10.4 Add a Menu Bar

Building a user interface

Create a Window
Add a Menu Bar
Add a File-Selection Dialog
Add an Exit Confirmation Dialog
Encapsulate the User Interface in a Macro

In this section, you add a menu bar to the Echo window. The menu bar includes a File menu with pulldown commands.

Add the Menu Bar Itself
1. Reposition UIapp in the DefaultApplication workspace, such that vertically it is in the center of the workspace and horizontally is somewhat to the right of center.
You will be instancing and connecting several user-interface objects. Positioning UIapp as described will allow all of the objects to fit easily in the workspace.
Later, if you run out of room, you can easily reposition the objects in the workspace. For example, you can lasso and drag the object. Alternatively, you can move the mouse pointer to an unoccupied area of the workspace, then drag the mouse pointer while holding down the Shift key and middle mouse button (on UNIX systems) or right mouse button (in Windows).
2. Instance UIcmdList and connect it to UIapp.
UIcmdList is located in the Menu Bar library.
Figure J-1


The window now has an empty menu bar. (In Windows, a menu bar does not appear until the menu has a menu item.)
Figure J-2


Consider the connection between UIapp and UIcmdList. The purpose of the connection is not to reference UIcmdList's data; UIapp does not need it. But UIapp's update method does need a pointer to the window's menu bar, if any, so it can display the correct one. The connection provides that pointer.

Add a Menu to the Menu Bar
1. Instance another UIcmdList object and connect it to the first UIcmdList object.
Figure J-3


The window's menu bar now has a menu item, which is currently set to UIcmdList#1.
Figure J-4


2. Open UIcmdList#1 and set the label parameter to the literal "File". Be sure to include quotation marks around the name.
Figure J-5


When you press Enter, the window menu's name changes to File.
Figure J-6


3. Close UIcmdList#1.
A menu bar typically contains several menu items, like File, Edit, and Help. Accordingly, you can connect several UIcmdList objects to the menu bar's UIcmdList object.
4. Instance another UIcmdList object and connect it to the menu bar's UIcmdList.
Figure J-7


The window's menu bar now has a second menu item.
Figure J-8


5. Delete UIcmdList#2, the object you just instanced.
To delete the object, select the Delete popup command for it.
6. Rename UIcmdList#1 to UIcmdListFile.
Figure J-9


Add Pulldown Commands to the Menu

The File menu requires Open and Exit commands. You create these, along with a separator that will appear between them.

7. Instance a UIcmd object, a UImenuSeparator object, and another UIcmd object, and arrange them as shown below.
Figure J-10


8. In the order described here, connect UIcmd to UIcmdListFile, then UImenuSeparator to UIcmdListFile, and finally UIcmd#1 to UIcmdListFile.
The order you connect objects to UIcmdListFile determines the order they appear in the menu.
Figure J-11


9. Pull down the Echo window's File menu.
Figure J-12


The commands are currently named UIcmd and UIcmd#1.
10. Open UIcmd, scroll down the see the label parameter, and change it to the literal "Open...".
Press Enter to apply the change, then close UIcmd.
11. Open UIcmd#1, change its label parameter to the literal "Exit...".
Press Enter to apply the change, then close UIcmd#1.
12. Pull down the Echo window's File menu.
The menu now displays the names you assigned.
Figure J-13


13. Rename the UIcmd object to UIcmdOpen. Rename UIcmd#1 to UIcmdExit.
Figure J-14


10.5 Add a File-Selection Dialog

Building a user interface

Create a Window
Add a Menu Bar
Add a File-Selection Dialog
Add an Exit Confirmation Dialog
Encapsulate the User Interface in a Macro

The User Interface Kit includes a wide assortment of common dialogs, such as a dialog for selecting a file or for displaying an error message. To use a common dialog, you simply instance it, set appropriate parameters, and connect it into your application.

In this section, you add a file-selection dialog to your user interface. You then explore how the user interface works.

Add the Dialog
1. Instance UIfileDialog from the Dialogs library and position it next to UIcmdOpen


You connect these objects so that the Open pulldown command in the Echo window brings up a file dialog.
2. Connect UIfileDialog to UIcmdOpen as shown below:
Figure J-1


If you previously tried selecting the Echo window's File`Open pulldown command, the file-selection dialog will now appear. Select the Cancel button to remove it.
You can now test the dialog.
3. In the Echo window, select the File->Open pulldown command.
A file selection dialog appears. Here is the top portion of it:
Figure J-2


Notice that the dialog's name is UIfileDialog. You want to set it to something more meaningful.
4. Select the dialog's Cancel button to remove the dialog.
5. Open UIfileDialog and set the title parameter to "Select a Data File".
To see the entire literal at once as you enter it, you need to widen UIfileDialog. Drag the lower right-hand corner of UIfileDialog's window to the right.
Figure J-3


Remember to enclose the literal in quotes and press Enter to apply the change. You can now see the results.
6. In the Echo window, select the File->Open pulldown command again.
The file-selection dialog appears, with its new title. Select the Cancel button.
Figure J-4


Observe How UIcmdOpen and UIfileDialog Work

In this section, you open UIfileDialog and UIcmdOpen to see how they work.

1. Open UIfileDialog (if you closed it) and scroll so you can see the visible parameter.
2. Open UIcmdOpen and scroll so you can see the do parameter.
Figure J-5


Notice that UIfileDialog.visible is connected to UIcmdOpen.do.
Here is how they work:
  • When you select File->Open in the Echo window, UIcmdOpen's update method executes and sets UIcmdOpen.do to 1. UIfileDialog.visible is connected to the do parameter, so it, too, gets set to 1. This causes UIfileDialog's update method to execute, and it displays the file-selection dialog. (In Windows, if UIcmdOpen.do is already 1 when you select File->Open, AVS/Express increments it to 2, but everything else works the same way.)
  • When you select the Cancel button in the file-selection dialog, UIfileDialog's update method executes. The update method then removes the window and sets UIfileDialog.visible back to 0. Because of the connection, UIcmdOpen.do is also set back to 0. (If you select the OK button, the update method also inserts the filename you selected into UIfileDialog's filename parameter.)
3. Select the File->Open pulldown command from the Echo window, then select the Cancel button in the file-selection dialog.
Observe what happens to UIcmdOpen.do and UIfileDialog.visible.
4. Close UIfileDialog and UIcmdOpen.
10.6 Add an Exit Confirmation Dialog

Building a user interface

Create a Window
Add a Menu Bar
Add a File-Selection Dialog
Add an Exit Confirmation Dialog
Encapsulate the User Interface in a Macro

When a user of your application selects the Exit command, the application should exit, but should first display a confirmation dialog. In this section, you add an exit confirmation dialog to your application's user interface.

1. Instance UImessageDialog and connect it to UICmdExit, thus exporting the input port for the visible parameter. (Use the same procedure as you did for UIfileDialog in steps two and three in the last section, Add the Dialog )
UImessageDialog is located in the Dialogs library.
2. connect UImessageDialog to UIcmdExit, as shown in the diagram below.
Figure J-1


3. Open UImessageDialog and scroll to the ok parameter.
The parameter currently has no value.
Figure J-2


4. In the Echo window, select the File->Exit pulldown command.
A message dialog appears.
Figure J-3


Notice that the dialog currently does not have a meaningful title and has no descriptive message. You will add these soon. First, observe what happens when you select the OK button.
5. Select the OK button.
The dialog is removed and the ok parameter gets set to 1.
Figure J-4


In the next chapter, you will connect the output of ok to a module that exits AVS/Express. In preparation, you will now export a port for ok.
6. Add an output port for the ok parameter, then export the port.
To add an output port, select the ok parameter and the select the Add Output Port popup command.
A port is added to the right side of the parameter:


To export the port, move the mouse pointer directly over the output port, then select the Export Port pop-up command as shown below.
Figure J-5


The port now extends to the outside of the module.
Figure J-6


Next, add a meaningful title and message.
7. Scroll to the title parameter, open it, and change its value to the literal "Exit?"
Figure J-7


Remember to enclose the literal in quotes and press Enter.
8. In UImessageDialog, scroll to the message parameter and change its value to the literal "Are you sure you want to exit?".
You have to widen UImessageDialog to see the whole literal as you are typing it.
Figure J-8


You can now see the results.
9. In the Echo window, select the File`Exit pulldown command.
The message window reflects your changes to the title and message parameters.
Figure J-9


10. Select the OK or Cancel button to remove the dialog.
11. Close UImessageDialog.
Notice that UImessageDialog now displays the output port for the ok parameter.
Figure J-10


Remember you can always determine which parameter is accessible through a port by selecting the Info popup command for an object.
Add an exit_process Module

AVS/Express supplies a set of general-purpose modules for doing handy things like creating execution loops and timers. One of the general-purpose modules is called exit_process. As its name suggests, exit_process exits the express process. You want to connect this object to your application, but you want to make sure it does not inadvertently execute.

In the previous section, if you had tried the Echo window's File`Exit command and had selected the OK button in the message box, UImessageDialog's ok parameter would have been set to 1. If you then connected exit_process to EchoUI, exit_process would execute immediately, causing AVS/Express to exit.

In this section, you add exit_process to your application. But first you make sure it is safe to do so.

1. Reposition UImessageDialog so that it is below UIcmdExit.
This will result in cleaner connection lines.
2. Open UImessageDialog.
You open a group object by double-clicking on it or by selecting the Open popup command.
3. Scroll to the ok parameter and verify that its value is either null or 0.
The value appears next to the parameter's name. A null value appears as a question mark.
4. If the value is not null or 0, open the object, assign the value 0, then close the object.
5. Close UImessageDialog.
You are now ready to add exit_process. It is located in the GMOD library on the Templates library page. But what if you did not know where it was located? The instructions below show you how to find the object using the Object Finder.
6. In the Network Editor, select Object->Find in All Libraries.
The Object Finder appears. Here is the top portion of it:
Figure J-11


7. In the Search Pattern field, enter the name of the object you are seeking.
The object's name is exit_process (you can type a space instead of the underscore). Do not use quotes.
Figure J-12


8. Select the Find button.
AVS/Express searches for all occurrences of the specified object. It finds one, which it displays in the Objects list box. For Developer Users, the listing tells you that exit_process is located on the Templates library page, in the GMOD library.
Figure J-13


9. Select the Show button.
AVS/Express displays and open the appropriate library page and library, and highlights exit_process.
Figure J-14


10. In the Object Finder dialog, select the Cancel button.
11. Instance exit_process and connect it to EchoUI, as shown in the diagram below.
Figure J-15


Continue on to the next section to save this user interface in a macro. But first, notice the technique you have used to construct a user interface:

This is the same technique you use for other groups of objects in other libraries.

10.7 Encapsulate the User Interface in a Macro

Building a user interface

Create a Window
Add a Menu Bar
Add a File-Selection Dialog
Add an Exit Confirmation Dialog
Encapsulate the User Interface in a Macro

A macro is one of AVS/Express' standard objects. You use a macro to encapsulate a network of connected objects.

In this section, you encapsulate the user interface you just built into a macro.

Move the Network into a Macro
1. Go to the Standard Objects library page.
2. Instance macro into the DefaultApplication workspace.
macro is located in the Macros library.
Notice that macro is in the open state, enabling you to move objects into it.
Figure J-1


3. Select all of the objects in the user interface.
One way to select multiple objects is to select one, then Shift-select the others (that is, hold down the Shift key while selecting the other objects).
Another way is to use a lasso. Move the mouse pointer to just above UIfileDialog. Then drag the mouse pointer down and to the right to create a rectangular region called a lasso. The lasso should fully or partially surround all of the objects you intend to select. Then release the mouse button.
The Network Editor highlights the selected objects in blue. All of the objects in the workspace, except for macro, should be highlighted in blue.
4. Drag the selected objects into the macro.
To drag the objects, move the mouse pointer to one of the selected objects, then drag the pointer into the macro. When the macro turns pink, you can release the mouse pointer.
Moving objects from one container object (in this case, DefaultApplication) to another is called reparenting. The objects now have a new parent object, the macro.
Figure J-2


You will soon maximize the macro to view and reposition its subobjects. First, though, you rename the macro.
5. Select the macro object and use the Rename popup command to change its name to EchoUI.
Figure J-3


6. Maximize EchoUI.
To maximize the object, move the mouse pointer to EchoUI's title bar and select the Maximize popup command.
EchoUI now occupies the entire workspace. The title bar reads DefaultApplication.EchoUI, indicating that you are viewing the EchoUI object, located in DefaultApplication.
Many of the objects are probably not visible in the workspace.
7. Move the objects in EchoUI so they are all visible.
To move all of EchoUI's objects, including objects you cannot currently see, position the mouse pointer in an unoccupied area inside EchoUI. Then drag the mouse pointer while holding down the shift key and middle mouse button (on UNIX systems) or right mouse button (in Windows)
You should now be able to see all of EchoUI's objects.
Figure J-4


Export the File Dialog Port

You can export ports out of a macro, in much the same way as you can for a module or group object. Exporting an object's ports allows you to connect the object to other objects in your application, which you will do in the next chapter.

8. Export UIfileDialog's output port and to the outside of the EchoUI macro. This makes the filename parameter, a string containing the filename selected in the file dialog, accessible to other object outside the macro.
You can export the port in either of two ways:
  • Move the mouse pointer to the port, then select the Export Port popup command.
  • Draw a connection line from the port to the top or bottom of the macro. For an input port, you draw the connection line to the top of the macro. For an output port, you draw the connection line to the bottom.
The diagram below shows the result. (Note that the height of the AVS/Express window has been reduced in order that the screen shot you see takes up less space. You do not have to reduce the height of your AVS/Express window.)
Figure J-5


9. Close EchoUI.
Move the mouse pointer to EchoUI's title bar, then either double-click or select the Close popup command.
Figure J-6


Save EchoUI as a Template
1. Go to the Library Workspaces page.
2. Drag EchoUI from the DefaultApplication workspace to Workspace 1.
Figure J-7


3. Save your project.
Select Project->Save.

This completes the tutorial.

n Either stay in AVS/Express and continue to the next tutorial, or exit AVS/Express by selecting File->Exit.
10.8 For More Information

TOC PREV NEXT INDEX