# -*-mode: text; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- NAME objtix_class - create a class of Tix objects SYNOPSIS objtix_class className baseClass { method name args body ?options? method Constructor args body - required method Destructor body def name {self args} body ?options? slot varName ?options? } objtix_widget_class className baseClass { method name args body ?options? method ConstructWidget args body - required method InitWidgetRec {} body method SetBindings {} body method Destructor body def name {self args} body ?options? slot varName ?options? } className objName ?options? objName method ?args...? DESCRIPTION Tix comes with a simple object oriented programming (OOP) framework, the Tix Intrinsics, for writing mega-widgets. The Tix Intrinsics is not a general purpose OOP system and it does not support some features found in general purpose OOP systems such as [incr Tcl]. However, the Tix Intrinsics is specially designed for writing mega-widgets. It provides a simple and efficient interface for creating mega-widgets so that you can avoid the complexity and overheads of the general purpose OOP extensions to Tcl. The ObjTix wrapper exposes Tix's object oriented programming framework with a simple OO syntax. ObjTix objects can also be automatically wrapped into other languages (Python). objtix_class className baseClass definition Provides the definition for a class named className. If className is already defined, then this command returns an error. If the class definition is successfully parsed, className becomes a command in the current namespace context, handling the creation of objects. The class definition is evaluated as a series of Tcl statements that define elements within the class. In addition to the usual commands, the following class definition commands are recognized: slot - declare a slot (attribute) in the class method - declare a method (meesage-handler) alias - alias an existing slot to a new name The baseClass declares one or none baseclass, causing the current class to inherit their characteristics. Classes must have been defined by a previous objtix_class command, or by a previous tixClass ot tixWidgetClass, or must be available to the auto-loading facility (see "AUTO-LOADING" below). When the same member name appears in two or more base classes, the base class that appears last in the inherit list takes precedence. method name args body ?options? Declares a method called name with an argument list args and a body of Tcl statements. A method is just like the usual Tcl "proc" except that it has the variable 'self' set to the name of the instance, and the array 'slot' set to the array that contains all of the slots of the instance. The method command accepts the following options: -type - one of: "string symbol lexeme boolean integer float number list arraylist instance widget path void" Name of a type - creates a typesetting procedure when wrapped into other languages. -doc - Documentation string (ignored) method name args body ?options? Same as method, but you must provide a self argument as the first element in the list of args. slot varName ?options? Declares a public slot named varName. Slots are elements of the array slot, which is visible in methods within the scope of their class and any derived class. In addition, they can be modified outside of the class scope using the special "config" formal argument (see "ARGUMENT LISTS" above). The slot command accepts the following options: varName "" "Name of the slot - required" -readonly -boolean false "Can only be set by instance default" -static -boolean false "Can only be set at instance creation" -forcecall -boolean false "Force a call of the config procedure" -typecheck -string "" "Name of a typechecking procedure of {arg}; precludes -type" -type -choice "string symbol lexeme boolean integer float number list arraylist instance widget path" "Name of a type - creates a typechecking procedure" -resourcename -string "" "Resource name (widgets only)" -resourceclass -string "" "Resource class (widgets only)" -default -any "" "Default value" -doc -string "" "Documentation string (ignored)" -configproc -list {} "Body of a config procedure of {w arg}" CLASS USAGE When a class definition has been loaded (or made available to the auto-loader), the class name can be used as a command. className objName ?args...? Creates a new object in class className with the name objName. Remaining arguments are passed to the constructor. If construction is successful, the object name is returned and this name becomes a command in the current namespace context. Otherwise, an error is returned. You must provide a Constructor or ConstructWidget method for each objtix_class and objtix_widget_class, respectively. OBJECT USAGE objName method ?args...? Invokes a method named method to operate on the specified object. Remaining arguments are passed to the method. The method name can be "constructor", "destructor", any method name appearing in the class definition, or any of the following built-in methods. OTHER BUILT-IN COMMANDS The following commands are also available within the scope of each class. They cannot be accessed from outside of the class as proper methods or procs; rather, they are useful inside the class when implementing its functionality. alias -old_slot -new_slot Make an alias for a slot name. doc Documentation string for the class or method (ignored) AUTO-LOADING Class definitions need not be loaded explicitly; they can be loaded as needed by the usual Tcl auto-loading facility. Each directory containing class definition files should have an accompanying "tclIndex" file. Each line in this file identifies a Tcl procedure or objtix_class definition and the file where the definition can be found. To make the Tcl auto_mkindex command aware of Tix classes, you must first source the ObjTix.tcl file before issuing the auto_mkindex command. From a Makefile or command line, this can be done with a command similar to the following: echo 'source ObjTix.tcl; auto_mkindex . *.tcl' | tclsh WRAPPING You can use ObjTix objects directly from other languages: Python. Use the file ObjTixPython.tcl to convert a file containing ObjTix objects to Python: tixwish ObjTixPython.tcl [] If is not provided, it defaults to stdout. BUGS Only single inheritance is supported. KEYWORDS class, object, object-oriented, inheritance. SEE ALSO objtix_info, ObjTixPython.tcl