Importing Tcl Projects into XOTclIDE Components

In XOTclIDE there are 3 ways to import your Tcl sources in XOTclIDE components. The section describes how these importing function works and what are their limits. Generally if your Tcl program is good structured and have no or a few commands in global script context beside class or procedure definitions when the importing works out the box.

Importing per definition tracking

There are 2 main importing function in XOTclIDE both accessible from Component Browser

Load Package

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

Import Source

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

The importing functions in XOTclIDE do not parse Tcl scripts but let it evaluate them by Tcl Interpreter. Therefore the importing works very reliable. It means every package or script can be loaded into XOTclIDE. XOTclIDE track the definition of Tcl procedures proc name arguments body command and definition of XOTcl Class Objects and their instance methods and class methods. The importing tracker notice every new defined procedure create components and add this procedure to this component. All this procedures are normally evaluated by Tcl interpreter too. On the other hand the importing tracker can not notice the other script evaluation in global context.

Limits of Source Importing and manual adaptation

Lets see on same example of Tcl script in 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 Applikation 
# parameters: None
proc startApp {} {
   buton .re -text "Quit" -command "quite"
   # ... your programm
}

... many other defined procedures

# next line start the application
startApp
The importing function will create new component with name myapp with all your procedures. The imported package can see as follow
# automatically generated from XOTclIDE
package provide importExample 0.1

@ tclproc startApp idemeta struct importExample default
proc startApp {} {
   # button .re -text "Quit" -command "quite"
   # ... your programm
}
As you see all comments, global context commands and starting application command are lost. The # comments in global context can not be imported by evaluation because Tcl ignore it. You can use comments importer (see the Section called Importing Tcl comments).

Another problem is the evaluation of Tcl commands in global context. In XOTclIDE you should have one one line of such evaluation that is coded in configuration map (see the Section called Configurations Management). To enable proper import the definition block should be moved to special new procedure. The Example above could see as follow.

# 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 Applikation 
# parameters: None
proc startApp {} {
   buton .re -text "Quit" -command "quite"
   # ... your programm
}
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 exported into XOTclIDE without losing information. Anyway I think good Tcl programs should be written such way (no evaluation in global context).

Importing - Load regular Tcl Package

To import a regular tcl package use menu Component->Load Package in Component Browser. The new components with name of imported package are created. Also nested packages (That are loaded from package with package require).

Figure 16. Load Package Dialog

Importing - Import Source

The new created components have names that correspond to script file names (without extension). Also nested script evaluation or package require commands are respected. Before sourcing the script XOTclIDE change the working directory to path of script file. The application will normal start. The problem can appears when the application use toplevel window. Toplevel window is already used by XOTclIDE Transcript window. If an error occurs while evaluation the importing is interrupted with error message.

If procedures are defined in :: namespace then their are added to Tcl-Proc-Group named "default". The procedure with name "mynamespace::myname" with be added to Tcl-Proc-Group with name "mynamespace".

Importing per System Introspection

The another way to importing your application is to start XOTclIDE from your application and introspect it with XOTclIDE. XOTclIDE can import procedures and XOTcl object classes directly from Tcl interpreter. To start XOTclIDE from your application you can use START.tcl script in XOTclIDE directory. Please change the working directory to the XOTclIDE directory (with START.tcl script).

For importing code from your application you must create first new component where you want to import all procedures and classes from Interpreter. To import Tcl procedure from Tcl interpreter select the component first 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 Interpreter select the component and choose menu Command->Low level Functions->Register Class from Interp in Component Browser

Importing application on this way demand more work but if you want to import only a part of application or the application is in format that you can not read it, it is good chose

Importing Tcl comments

Consider the example below

# This procedure make magic initialization of
# X Module.
# Warning: 
proc initModuleX {{path {}} {
   #
   #
} 
The 3 lines comment belong to procedure initModuleX. XOTclIDE have special parser that can scan Tcl files script and associate the comments to already imported components. To lunch # Comments Scanner use menu System->Extras-># Comments Scanner The difference to source importer this tool do not evaluate the selected scripts but scan all lines after leading # character.

Figure 17. Comment Scanner Tool

Plug-ins Architecture

One of main advantages of XOTclIDE is ease customizing of XOTclIDE for users needs. Indeed XOTclIDE was developed with itself. It is no problem to develop change XOTclIDE in runing time. 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 to 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