Objective-Everything Release 5.  Copyright ©1994-1998 by TipTop Software, Inc.  All Rights Reserved.

Using Objective-Everything with InterfaceBuilder

ObjPalette provides a number of high-level objects and introduces a few programming patterns valuable for rapid, interactive application prototyping and developent.

ObjPalette

Objects in ObjPalette

Window Interactor


Editing Window Interactor


Nib Implementation


Object Well


NSMutableDictionary


Objective-Python Interpreter

Objective-Tcl Interpreter

Objective-Perl Interpreter

Objective-WebScript Interpreter

When ObjPalette is loaded, the Objective submenu appears between the "Tools" and "Window" menu items. From this menu, you can run any Objective language interactor, run Objective-Browser, etc.

Multiple interpreter instances

To include an interpreter in your application, simply drag an icon representing a language interpreter from ObjPalette, and drop it in the object suitcase. The language framework is dynamically loaded if needed.

If a language supports multiple interpreters (e.g., like Tcl), you can specify whether the interpreter object in the suitcase represents the (shared) default language interpreter, or it is a distinct interpreter instance. Each distinct interpreter instance represents a separate execution context, with its own stack frame, global variables, and procedures.

Connecting globals

To tie an object so that it is known in an interpreter as a global variable, simply Ctr-Drag from the interpreter instance in the object suitcase to the object, and type in the object name.

Hooking Globals

If the language supports namespaces, you can use a namespace qualifier in the global name.

Example:

Create a new application in Interface builder. Drop a button into the window. Drop an ObjPy interpreter into the object suitcase. Ctrl-Drag from the ObjPy interpreter to the button. Type "but".

Add another button. Change its title to "Interactor". Ctrl-Drag from the button to the interpreter object and connect action "newWInteractor:".

Run the application (Document->TestInterface or Cmd-r). Click the Interactor button. Type:

py% but
<NSButton: 0x...>
py% but.setTitle('Foo')

The button title changes.

Connecting XVars in InterfaceBuilder

When ObjPalette is loaded in InterfaceBuilder, you can hook xvars of an object to any destination object using the XVar connection inspector. XVar are an extension to the OpenStep object model which allows you to associate arbitrary object values with any object.

Note that, by default, InterfaceBuilder shows its own connection inspector. To make InterfaceBuilder show the XVar connection inspector do:

If the default "Connections" inspector is already selected:

Note that xvars retain their target, so it is really easy to creeate cycles.

NOTE: If you are using EO palette, make sure that it is loaded before ObjPalette. Otherwise, ObjPalette will not be able to set up connection inspectors properly.

Instant Implementation

Objective-Everything extends the InterfaceBuilder capabilites with the ability to instantly implement methods and extend functionality of any object directly in InterfaceBuilder.

This functionality facilitates rapid prototyping and development.

There are three different ways to do this: using interpreter startup code, nib implementation object, or extending an object directly.

For each of these, we will demonstrate how to associate a simple action with a button in a window so that when clicked, an alert panel is displayed:

We will start each of the examples as a new application Document->NewApplication (Cmd-n). Then drag a button into the application window.

Interpreter Startup Code

You can include arbitrary programming code with an interpreter instance in a nib file. This code will be executed when the nib file is loaded into a running application.

Example

Create a new application (Cmd-n) and drag a button into the application window as described above. Drag the ObjTcl interpreter from ObjPalette and drop it into the object suitcase. Ctrl-Drag from the interpreter object to the button. Type "button" and hit return. This associates the button with the global variable "button" in the interpreter.

Double click "button" connection in the connection inspector. Confirm that you want to create action implementation. In the code editor window that appears, implement button extension as follows:

objtcl::log "Extending $button"

extend $button {
  method -(void)action:(id)sender {
    NSRunAlertPanel "Foo" "Hello World!" [nil] [nil] [nil]
  }
}

Now, test the application Document->TestInterface (Cmd-r), and click the button. The alert panel should appear.

Note: Extending objects in interpreter startup code is not supported for WebScript.

NibImplementation Object

The NibImplementation object lets you include any arbitrary implementation code in a nib file.

Example

Create a new application (Cmd-n) and drag a button into the application window as described above. Drag-and-drop the nib implementation object from ObjPalette into the object suitcase. Switch to the implementation inspector (Cmd-6). Select Tcl as the implementation language. Click the "+" button, and implement the action as follows:

objtcl::log "Extending $self"

extend $self {
  method -(void)action:(id)sender {
    NSRunAlertPanel "Foo" "Hello World!" [nil] [nil] [nil]
  }
}

Ctrl-Drag from the button to the NibImplementation object, and hook it so that the button invokes "action:" of the NibImplementation object.

Now, test the application Document->TestInterface (Cmd-r), and click the button. The alert panel should appear.

In addition to editing code in the Implementation inspector, you can also double-click on an implementation object to bring up a code editor window.

You can also directly hook an implementation object to a specific interpreter instance via its "interp" outlet. This way, the implementation will be evaluated in the specified interpreter.

If you don't specify implementation language, your favorite language (from Preferences) is assumed.

Extending Any Object

Create a new application (Cmd-n) and drag a button into the application window as described above. Select the button in the application window (click on it), and bring up the Implementation inspector (cmd-6). Select "Tcl" and click the "+" button and implement button action as follows:

objtcl::log "Extending $self"

extend $self {
  method -(void)action:(id)sender {
    NSRunAlertPanel "Foo" "Hello World!" [nil] [nil] [nil]
  }
}

Now, test the application Document->TestInterface (Cmd-r), and click the button. The alert panel should appear.

Implementation Inspector and Code Editor

Implementation inspector lets you select implementation language and edit implementation code.

You can change the object's name inside the nib file. This is important becuase when you save a nib file, the implementaiton code is stored as a file inside the nib file wrapper. The file name will be the object name with an appropriate file extension for the language.

The "+" button adds a method template. Make sure that you edit the method prototype.

If you want to remove an implementation, simply remove all the code.

To see all of the objects with implementations, switch to the Implementation inspector (Cmd-6) and make empty selection (click into the empty space in the object suitcase), or make a multiple selection.

Code editor can be used for editing NibImplementation code and interpreter object startup code.

Expert topics

Interactors:
Default interpreter, specific interpreter, remote interpreter

At runtime, you can create interactors by sending -newWInteractor: and -newEditWInteractor: to interpreter instances.

Alternatively, you can drop an interactor instance into the object suitcase. Send interactor -run: message to run it.

To hook interactor to a specific interpreter instance, use the connection inspector and hook its "interp" outlet to an interpreter.
If you don't hook it to a specific interpreter, you can select a language in the "Attribute" inspector. In this case, the interactor will execute commands in the default interpreter for the selected language.
If you don't specify a language, you will get a panel in which you can select a language when the interactor runs.

Interactors can also be remote. In the "Attribute" window, you can specify a remote connection name, an interpreter name in that connection, and a remote host name to connect to. See the Remote Access, Vending Objects section for more info.

ObjectWell

See the Remote Access, Object Well section.

NSMutableDictionary

NSMutableDictionary object is included in ObjPalette. It allows you to hook arbitrary objects in a nib file to dictionary string keys. I.e., the dictionary object facilitates a name space.

Running nib files

You use nib files which contain Objective-Everything objects just like you use any other nib files. Note that you normally want to link your project with ObjCore and ObjAppKit frameworks. Note however that if a nib file references any Objective languages that are not loaded, they will be dynamically loaded as needed.

You can also run a nib file from command shell directly. E.g., using ObjTcl do:

objtclsh
appkit::run -nib <path-to-your-nib-file>

[previous][contents][next]