0

Here is a demo sample of TCL code for iwidgets::scrolledtext.

package require Iwidgets
iwidgets::scrolledtext .st \
        -labeltext "Scrolledtext Example" \
        -visibleitems 70x20 \
        -textfont {Courier 10} \
        -textbackground black \
        -vscrollmode dynamic \
        -hscrollmode dynamic \
        -wrap none
pack .st -fill both -expand true
.st component text configure -foreground green
.st import /path/to/some/file

I need the following additional options.

  1. To make iwidgets::scrolledtext online, i.e. when iwidgets::scrolledtext is opened and when I add some lines to file at /path/to/some/file, I want the iwidgets::scrolledtext to be updated automatically.
  2. To make the text at iwidgets::scrolledtext static, i.e. to prevent the text from editing.
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Vahagn
  • 4,670
  • 9
  • 43
  • 72

2 Answers2

2

Try this little subclass of the scrolledtext class:

itcl::class TailScrolled {
    inherit iwidgets::Scrolledtext
    destructor {}
    public method import {filename}
    private variable fd
    private variable cb
    private method ReadAppend {}
}

itcl::body TailScrolled::destructor {} {
    if {[info exist fd]} {
        close $fd
        after cancel $cb
    }
}
itcl::body TailScrolled::import {filename} {
    if {[info exist fd]} {
        close $fd
        after cancel $cb
    }
    set fd [open $filename r]
    ReadAppend
}
itcl::body TailScrolled::ReadAppend {} {
    set cb [after 500 [::itcl::code ReadAppend]]
    insert end [read $fd]
}

(Warning: I've not actually tried it, so I might've fluffed exactly how to do inheritance from an IWidgets widget. This is the principle of how to do it though.)

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
1

So in other words you want some kind of functionality like the unix 'tail' command.

Not really for iwidgets, but the code should be easily adapted, so have a look at the tailing widget on the Tcl'ers wiki. http://wiki.tcl.tk/1158

schlenk
  • 7,002
  • 1
  • 25
  • 29