Importing Tcl Projects into XOTclIDE Components

In XOTclIDE there are three ways to import your existing Tcl sources into XOTclIDE components. This section describes how these importing function work and what their limits are. Generally if your Tcl program is well structured and has no commands or a few commands in the global script context other than class or procedure definitions the importing works out of the box.

Importing by definition tracking

There are two main importing functions in XOTclIDE, both accessible from the Component Browser

Load Package

Component->Load Package With this function you can load any Tcl package accessible in your Tcl system by calling package require name.

Import Source

Component->Import Source This importing function can evaluate any script in the file system. It is the same as using the command source filename.

The importing functions in XOTclIDE do not parse Tcl scripts but evaluate them with the Tcl Interpreter. Therefore the importing works very reliably. Any package or script can be loaded into XOTclIDE. XOTclIDE tracks the definition of Tcl procedures with the proc name arguments body command and the definition of XOTcl Classes, Objects and their instance methods and class methods. The importing tracker notices every newly defined procedure, creates components, and adds the procedure to this component. All procedures are also normally evaluated by Tcl interpreter. The importing tracker does not notice any other script evaluation in the global context.

Limits of Source Importing and manual adaptation

Let's examine a Tcl script in the file myapp.tcl that should be imported.

# This is great script that I want to reuse in XOTclIDE
# Author: old Tcl'er
# Revision: 
package require Tk

# set debug 1 
set color red
set configfile myapp.conf
if {![file exists $myapp.conf]} {
    # error "can not find config file $configfile"
}

# Starting Application 
# parameters: None
proc startApp {} {
    button .re -text "Quit" -command "quite"
    # ... your program
}
... many other defined procedures

# next line starts the application
startApp

The importing function will create a new component with the name myapp with all your procedures. The new component can be seen as follows

# automatically generated from XOTclIDE
package provide importExample 0.1

@ tclproc startApp idemeta struct importExample default
proc startApp {} {
   # button .re -text "Quit" -command "quite"
   # ... your program
}

As you see, all comments, global context commands and the application starting command are lost. Comments (# lines) in the global context are not imported during evaluation because Tcl ignores them. You can use the comment importer (see the section called “Importing Tcl comments”) to add these comments to the component.

Another problem is the evaluation of Tcl commands in the global context. In XOTclIDE you should have just one such line coded in the configuration map (see the section called “Configurations Management”). To enable proper import the definition block should be moved to a special new procedure. The example above could appear as follows:

# This is great script that I want to reuse in XOTclIDE
# Author: old Tcl'er
# Revision: 
package require Tk

# set debug 1 
proc defineGlobalConstans {} {
    global color configfile
    set color red
    set configfile myapp.conf
}
proc checkConfigFile {}  {
    global configfile
    if {![file exists $configfile]} {
         # error "can not find config file $configfile"
    }
}
# Starting Application 
# parameters: None
proc startApp {} {
     button .re -text "Quit" -command "quite"
     # ... your program
}
proc basicStartApp {} {
     defineGlobalConstans
     checkConfigFile
     startApp
}
... many other defined procedures

# next line start the application
basicStartApp

In this case we have only one line with direct script evaluation and this can be imported into XOTclIDE without losing information. I think good Tcl programs should be written this way - no evaluation in the global context - anyway.

Importing - Load regular Tcl Package

To import a regular tcl package use menu Component->Load Package in Component Browser. A new component with the same name as the imported package will be created, along with nested packages that are loaded from the imported package using package require.

Figure 4.12. Load Package Dialog

Load Package Dialog

Importing - Import Source

Newly created components will have names that correspond to the script file name, without extension. Any nested script evaluation or package require commands are respected. Before sourcing the script XOTclIDE changes the working directory to the path of the script file. The application will start normally. A problem may appear when the application uses a toplevel window, as the toplevel window is already used by the XOTclIDE Transcript window. If an error occurs while importing, importing is interrupted with the error message.

Procedures defined in the :: namespace will be added to a Tcl-Proc-Group named “default”. Procedures with names “mynamespace::myname” with be added to a Tcl-Proc-Group named “mynamespace”.

Importing by System Introspection

Another way to import your application is to start XOTclIDE from your application and introspect it with XOTclIDE. XOTclIDE can import procedures and XOTcl object classes directly from a running Tcl interpreter. To start XOTclIDE from your application you can use the START.tcl script in the XOTclIDE directory. Change the working directory to the XOTclIDE directory with the START.tcl script.

To import code from your running application you must first create a new component where all procedures and classes from the Interpreter will be stored. To import a Tcl procedure from the Tcl interpreter, first select the component where you want to import to and use menu Command->Low Level Functions->Register Tcl Proc from Interp in Component Browser

To import XOTcl Classes from the Interpreter select the component and choose menu Command->Low level Functions->Register Class from Interp in Component Browser

Although importing an application like this is more work, it's a good choice if you want to import only part of an application or the application is not in a readable format.

Importing Tcl comments

Consider the example below

# This procedure make magic initialization of
# X Module.
# Warning: 
proc initModuleX {{path {}} {
     #
     #
} 

The three line comment belongs to procedure initModuleX. XOTclIDE has a special parser that can scan Tcl script files and associate the comments to previously imported components. To launch the # Comments Scanner use the menu System->Extras-># Comments Scanner Unlike the source importer, this tool does not evaluate the selected scripts but scans all lines after a leading # character.

Figure 4.13. Comment Scanner Tool

Comment Scanner Tool

Plug-ins Architecture

One of main advantages of XOTclIDE is easy customizing of XOTclIDE for users needs. Many of XOTclIDE components are loaded dynamic at runing time only on demand. In menu System->Plug Ins are all currently registered plug-ins accesible. The plug ins are normal components the registration and start scripts are specified per file pluginslist.txt in XOTclIDE directory.

Following Plug-Ins are currently delivered with XOTclIDE

Unit Test Framework

Unit Test Framework programmed after Smalltalk SUnit (JUnit, NUnit). See also Unit Tests Homepage

XOTclIDE Unit Tests

Tests of XOTclIDE itself

Funny Graphics Example

Small XOTcl Application taken from Tcl Wiki

HTML Doc Generator

Generate HTML Source Code Documentation from Source Comments

# Comments Scaner

Importing tool described in the section called “Importing Tcl comments”

Tcl Wiki Reaper

Can import code sniplets form Tcl wiki Tcl Wiki

TclKit Deploeyer Tool

This tool extend the functionality of Application Deployer Wizard. It can generate TclKit Distributions or standalone Starpacks directly from XOTclIDE. It work properly only form XOTclIDE TclKit version or if TclKit envirorment are installed properly in your Tcl system

Tk Win Inspector

This tool can inspect all Tk windows. It can be used to view and change all configuration of every Tk window. Tk Inspector includes also widget serializator that can be used to serialize every windows and their descend to Tcl script that can be used as code snippet.

Tcl Script Editor

Ideal for edit and test short Tcl-scripts that all contents are evaluated in global context. You can use all advantages of XOTclIDE: syntax highlighting, syntax check, code completion. The script can be evaluated in slave interpreter.

SQL Browser

GUI helper for SQL access to all databases supported by XOTclIDE. Additional 2 Lists-Views show all table names and columns names (schema of DB). The result will be displayed in TkTable-Widget. Every cell can be also viewed in separately view.

Visual Regexp

This plug-in is adapted GPL program written by L. Riesterer original source