Next: , Previous: Defining Application Frames, Up: The First Application


3.3 A First Attempt

Let us define a very primitive CLIM application. For that, let us put the following code in a file:

     (in-package :common-lisp-user)
     
     (defpackage "APP"
       (:use :clim :clim-lisp)
       (:export "APP-MAIN"))
     
     (in-package :app)
     
     (define-application-frame superapp ()
       ()
       (:panes
         (int :interactor :height 400 :width 600))
       (:layouts
         (default int)))
     
     (defun app-main ()
       (run-frame-top-level (make-application-frame 'superapp)))

As we can see in this example, we have put our application in a separate package, here a package named APP. While not required, putting the application in its own package is good practice.

The package for the application uses two packages: CLIM and CLIM-LISP. The CLIM package is the one that contains all the symbols needed for using CLIM. The CLIM-LISP package replaces the COMMON-LISP package for CLIM applications. It is essentially the same as the COMMON-LISP package as far as the user is concerned.

In our example, we export the symbol that corresponds to the main function to start our application, here called APP-MAIN.

The most important part of the code in our example is the definition of the application-frame. In our example, we have defined an application frame called superapp, which becomes a CLOS class that automatically inherits from some standard CLIM application frame class.

The second argument to define-application-frame is a list of additional superclasses from which you want your application frame to inherit. In our example, this list is empty, which means that our application frame only inherits from the standard CLIM application frame.

The third argument to define-application-frame is a list of CLOS slots to be added to any instance of this kind of application frame. These slots are typically used for holding all application-specific data. The current instance of the application frame will always be the value of the special variable *application-frame*, so that the values of these slots can be accessed. In our example, we do not initially have any further slots.

The rest of the definition of an application frame contains additional elements that CLIM will allow the user to define. In our example, we have two additional (mandatory) elements: :panes and :layouts.

The :panes element defines a collection of CLIM panes that each instance of your application may have. Each pane has a name, a type, and perhaps some options that are used to instantiate that particular type of pane. Here, we have a pane called int of type :interactor with a height of 400 units and a width of 600 units. In McCLIM, the units are initially physical units (number of pixels) of the native windowing system.

The :layouts element defines one or more ways of organizing the panes in a hierarchy. Each layout has a name and a description of a hierarchy. In our example, only one layout, named default, is defined. The layout called default is the one that is used by CLIM at startup. In our example, the corresponding hierarchy is trivial, since it contains only the one element int, which is the name of our only pane.