[Top] [Prev] [Next] [Bottom]
Tk - graphics toolkit module
include "tk.m";
tk:= load Tk Tk->PATH;
Tki: type ref Draw->Image;
Toplevel: adt
{
id: int;
image: Tki;
};
toplevel: fn(screen: ref Draw->Screen, arg: string)
: ref Toplevel;
intop: fn(screen: ref Draw->Screen, x, y: int)
: ref Toplevel;
namechan: fn(t: ref Toplevel, c: chan of string, n: string)
: string;
cmd: fn(t: ref Toplevel, arg: string): string;
mouse: fn(screen: ref Draw->Screen, x, y, button: int);
keyboard: fn(screen: ref Draw->Screen, key: int);
imageput: fn(t: ref Toplevel, name: string, i, m: Tki)
: string;
imageget: fn(t: ref Toplevel, name: string)
: (Tki, Tki, string);
Description
The Tk module provides primitives for building user interfaces, based on Ousterhout's Tcl/Tk. The interface to the toolkit itself is primarily the passing of strings to and from the elements of the toolkit using the cmd function.
toplevel
toplevel: fn(screen: ref Draw->Screen, arg: string)
: ref Toplevel;
## returns nil on error.
The toplevel function, given an existing Screen (usually one inherited from the graphics Context; see Context - graphics environment in Chapter 11), creates a new window, called a Toplevel, under the control of the Limbo/Tk toolkit. The Toplevel is passed to the cmd and namechan functions to drive the widgets in the window. The arg parameter is a string containing creation options (such as -borderwidth 2) that are applied when creating the toplevel window.
cmd
cmd: fn(t: ref Toplevel, arg: string): string;
## returns string result from Limbo/Tk command.
The cmd function passes command strings to the widgets in the Toplevel t and returns the string resulting from their execution. For example, given a canvas .c in the Toplevel t,
x:= int tk->cmd (t, ".c cget -actx");
returns the integer x coordinate of the canvas.
namechan
namechan: fn(t: ref Toplevel, c: chan of string, n: string)
: string;
## returns empty string on success; error message on
failure.
Bindings can be created in a Toplevel that trigger strings to be sent on Limbo channels. Such channels must be declared to the Tk module using namechan. The following example creates a button that sends the word Ouch when it is pressed:
hitchannel:= chan of string;
tk->namechan(t, hitchannel, "channel");
tk->cmd(t, "button.b.Hit -text Hit -command {send channel
Ouch}");
expl:= <-hitchannel; # will see "Ouch" when button pressed
mouse and keyboard
mouse: fn(screen: ref Draw->Screen, x, y, button: int);
keyboard: fn(screen: ref Draw->Screen, key: int);
The mouse and keyboard functions deliver mouse and keyboard events to Limbo/Tk for delivery to widgets. They are usually called only by the Window Manager.
Caveat
Because Limbo/Tk input is handled globally, there can be only one instance of a Limbo/Tk implementation on a given machine or a given emulator.
See Also
-
Context - graphics environment in Chapter 11
-
wmlib - window manager toolkit in Chapter 15
-
John K. Ousterhout, Tcl and the Tk Toolkit, Addison-Wesley Publishing Company, Reading, Massachusetts, 1994.
-
[Top] [Prev] [Next] [Bottom]
infernosupport@lucent.com
Copyright © 1997, Lucent Technologies, Inc.. All rights
reserved.