From: Emiliano on
On 2 jul, 15:24, "Gerald W. Lester" <Gerald.Les...(a)KnG-Consulting.net>
wrote:
> Donald G Porter wrote:
> > Donald G Porter wrote:
> >>...
>
> > Having said that, it seems that with modern Tcl such things would be
> > more easily done with [chan create].
>
> When I saw this post I was thinking the same thing.  :)

indeed.
Disclaimer: This code *just works*. Nothing sophisticated here

#
package require Tcl 8.6
package require Tk

namespace eval textchan {}

proc textchan::text {w args} {
::text $w {*}$args
return [chan create write [list [namespace which chancmd] $w]]
}

proc textchan::chancmd {w cmd args} {
$cmd $w {*}$args
}

proc textchan::initialize {w fd args} {
return {initialize finalize watch write}
}

proc textchan::finalize {w fd args} {
# closing the channel also gets rid of the text widget
destroy $w
}

proc textchan::watch {w fd args} {
# do nothing
}

proc textchan::write {w fd data} {
$w insert end $data
return [string length $data]
}

# quick test
#################################################################
set fd [textchan::text .t]
chan configure $fd -buffering line
pack .t -expand 1 -fill both
chan puts $fd "hello"
chan puts $fd "world"
after 5000 {chan puts $fd "And more text ..."}
after 10000 {chan close $fd}
From: Emiliano on
On 2 jul, 16:02, Emiliano <emilianogavi...(a)gmail.com> wrote:

It was pointed out to me that the above code also works with Tcl 8.5
(sorry, I had only a HEAD installation). But I tested it with a tclkit
binary and it works with 8.5

Emiliano
From: Gerald W. Lester on
Emiliano wrote:
> On 2 jul, 16:02, Emiliano <emilianogavi...(a)gmail.com> wrote:
>
> It was pointed out to me that the above code also works with Tcl 8.5
> (sorry, I had only a HEAD installation). But I tested it with a tclkit
> binary and it works with 8.5

Please document and submit to TkLib


--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald.Lester(a)kng-consulting.net |
+------------------------------------------------------------------------+
From: Andreas Kupries on
"Gerald W. Lester" <Gerald.Lester(a)KnG-Consulting.net> writes:

> Donald G Porter wrote:
>> Donald G Porter wrote:
>>>...
>>
>> Having said that, it seems that with modern Tcl such things would be
>> more easily done with [chan create].
>
> When I saw this post I was thinking the same thing. :)

package require tcl::chan::textwindow

in tcllib/modules/virtchannel_base/textwindow.tcl

and a host of others. This straight from the examples I made for the
paper I presented in Portland 2009.

--
So long,
Andreas Kupries <akupries(a)shaw.ca>
<http://www.purl.org/NET/akupries/>
Developer @ <http://www.activestate.com/>
-------------------------------------------------------------------------------