Embed the Tk Console in a Tcl/Tk application

This is a discussion on Embed the Tk Console in a Tcl/Tk application within the TCL forums in Programming Languages category; I have many programs that have a GUI and use the Tk Console. It is difficult and annoying to have two separate windows for one application. How can the Console be integrated into a Tcl program GUI? What I want to do is simply create a container frame in my main program then call: console eval ". configure -use $frameId" but -use does not work with configure. Surly this has been done many times before but I have been searching for a few hours now and have not found anything. Does anyone have a solution?...

Go Back   Application Development Forum > Programming Languages > TCL

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 01-31-2008, 04:07 PM
dallas.goecker@gmail.com
Guest
 
Default Embed the Tk Console in a Tcl/Tk application

I have many programs that have a GUI and use the Tk Console. It is
difficult and annoying to have two separate windows for one
application. How can the Console be integrated into a Tcl program
GUI?
What I want to do is simply create a container frame in my main
program then call:
console eval ". configure -use $frameId"
but -use does not work with configure.

Surly this has been done many times before but I have been searching
for a few hours now and have not found anything.

Does anyone have a solution?
Reply With Quote
  #2  
Old 01-31-2008, 04:39 PM
Hugues Leonardi
Guest
 
Default Re: Embed the Tk Console in a Tcl/Tk application

dallas.goecker@gmail.com a écrit :
> I have many programs that have a GUI and use the Tk Console. It is
> difficult and annoying to have two separate windows for one
> application. How can the Console be integrated into a Tcl program
> GUI?
> What I want to do is simply create a container frame in my main
> program then call:
> console eval ". configure -use $frameId"
> but -use does not work with configure.
>
> Surly this has been done many times before but I have been searching
> for a few hours now and have not found anything.
>
> Does anyone have a solution?


CrowTDE is an example of application which integrates Tkcon in the GUI.
http://crowtde.sourceforge.net/
Reply With Quote
  #3  
Old 01-31-2008, 05:59 PM
Jeff Hobbs
Guest
 
Default Re: Embed the Tk Console in a Tcl/Tk application

On Jan 31, 1:07 pm, dallas.goec...@gmail.com wrote:
> application. How can the Console be integrated into a Tcl program GUI?


See http://wiki.tcl.tk/17616

Jeff
Reply With Quote
  #4  
Old 02-02-2008, 05:23 AM
EL
Guest
 
Default Re: Embed the Tk Console in a Tcl/Tk application

dallas.goecker@gmail.com schrieb:
> I have many programs that have a GUI and use the Tk Console. It is
> difficult and annoying to have two separate windows for one
> application. How can the Console be integrated into a Tcl program
> GUI?
> What I want to do is simply create a container frame in my main
> program then call:
> console eval ". configure -use $frameId"
> but -use does not work with configure.
>
> Surly this has been done many times before but I have been searching
> for a few hours now and have not found anything.
>
> Does anyone have a solution?


You might also check out Tloona: http://tloona.sourceforge.net/
In fact, the console there is designed to be reused in other programs.
Look at src/tmw-console.

- Eckhard
Reply With Quote
  #5  
Old 02-04-2008, 10:50 PM
slebetman@yahoo.com
Guest
 
Default Re: Embed the Tk Console in a Tcl/Tk application

On Feb 1, 5:07 am, dallas.goec...@gmail.com wrote:
> I have many programs that have a GUI and use the Tk Console. It is
> difficult and annoying to have two separate windows for one
> application. How can the Console be integrated into a Tcl program
> GUI?
> What I want to do is simply create a container frame in my main
> program then call:
> console eval ". configure -use $frameId"
> but -use does not work with configure.
>
> Surly this has been done many times before but I have been searching
> for a few hours now and have not found anything.
>
> Does anyone have a solution?


Here's an embeddable console I wrote for my own use. It is based on
the text widget and behaves like a text widget:

namespace eval textConsole {
proc notEnd {widget} {
set current [split [$widget index insert] "."]
set this [lindex $current 0]
set that [lindex [split [$widget index end] "."] 0]
incr this
if {$this != $that} {
return 1
}
set this [lindex $current 1]
if {$this <= 1} {
return 1
}
return 0
}

proc handlekey {widget {command ""}} {
set idx [$widget index {end -1 lines}]
set line [string trim [$widget get "$idx +1 chars" end]]

# clear is an internal command:
if {[string trim $line] == "clear"} {
after 1[list $widget delete 0.0 end]
} else {
if {$command == ""} {
set command {namespace eval textConsole::context $line}
} else {
lappend command $line
}
if {[catch {eval $command} out]} {
set out $::errorInfo
}
$widget insert end "\n$out\n"
}

after idle[list $widget insert end ">"]
}
}

proc textConsole {widget args} {
set handler ""
while {[llength $args]} {
set op [lindex $args 0]
set args [lrange $args 1 end]
switch -exact -- $op {
-handler {
set handler [lindex $args 0]
set args [lrange $args 1 end]
}
}
}

frame $widget
pack [text $widget.t \
-yscrollcommand[list $widget.s set] \
-font "Courier 8"] \
-fill both -expand 1 -side left
pack [scrollbar $widget.s \
-command[list $widget.t.internal yview] \
-orient vertical] \
-side right -fill y

rename $widget.t $widget.t.internal
proc $widget.t {args} [string map[list %WIDGET% $widget] {
if {[lindex $args 0] == "insert" &&
[lindex $args 1] != "end"} {
if {[textConsole::notEnd %WIDGET%.t.internal]} {
set args [lreplace $args 1 1 "end"]
%WIDGET%.t.internal mark set insert end
}
} elseif {[lindex $args 0] == "delete"} {
if {[textConsole::notEnd %WIDGET%.t.internal]} {
return
}
} elseif {[lindex $args 0] == "handler"} {
if {[llength $args] != 2} {
error \
{wrong # args: should be "%WIDGET% handler script"}
}
bind %WIDGET%.t <KeyPress-Return> \[list textConsole::handlekey \
%WIDGET%.t.internal [lindex $args 1]]
return
}
eval %WIDGET%.t.internal $args
}]
$widget.t.internal insert end ">"
bind $widget.t <KeyPress-Return> \[list textConsole::handlekey \
$widget.t.internal $handler]
return $widget
}

##
# USAGE EXAMPLE:
##
textConsole .con
pack .con -fill both -expand 1

##
# Commands typed into the console
# above are evaluated by the default
# handler. The default handler evals
# commands in a private namespace.
# You can also define your own custom
# handler if you want:
##

##
# EXAMPLE: this console evals
# in global scope:
##
textConsole .con2 -handler handle_con2
proc handle_con2 {line} {
uplevel #0 $line
}

##
# EXAMPLE: this console [exec]
# instead of [eval]:
##
textConsole .con3 -handler handle_con3
proc handle_con3 {line} {
eval exec $line
}
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:10 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.