| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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? |
|
#2
| |||
| |||
| 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/ |
|
#3
| |||
| |||
| 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 |
|
#4
| |||
| |||
| 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 |
|
#5
| |||
| |||
| 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 } |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.