Home Page ] [ Eiffel Archive ] [ Eiffel Classes and Clusters ]

Arc de Triomphe clipart (2486 bytes)Tcl/Tk Interface


Written by Roy Phillips.

gweld-tclk.zip (108,631 bytes)


GWELD-TCLTK

Graphical Widget Eiffel Library D

This cluster provides an interface to the Tcl/Tk interpreter & library. It is intended to give access to all TCl/Tk features (widgets and their options) from Eiffel, without the need to create Tcl-specific strings in the Eiffel code.

This is an implementation layer for Gweld.

The main interface class is TCL, which implements three interesting features:

start -- initialise interpreter

evaluate (command: STRING) -- have the interpreter evaluate `command'

process -- enter the interpreter's event-loop (i.e., start handling events on the elements created

Class TCL_ELEMENT is the ancestor of all display elements that may be created


Description

Gweld-TclTk is an Eiffel widget library, providing an intuitive and easy to use interface, and reasonable defaults for most options, yet making use of sophisticated options easy.

The Gweld-TclTk library packages Tcl/Tk as Eiffel classes, and is intended to provide an implementation for a generic widget (Gweld) library that could be re-wired to use other, native, services, in a more accessible manner.

The philosophy behind Gweld is to concentrate on the purpose of a widget/control and not on its physical implementation. It is intended that widgets that have certain characteristic should be able to be swapped with each other: for example, a field for a number could be replaced with a spin-button, provided the interface and contract remains unchanged. With this in mind, Gweld-TclTk tries to implement an interface to Tcl/Tk that reflects the structure of Tcl/Tk, leaving it up to Gweld to make the interface simpler and to provide more advanced features (such as auto-layout).

How Gweld-TclTk works

To program the Tcl/Tk environment, Gweld-TclTk generates textual commands and sends them to the interpreter. Communications of values is achieved by creating variables in the interpreter’s namespace, and setting or querying them. Fields have a variable associated with them, enabling edited values to be accessed. Widgets that instigate commands can be set to call back into the Eiffel system.

Tcl/Tk extension libraries are used to provide more sophisticated widgets, such as Notebooks, Combo-boxes etc. (Tix)

Execution Modes

Whilst developing the library, code has been executed by piping it to a Wish shell. This facilitates debugging and comparing results of changes (the resulting Tcl/Tk script can be stored and examined). It can also (would normally) be used in a compiled mode, where commands are passed directly to a linked-in interpreter (code for this inspired by Bill Foote’s mini-case tool).

Future Directions

Although currently using Tcl/Tk, it is the author’s intent to provide a AWT and/or a JFC implementation, to enable Eiffel apps. to interface to a JVM-flavored world, just as soon as I get a compiled version of ‘compile_to_java’ compiled, that is.

Compiler and Tcl/Tk Versions

The version of the library here hasn’t been updated in a year, and previously ran under Linux with SmallEiffel version (-.86) and Tcl4.2, it also worked with ISE EiffelBench version 4.0, provided some list classes were swapped around. It needs updating to Tcl/Tk 8.0 and SmallEiffel version -0.83

Structure of directories

Gweld

Clib
C interface and libraries
docs
Documentation
examples
Example: file browser
images
Images used in example and test code
tcl
Tcl classes
test
Various test harnesses
tix
Widget classes specific to the TIX extensions
tk
TkClasses

Source Code License Terms

Source code is Freeware: no terms, no conditions, no warranty, no problems

Required libraries

Tcl/Tk 8.0

http://sunscript.sun.com/TclTkCore/8.0.html

Tix – for Tix-based Widgets

http://www.xpi.com/download/binaries.html

Class Diagrams

Figure 1. TCL and TK_WIDGETS

Figure 2. OPTIONS, MEASURE and FIGURE

Figure 3. WIDGETS

Examples

class T_TCLTK

creation
   make

feature

   panel: T_PANEL

   tcl: TCL

   make is
      do
      !!tcl.make
      !!panel.build ( tcl)
      tcl.run
   end -- make

end -- class T_TCLTK

The class T_TCLTK, creates a Tcl interpreter (TCL), passing it to the creation routine of a test panel (T_PANEL). Finally, it calls run to start the interpreter’s event-processing loop.

class T_PANEL

inherit
   TK_FRAME

creation
   build

feature

   menu: T_MENUBOX
   tools: T_BUTTON_BAR
   buttons2: T_2BUTTONS

   build ( tcl: TCL) is
      do
         make ( tcl, "main")
         init ( tcl)
      end -- build

   frame2: TK_FRAME
   label: TK_LABEL
   scale: TK_SCALE

   dir_frame: TK_FRAME
   dir: TIX_DIRLIST
   book: TIX_NOTEBOOK

   form: T_FORM

   init ( tcl: TCL) is
      local
         reply: STRING
      do
         !!label.make ( Current, "title", "Test Eiffel TCL/TK")
         !!tools.build ( Current)
         !!book.make_subframe ( Current, "book")
         !!frame2.make_subframe ( book, "scale_page")
         !!scale.make ( frame2, "scale", "Volume", 200, 20)
         scale.set_range ( 5, 67)
         !!dir_frame.make_subframe ( book, "file_list")
         !!buttons2.build ( dir_frame)
         !!dir.make ( dir_frame, "files")
         !!form.build ( book)
         define
      end -- init

end -- class T_PANEL

Class T_PANEL, a TK_FRAME specialisation, is the root of the graphical system, is passed the Tcl interpreter to it’s creation routine, build. It in turn invokes one of TK_FRAME’s creation routines, make, to create a top-level frame (TK_FRAME also provides a make_subframe creator, to create a frame as a child of another). The creation completes with a call to an initialisation function, init, whose responsibility it is to create the widgets that the test-panel will contain. After this, control returns to T_DEMO, which invokes the event-loop of the Tcl interpreter, and the system is running.


Home Page ] [ Eiffel Archive ] [ Eiffel Classes and Clusters ]