Purpose: to describe the tkcon application and the special features that make it a worth the moments it takes to download. ---- TkCon provides a console for interacting with [Tcl]. This console has an input history, the ability to help loading packages, ability to attach to running [Tk] applications (if on a system which supports Tk's [send] command), What: TkCon Where: http://tkcon.sourceforge.net/ http://www.purl.org/net/hobbs/tcl/script/tkcon/ http://www.purl.org/net/hobbs/tcl/script/widget/ Description: A Tcl/Tk source standard console. It not only is a replacement for the one that comes with Tk on Windows and Macintosh, but can also be used under Unix. Provides command history, path/proc/variable name expansion, multiple interpreter consoles, captures stdout and stderr, character and proc highlighting, history searching, copy/paste between consoles, communicate with other tk interpreters, supports dynamically loadable extensions, electric character and proc highlighting. Latest version supports attaching to itcl/Tcl 8 namespaces. Regular updates occur - check pack on the WWW page for announcements. Requires Tcl/Tk 8.0+ . Currently version 2.2 . At the widget URL find a fully widgetised version of TkCon. Updated: 10/2001 Contact: mailto:jeff@hobbs.org (Jeffrey Hobbs) ---- '''TkCon as an application console''' You can use TkCon as a console for your applications. This is great for debugging, or giving your users a lot of flexibility with the application. The console window interacts directly with the main interpreter. As of TkCon version 2.4, you can source tkcon.tcl and load it as a quasi-package. (There is no pkgIndex.tcl) Put code like this into your GUI construction. #------------------------------------------------------ # Tkcon isn't packaged in a library, so we have to # source the code, but it provides a package, and # the commands [tkcon show] and [tkcon hide] #------------------------------------------------------ source tkcon.tcl package require tkcon But this doesn't actually create the console until the first time you use it. You also might find some behavior you don't like. For example, if you close the tkcon console window by clicking the "X", then the application exits. There isn't a good public interface for just creating the console and attaching show/hide to a radio button, so you might end up using code like this, even after the ''package require tkcon''. #------------------------------------------------------ # The console doesn't exist yet. If we create it # with show/hide, then it flashes on the screen. # So we cheat, and call tkcon internals to create # the console and customize it to our application. #------------------------------------------------------ set tkcon::PRIV(showOnStartup) 0 set tkcon::PRIV(root) .console set tkcon::PRIV(protocol) {tkcon hide} set tkcon::OPT(exec) "" tkcon::Init tkcon title "My Application Console" If you have an older version of TkCon (before 2.4), then upgrade. If you can't upgrade, then you can try this code, documented here by [FPX]. You get the same ''[[tkcon show]]'' and ''[[tkcon hide]]'' commands. namespace eval tkcon {} set tkcon::PRIV(showOnStartup) 0 set tkcon::PRIV(root) .tkcon set tkcon::OPT(exec) "" source tkcon.tcl ---- [stevel]: tkcon packaged as a [starkit] can be found at http://mini.net/sdarchive/tkcon.bin. The tkcon "Help/Retrieve latest version" option will update the starkit with the latest CVS version of tkcon.tcl. [LV] Steve, the code for retrieve latest version would be useful to turn into a proc that became part of tclkit's std environment, so that all starkits might do that. Or at least, all the ones at sf.net... This application is also part of the [ActiveTcl] Batteries Included distribution. Tkcon is in the bin directory, which you can find with ''[[info nameofexecutable]]'' and ''[[file dirname]]''. It is named ''tkcon.tcl'' on Windows and ''tkcon'' (without ''.tcl'') on Unix. ---- To get tkcon to work using only the main interpreter and the . toplevel, [Jeff Hobbs] writes: You need to pass with -exec "" on the command line (in ::argv) or add the following code before you source tkcon: namespace eval ::tkcon {} # we want to have only the main interpreter set ::tkcon::OPT(exec) "" ---- Outstanding questions relating to tkcon: ---- [JH]: '''Debugging with tkcon''' I was asked: * [[could someone please add more about the observe and idebug commands in tkcon?]] * [[could someone discuss how to debug with tkcon: explain idebug [http://tkcon.sourceforge.net/docs/idebug.html], observe [http://tkcon.sourceforge.net/docs/observe.html], "hot errors", and state introspection.]] ''idebug'' is a very simple "debugger" that is really more of an interactive introspection tool. You have to actively add the ''idebug break'' lines into your code. You can turn off idebug triggers globally (or by id). You can also add ''idebug trace'' calls which just show the call stack anytime they are hit. ''idebug'' was inspired by an earlier work done by Stephen Uhler (one of the former Tcl Sunlabs folks). When you stop at an idebug breakpoint, you can introspect or eval any code you want. There are shortcuts for most introspection, just type '?' to see them. ''observe'' is just a wrapper around [trace] that allows you to watch variable modifications or command invocations easily in tkcon. ''hot errors'' is the facility in tkcon that makes any error thrown to the toplevel tkcon command line a link. Clicking on the link will pop up the full error (with [errorInfo]) and, where possible, highlight procs. Green highlighted procs will pop up an edit window with that proc information, while blue highlighted procs will do the same, but highlight the error information it received from the stack trace. In this way, errors in your code that reach the global level become much easier to debug. Try this example in tkcon: % proc foo {args} { set a b $args } % proc bar {} { foo a b c } % bar wrong # args: should be "set varName ?newValue?" and click on the error. Simply by running in tkcon you can do all sorts of introspection and state modification. It has many other features, but now my fingers are tired ... ---- See also: [tkcon.cfg] ---- [Arts and crafts of Tcl-Tk programming] ---- [Category Application]